Skip to content

Commit

Permalink
Work on syntax and snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
technosophos committed May 20, 2017
1 parent daddf0d commit 9e4ca06
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 3 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@
"description": "Run 'helm template' on this chart and show only this file. Requires the helm-template plugin."
}
],
"menus": {
"explorer/context": [
{
"title": "Update Dependencies",
"when": "resourceFilename == requirements.yaml",
"command": "extension.helmDepUp",
"group": "navigation@99"
}
]
},
"languages": [{
"id": "helm",
"aliases": ["helm-template", "helm"],
Expand Down
7 changes: 7 additions & 0 deletions rawsnippets/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: ${1}
namespace: ${3:default}
data:
${2}
29 changes: 29 additions & 0 deletions rawsnippets/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata: {{ \$fullname := printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" }}
name: {{ \$fullname }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
replicas: {{ default 1 .Values.replicaCount | int }}
template:
metadata:
labels:
app: {{ \$fullname }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image }}"
imagePullPolicy: IfNotPresent
ports:
- containerPort: {{ .Values.service.internalPort | int }}
livenessProbe:
httpGet:
path: /
port: {{ .Values.service.internalPort | int }}
readinessProbe:
httpGet:
path: /
port: {{ .Values.service.internalPort | int }}
resources:
{{ toYaml .Values.resources | indent 10 }}
32 changes: 32 additions & 0 deletions rawsnippets/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.ingress.enabled -}}
{{- \$serviceName := $1 . -}}
{{- \$servicePort := .Values.service.externalPort -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: $1
labels:
app: $1
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
annotations:
{{- range \$key, \$value := .Values.ingress.annotations }}
{{ \$key }}: {{ \$value | quote }}
{{- end }}
spec:
rules:
{{- range \$host := .Values.ingress.hosts }}
- host: {{ \$host }}
http:
paths:
- path: /
backend:
serviceName: {{ \$serviceName }}
servicePort: {{ \$servicePort }}
{{- end -}}
{{- if .Values.ingress.tls }}
tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
{{- end -}}
{{- end -}}
15 changes: 15 additions & 0 deletions rawsnippets/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: $1
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.externalPort }}
targetPort: {{ .Values.service.internalPort }}
protocol: TCP
name: {{ .Values.service.name }}
selector:
app: $1
21 changes: 21 additions & 0 deletions snippets.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
)

// Snippet represents a VS Code snippet.
type Snippet struct {
Prefix string `json:"prefix"`
Body []string `json:"body"`
Expand All @@ -25,6 +26,26 @@ var snippets = map[string]Snippet{
Description: "Create a Pod manifest",
Body: load("pod.yaml"),
},
"ConfigMap": {
Prefix: "kindConfigMap",
Description: "Create a ConfigMap manifest",
Body: load("configmap.yaml"),
},
"Deployment": {
Prefix: "kindDeployment",
Description: "Create a Deployment manifest",
Body: load("deployment.yaml"),
},
"Service": {
Prefix: "kindSerice",
Description: "Create a Service manifest",
Body: load("service.yaml"),
},
"Ingress": {
Prefix: "kindIngress",
Description: "Create a Ingress manifest",
Body: load("ingress.yaml"),
},
"Chart.yaml": {
Prefix: "Chart.yaml",
Description: "Create a Chart.yaml file",
Expand Down
107 changes: 107 additions & 0 deletions snippets/helm.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,92 @@
],
"description": "Create a Chart.yaml file"
},
"ConfigMap": {
"prefix": "kindConfigMap",
"body": [
"kind: ConfigMap",
"apiVersion: v1",
"metadata:",
" name: ${1}",
" namespace: ${3:default}",
"data:",
" ${2}"
],
"description": "Create a ConfigMap manifest"
},
"Deployment": {
"prefix": "kindDeployment",
"body": [
"apiVersion: extensions/v1beta1",
"kind: Deployment",
"metadata: {{ \\$fullname := printf \"%s-%s\" .Release.Name .Chart.Name | trunc 63 | trimSuffix \"-\" }}",
" name: {{ \\$fullname }}",
" labels:",
" chart: \"{{ .Chart.Name }}-{{ .Chart.Version | replace \"+\" \"_\" }}\"",
"spec:",
" replicas: {{ default 1 .Values.replicaCount | int }}",
" template:",
" metadata:",
" labels:",
" app: {{ \\$fullname }}",
" spec:",
" containers:",
" - name: {{ .Chart.Name }}",
" image: \"{{ .Values.image }}\"",
" imagePullPolicy: IfNotPresent",
" ports:",
" - containerPort: {{ .Values.service.internalPort | int }}",
" livenessProbe:",
" httpGet:",
" path: /",
" port: {{ .Values.service.internalPort | int }}",
" readinessProbe:",
" httpGet:",
" path: /",
" port: {{ .Values.service.internalPort | int }}",
" resources:",
"{{ toYaml .Values.resources | indent 10 }}"
],
"description": "Create a Deployment manifest"
},
"Ingress": {
"prefix": "kindIngress",
"body": [
"{{- if .Values.ingress.enabled -}}",
"{{- \\$serviceName := $1 . -}}",
"{{- \\$servicePort := .Values.service.externalPort -}}",
"apiVersion: extensions/v1beta1",
"kind: Ingress",
"metadata:",
" name: $1",
" labels:",
" app: $1",
" chart: \"{{ .Chart.Name }}-{{ .Chart.Version | replace \"+\" \"_\" }}\"",
" release: \"{{ .Release.Name }}\"",
" heritage: \"{{ .Release.Service }}\"",
" annotations:",
" {{- range \\$key, \\$value := .Values.ingress.annotations }}",
" {{ \\$key }}: {{ \\$value | quote }}",
" {{- end }}",
"spec:",
" rules:",
" {{- range \\$host := .Values.ingress.hosts }}",
" - host: {{ \\$host }}",
" http:",
" paths:",
" - path: /",
" backend:",
" serviceName: {{ \\$serviceName }}",
" servicePort: {{ \\$servicePort }}",
" {{- end -}}",
" {{- if .Values.ingress.tls }}",
" tls:",
"{{ toYaml .Values.ingress.tls | indent 4 }}",
" {{- end -}}",
"{{- end -}}"
],
"description": "Create a Ingress manifest"
},
"Pod": {
"prefix": "kindPod",
"body": [
Expand Down Expand Up @@ -52,6 +138,27 @@
],
"description": "Create a Secret manifest"
},
"Service": {
"prefix": "kindSerice",
"body": [
"apiVersion: v1",
"kind: Service",
"metadata:",
" name: $1",
" labels:",
" chart: \"{{ .Chart.Name }}-{{ .Chart.Version | replace \"+\" \"_\" }}\"",
"spec:",
" type: {{ .Values.service.type }}",
" ports:",
" - port: {{ .Values.service.externalPort }}",
" targetPort: {{ .Values.service.internalPort }}",
" protocol: TCP",
" name: {{ .Values.service.name }}",
" selector:",
" app: $1"
],
"description": "Create a Service manifest"
},
"requirements.yaml": {
"prefix": "requirements.yaml",
"body": [
Expand Down
37 changes: 34 additions & 3 deletions syntaxes/helm.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@
"patterns": [
{
"name": "meta.tag.gotpl.instruction",
"begin": "{{-?\\s*",
"end": "\\s*-?}}",
"begin": "({{-?)\\s*",
"beginCaptures": {
"0": {
"name": "punctuation.definition.mapping.begin.helm"
}
},
"end": "\\s*(-?}})",
"endCaptures": {
"0": {
"name": "punctuation.definition.mapping.end.helm"
}
},
"patterns": [
{"include": "#gotpl-comment"},
{"include": "#gotpl-expressions"}
Expand Down Expand Up @@ -537,7 +547,28 @@
{
"match": "\\\\\\n",
"name": "constant.character.escape.double-quoted.newline.yaml"
}
},
{
"name": "meta.tag.gotpl.instruction",
"begin": "({{-?)\\s*",
"beginCaptures": {
"0": {
"name": "punctuation.definition.mapping.begin.helm"
}
},
"end": "\\s*(-?}})",
"endCaptures": {
"0": {
"name": "punctuation.definition.mapping.end.helm"
}
},

"comment": "FIXME: This should set highlighting on the {{ and }}",
"patterns": [
{"include": "#gotpl-comment"},
{"include": "#gotpl-expressions"}
]
}
]
},
"flow-scalar-plain-in": {
Expand Down

0 comments on commit 9e4ca06

Please sign in to comment.