github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/tiltfile/text_test.go (about) 1 package tiltfile 2 3 const kustomizeFileText = `# Example configuration for the webserver 4 # at https://github.com/monopole/hello 5 commonLabels: 6 app: my-hello 7 8 resources: 9 - deployment.yaml 10 - service.yaml 11 - configMap.yaml` 12 13 const kustomizeConfigMapText = `apiVersion: v1 14 kind: ConfigMap 15 metadata: 16 name: the-map 17 data: 18 altGreeting: "Good Morning!" 19 enableRisky: "false"` 20 21 const kustomizeDeploymentText = `apiVersion: apps/v1 22 kind: Deployment 23 metadata: 24 name: the-deployment 25 spec: 26 replicas: 3 27 template: 28 metadata: 29 labels: 30 deployment: hello 31 spec: 32 containers: 33 - name: the-container 34 image: gcr.io/foo 35 command: ["/hello", 36 "--port=8080", 37 "--enableRiskyFeature=$(ENABLE_RISKY)"] 38 ports: 39 - containerPort: 8080 40 env: 41 - name: ALT_GREETING 42 valueFrom: 43 configMapKeyRef: 44 name: the-map 45 key: altGreeting 46 - name: ENABLE_RISKY 47 valueFrom: 48 configMapKeyRef: 49 name: the-map 50 key: enableRisky` 51 52 const kustomizeServiceText = `kind: Service 53 apiVersion: v1 54 metadata: 55 name: the-service 56 spec: 57 selector: 58 deployment: hello 59 type: LoadBalancer 60 ports: 61 - protocol: TCP 62 port: 8666 63 targetPort: 8080` 64 65 const chartYAML = `apiVersion: v1 66 description: A Helm chart for Kubernetes 67 name: helloworld-chart 68 version: 0.1.0` 69 70 const valuesYAML = `# Default values for helloworld-chart. 71 # This is a YAML-formatted file. 72 # Declare variables to be passed into your templates. 73 replicaCount: 1 74 image: 75 repository: nginx 76 tag: stable 77 pullPolicy: IfNotPresent 78 service: 79 name: nginx 80 type: ClusterIP 81 externalPort: 80 82 internalPort: 80 83 ingress: 84 enabled: false 85 # Used to create an Ingress record. 86 hosts: 87 - chart-example.local 88 annotations: 89 # kubernetes.io/ingress.class: nginx 90 # kubernetes.io/tls-acme: "true" 91 tls: 92 # Secrets must be manually created in the namespace. 93 # - secretName: chart-example-tls 94 # hosts: 95 # - chart-example.local 96 namespace: 97 enabled: false 98 resources: {} 99 # We usually recommend not to specify default resources and to leave this as a conscious 100 # choice for the user. This also increases chances charts run on environments with little 101 # resources, such as Minikube. If you do want to specify resources, uncomment the following 102 # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 103 # limits: 104 # cpu: 100m 105 # memory: 128Mi 106 # requests: 107 # cpu: 100m 108 # memory: 128Mi` 109 110 const valuesDevYAML = `# Dev values for helloworld chart 111 service: 112 name: nginx-dev 113 ` 114 115 const helpersTPL = `{{/* vim: set filetype=mustache: */}} 116 {{/* 117 Expand the name of the chart. 118 */}} 119 {{- define "helloworld-chart.name" -}} 120 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} 121 {{- end -}} 122 123 {{/* 124 Create a default fully qualified app name. 125 We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 126 */}} 127 {{- define "helloworld-chart.fullname" -}} 128 {{- $name := default .Chart.Name .Values.nameOverride -}} 129 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} 130 {{- end -}} 131 ` 132 133 const deploymentYAML = `{{/* vim: set filetype=mustache: */}} 134 {{/* 135 Expand the name of the chart. 136 */}} 137 {{- define "helloworld-chart.name" -}} 138 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} 139 {{- end -}} 140 141 {{/* 142 Create a default fully qualified app name. 143 We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 144 */}} 145 {{- define "helloworld-chart.fullname" -}} 146 {{- $name := default .Chart.Name .Values.nameOverride -}} 147 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} 148 {{- end -}} 149 ` 150 151 const ingressYAML = `{{- if .Values.ingress.enabled -}} 152 {{- $serviceName := include "helloworld-chart.fullname" . -}} 153 {{- $servicePort := .Values.service.externalPort -}} 154 apiVersion: extensions/v1beta1 155 kind: Ingress 156 metadata: 157 name: {{ template "helloworld-chart.fullname" . }} 158 labels: 159 app: {{ template "helloworld-chart.name" . }} 160 chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} 161 release: {{ .Release.Name }} 162 heritage: {{ .Release.Service }} 163 namespaceLabel: {{ .Release.Namespace }} 164 annotations: 165 {{- range $key, $value := .Values.ingress.annotations }} 166 {{ $key }}: {{ $value | quote }} 167 {{- end }} 168 spec: 169 rules: 170 {{- range $host := .Values.ingress.hosts }} 171 - host: {{ $host }} 172 http: 173 paths: 174 - paths: / 175 backend: 176 serviceName: {{ $serviceName }} 177 servicePort: {{ $servicePort }} 178 {{- end -}} 179 {{- if .Values.ingress.tls }} 180 tls: 181 {{ toYaml .Values.ingress.tls | indent 4 }} 182 {{- end -}} 183 {{- end -}} 184 ` 185 186 // Best practice is to NOT specify a namespace in your chart, and use --namespace 187 // instead, but I bet there's a user out there doing this. 188 const namespaceYAML = `{{- if .Values.namespace.enabled -}} 189 apiVersion: v1 190 kind: Namespace 191 metadata: 192 name: {{ .Values.namespace.name }} 193 labels: 194 somePersistedLabel: indeed 195 {{- end -}} 196 ` 197 198 const serviceYAML = `apiVersion: v1 199 kind: Service 200 metadata: 201 name: {{ template "helloworld-chart.fullname" . }} 202 labels: 203 app: {{ template "helloworld-chart.name" . }} 204 chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} 205 release: {{ .Release.Name }} 206 heritage: {{ .Release.Service }} 207 namespaceLabel: {{ .Release.Namespace }} 208 spec: 209 type: {{ .Values.service.type }} 210 ports: 211 - port: {{ .Values.service.externalPort }} 212 targetPort: {{ .Values.service.internalPort }} 213 protocol: TCP 214 name: {{ .Values.service.name }} 215 selector: 216 app: {{ template "helloworld-chart.name" . }} 217 release: {{ .Release.Name }} 218 ` 219 220 const helmTestYAML = `apiVersion: v1 221 kind: Pod 222 metadata: 223 name: "{{ .Release.Name }}-credentials-test" 224 namespace: {{ .Release.Namespace }} 225 annotations: 226 "helm.sh/hook": test-success 227 spec: 228 containers: 229 - name: {{ .Release.Name }}-credentials-test 230 image: foobar 231 env: 232 - name: MARIADB_HOST 233 value: name 234 - name: MARIADB_PORT 235 value: "3306" 236 - name: WORDPRESS_DATABASE_NAME 237 value: database 238 - name: WORDPRESS_DATABASE_USER 239 value: user 240 - name: WORDPRESS_DATABASE_PASSWORD 241 valueFrom: 242 secretKeyRef: 243 name: name 244 key: mariadb-password 245 command: ["sh", "-c", "mysql --host=$MARIADB_HOST --port=$MARIADB_PORT --user=$WORDPRESS_DATABASE_USER --password=$WORDPRESS_DATABASE_PASSWORD"] 246 restartPolicy: Never 247 `