github.com/grahambrereton-form3/tilt@v0.10.18/internal/k8s/testyaml/testyaml.go (about)

     1  package testyaml
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  const BlorgBackendYAML = `
     8  apiVersion: v1
     9  kind: Service
    10  metadata:
    11    name: devel-nick-lb-blorg-be
    12    labels:
    13      app: blorg
    14      owner: nick
    15      environment: devel
    16      tier: backend
    17  spec:
    18    type: LoadBalancer
    19    ports:
    20    - port: 8080
    21      targetPort: 8080
    22    selector:
    23      app: blorg
    24      owner: nick
    25      environment: devel
    26      tier: backend
    27  ---
    28  apiVersion: extensions/v1beta1
    29  kind: Deployment
    30  metadata:
    31    name: devel-nick-blorg-be
    32  spec:
    33    selector:
    34      matchLabels:
    35        app: blorg
    36        owner: nick
    37        environment: devel
    38        tier: backend
    39    template:
    40      metadata:
    41        name: devel-nick-blorg-be
    42        labels:
    43          app: blorg
    44          owner: nick
    45          environment: devel
    46          tier: backend
    47      spec:
    48        containers:
    49        - name: backend
    50          imagePullPolicy: Always
    51          image: gcr.io/blorg-dev/blorg-backend:devel-nick
    52          command: [
    53            "/app/server",
    54            "--dbAddr", "hissing-cockroach-cockroachdb:26257"
    55          ]
    56          ports:
    57          - containerPort: 8080
    58  `
    59  
    60  const BlorgJobYAML = `apiVersion: batch/v1
    61  kind: Job
    62  metadata:
    63    name: blorg-job
    64  spec:
    65    template:
    66      spec:
    67        containers:
    68        - name: blorg-job
    69          image: gcr.io/blorg-dev/blorg-backend:devel-nick
    70          command: ["/app/server",  "-job=clean"]
    71        restartPolicy: Never
    72    backoffLimit: 4
    73  `
    74  
    75  const SanchoImage = "gcr.io/some-project-162817/sancho"
    76  
    77  const SanchoYAML = `
    78  apiVersion: apps/v1
    79  kind: Deployment
    80  metadata:
    81    name: sancho
    82    namespace: sancho-ns
    83    labels:
    84      app: sancho
    85  spec:
    86    replicas: 1
    87    selector:
    88      matchLabels:
    89        app: sancho
    90    template:
    91      metadata:
    92        labels:
    93          app: sancho
    94      spec:
    95        containers:
    96        - name: sancho
    97          image: gcr.io/some-project-162817/sancho
    98          env:
    99            - name: token
   100              valueFrom:
   101                secretKeyRef:
   102                  name: slacktoken
   103                  key: token
   104  `
   105  
   106  const SanchoTwoContainersOneImageYAML = `
   107  apiVersion: apps/v1
   108  kind: Deployment
   109  metadata:
   110    name: sancho-2c1i
   111    namespace: sancho-ns
   112    labels:
   113      app: sancho-2c1i
   114  spec:
   115    replicas: 1
   116    selector:
   117      matchLabels:
   118        app: sancho-2c1i
   119    template:
   120      metadata:
   121        labels:
   122          app: sancho-2c1i
   123      spec:
   124        containers:
   125        - name: sancho
   126          image: gcr.io/some-project-162817/sancho
   127        - name: sancho2
   128          image: gcr.io/some-project-162817/sancho
   129  `
   130  
   131  const SanchoYAMLWithCommand = `
   132  apiVersion: apps/v1
   133  kind: Deployment
   134  metadata:
   135    name: sancho
   136    namespace: sancho-ns
   137    labels:
   138      app: sancho
   139  spec:
   140    replicas: 1
   141    selector:
   142      matchLabels:
   143        app: sancho
   144    template:
   145      metadata:
   146        labels:
   147          app: sancho
   148      spec:
   149        containers:
   150        - name: sancho
   151          image: gcr.io/some-project-162817/sancho
   152          command: ["foo.sh"]
   153          args: ["something", "something_else"]
   154  `
   155  
   156  const SanchoBeta1YAML = `
   157  apiVersion: apps/v1beta1
   158  kind: Deployment
   159  metadata:
   160    name: sancho
   161    namespace: sancho-ns
   162    labels:
   163      app: sancho
   164  spec:
   165    replicas: 1
   166    template:
   167      metadata:
   168        labels:
   169          app: sancho
   170      spec:
   171        containers:
   172        - name: sancho
   173          image: gcr.io/some-project-162817/sancho
   174          env:
   175            - name: token
   176              valueFrom:
   177                secretKeyRef:
   178                  name: slacktoken
   179                  key: token
   180  `
   181  
   182  const SanchoBeta2YAML = `
   183  apiVersion: apps/v1beta2
   184  kind: Deployment
   185  metadata:
   186    name: sancho
   187    namespace: sancho-ns
   188    labels:
   189      app: sancho
   190  spec:
   191    replicas: 1
   192    template:
   193      metadata:
   194        labels:
   195          app: sancho
   196      spec:
   197        containers:
   198        - name: sancho
   199          image: gcr.io/some-project-162817/sancho
   200          env:
   201            - name: token
   202              valueFrom:
   203                secretKeyRef:
   204                  name: slacktoken
   205                  key: token
   206  `
   207  
   208  const SanchoExtBeta1YAML = `
   209  apiVersion: extensions/v1beta1
   210  kind: Deployment
   211  metadata:
   212    name: sancho
   213    namespace: sancho-ns
   214    labels:
   215      app: sancho
   216  spec:
   217    replicas: 1
   218    template:
   219      metadata:
   220        labels:
   221          app: sancho
   222      spec:
   223        containers:
   224        - name: sancho
   225          image: gcr.io/some-project-162817/sancho
   226          env:
   227            - name: token
   228              valueFrom:
   229                secretKeyRef:
   230                  name: slacktoken
   231                  key: token
   232  `
   233  
   234  const SanchoTwinYAML = `
   235  apiVersion: apps/v1
   236  kind: Deployment
   237  metadata:
   238    name: sancho-twin
   239    namespace: sancho-ns
   240    labels:
   241      app: sancho-twin
   242  spec:
   243    replicas: 1
   244    selector:
   245      matchLabels:
   246        app: sancho-twin
   247    template:
   248      metadata:
   249        labels:
   250          app: sancho-twin
   251      spec:
   252        containers:
   253        - name: sancho
   254          image: gcr.io/some-project-162817/sancho
   255          env:
   256            - name: token
   257              valueFrom:
   258                secretKeyRef:
   259                  name: slacktoken
   260                  key: token
   261  `
   262  
   263  const SanchoSidecarYAML = `
   264  apiVersion: apps/v1
   265  kind: Deployment
   266  metadata:
   267    name: sancho
   268    namespace: sancho-ns
   269    labels:
   270      app: sancho
   271  spec:
   272    replicas: 1
   273    selector:
   274      matchLabels:
   275        app: sancho
   276    template:
   277      metadata:
   278        labels:
   279          app: sancho
   280      spec:
   281        containers:
   282        - name: sancho
   283          image: gcr.io/some-project-162817/sancho
   284          env:
   285            - name: token
   286              valueFrom:
   287                secretKeyRef:
   288                  name: slacktoken
   289                  key: token
   290        - name: sancho-sidecar
   291          image: gcr.io/some-project-162817/sancho-sidecar
   292  `
   293  const SanchoSidecarImage = "gcr.io/some-project-162817/sancho-sidecar"
   294  
   295  const SanchoRedisSidecarYAML = `
   296  apiVersion: apps/v1
   297  kind: Deployment
   298  metadata:
   299    name: sancho
   300    namespace: sancho-ns
   301    labels:
   302      app: sancho
   303  spec:
   304    replicas: 1
   305    selector:
   306      matchLabels:
   307        app: sancho
   308    template:
   309      metadata:
   310        labels:
   311          app: sancho
   312      spec:
   313        containers:
   314        - name: sancho
   315          image: gcr.io/some-project-162817/sancho
   316          env:
   317            - name: token
   318              valueFrom:
   319                secretKeyRef:
   320                  name: slacktoken
   321                  key: token
   322        - name: redis-sidecar
   323          image: redis:latest
   324  `
   325  
   326  const SanchoImageInEnvYAML = `
   327  apiVersion: apps/v1
   328  kind: Deployment
   329  metadata:
   330    name: sancho
   331    namespace: sancho-ns
   332    labels:
   333      app: sancho
   334  spec:
   335    replicas: 1
   336    selector:
   337      matchLabels:
   338        app: sancho
   339    template:
   340      metadata:
   341        labels:
   342          app: sancho
   343      spec:
   344        containers:
   345        - name: sancho
   346          image: gcr.io/some-project-162817/sancho
   347          env:
   348            - name: foo
   349              value: gcr.io/some-project-162817/sancho2
   350            - name: bar
   351              value: gcr.io/some-project-162817/sancho
   352  `
   353  
   354  const TracerYAML = `
   355  apiVersion: extensions/v1beta1
   356  kind: Deployment
   357  metadata:
   358    name: tracer-prod
   359  spec:
   360    replicas: 1
   361    revisionHistoryLimit: 2
   362    template:
   363      metadata:
   364        labels:
   365          app: tracer
   366          track: prod
   367      spec:
   368        nodeSelector:
   369          cloud.google.com/gke-nodepool: default-pool
   370  
   371        containers:
   372        - name: tracer
   373          image: openzipkin/zipkin
   374          ports:
   375          - name: http
   376            containerPort: 9411
   377          livenessProbe:
   378            httpGet:
   379              path: /
   380              port: 9411
   381            initialDelaySeconds: 60
   382            periodSeconds: 60
   383          readinessProbe:
   384            httpGet:
   385              path: /
   386              port: 9411
   387            initialDelaySeconds: 30
   388            periodSeconds: 1
   389            timeoutSeconds: 1
   390            successThreshold: 1
   391            failureThreshold: 10
   392  ---
   393  apiVersion: v1
   394  kind: Service
   395  metadata:
   396    name: tracer-prod
   397    labels:
   398      app: tracer
   399      track: prod
   400  spec:
   401    selector:
   402      app: tracer
   403      track: prod
   404    type: ClusterIP
   405    ports:
   406      - protocol: TCP
   407        port: 80
   408        targetPort: http
   409  ---
   410  apiVersion: v1
   411  kind: Service
   412  metadata:
   413    name: tracer-lb-prod
   414    labels:
   415      app: tracer
   416      track: prod
   417  spec:
   418    selector:
   419      app: tracer
   420      track: prod
   421    type: LoadBalancer
   422    ports:
   423      - protocol: TCP
   424        port: 80
   425        targetPort: http
   426  `
   427  
   428  const JobYAML = `
   429  apiVersion: batch/v1
   430  kind: Job
   431  metadata:
   432    name: pi
   433  spec:
   434    template:
   435      spec:
   436        containers:
   437        - name: pi
   438          image: perl
   439          command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
   440        restartPolicy: Never
   441    backoffLimit: 4
   442  `
   443  
   444  const PodYAML = `apiVersion: v1
   445  kind: Pod
   446  metadata:
   447   name: sleep
   448   labels:
   449     app: sleep
   450  spec:
   451    restartPolicy: OnFailure
   452    containers:
   453    - name: sleep
   454      image: gcr.io/windmill-public-containers/servantes/sleep
   455  `
   456  
   457  const MultipleContainersYAML = `
   458  apiVersion: batch/v1
   459  kind: Job
   460  metadata:
   461    name: pi
   462  spec:
   463    template:
   464      spec:
   465        containers:
   466        - name: pi1
   467          image: gcr.io/blorg-dev/perl
   468          command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
   469        - name: pi2
   470          image: gcr.io/blorg-dev/perl
   471          command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
   472        restartPolicy: Never
   473    backoffLimit: 4
   474  `
   475  
   476  const MultipleContainersDeploymentYAML = `apiVersion: apps/v1
   477  kind: Deployment
   478  metadata:
   479    name: test-deployment
   480  spec:
   481    replicas: 1
   482    template:
   483      spec:
   484        containers:
   485          - name: client
   486            image: dockerhub.io/client:0.1.0-dev
   487            imagePullPolicy: Always
   488            ports:
   489            - name: http-client
   490              containerPort: 9000
   491              protocol: TCP
   492          - name: backend
   493            image: dockerhub.io/backend:0.1.0-dev
   494            imagePullPolicy: Always
   495            ports:
   496            - name: http-backend
   497              containerPort: 8000
   498              protocol: TCP
   499            volumeMounts:
   500            - name: config
   501              mountPath: /etc/backend
   502              readOnly: true
   503        volumes:
   504          - name: config
   505            configMap:
   506              name: fe-backend
   507              items:
   508              - key: config
   509                path: config.yaml`
   510  
   511  const SyncletYAML = `apiVersion: apps/v1beta2
   512  kind: DaemonSet
   513  metadata:
   514    name: owner-synclet
   515    namespace: kube-system
   516    labels:
   517      app: synclet
   518      owner: owner
   519      environment: dev
   520  spec:
   521    selector:
   522      matchLabels:
   523        app: synclet
   524        owner: owner
   525        environment: dev
   526    template:
   527      metadata:
   528        labels:
   529          app: synclet
   530          owner: owner
   531          environment: dev
   532      spec:
   533        tolerations:
   534        - key: node-role.kubernetes.io/master
   535          effect: NoSchedule
   536        containers:
   537        - name: synclet
   538          image: gcr.io/windmill-public-containers/synclet
   539          imagePullPolicy: Always
   540          volumeMounts:
   541          - name: dockersocker
   542            mountPath: /var/run/docker.sock
   543          securityContext:
   544            privileged: true
   545        - image: jaegertracing/jaeger-agent
   546          name: jaeger-agent
   547          ports:
   548          - containerPort: 5775
   549            protocol: UDP
   550          - containerPort: 6831
   551            protocol: UDP
   552          - containerPort: 6832
   553            protocol: UDP
   554          - containerPort: 5778
   555            protocol: TCP
   556          args: ["--collector.host-port=jaeger-collector.default:14267"]
   557        volumes:
   558          - name: dockersocker
   559            hostPath:
   560              path: /var/run/docker.sock
   561  `
   562  
   563  // We deliberately create a pod without any labels, to
   564  // ensure code works without them.
   565  const LonelyPodYAML = `
   566  apiVersion: v1
   567  kind: Pod
   568  metadata:
   569    name: lonely-pod
   570  spec:
   571    containers:
   572    - name: lonely-pod
   573      image: gcr.io/windmill-public-containers/lonely-pod
   574      command: ["/go/bin/lonely-pod"]
   575      ports:
   576      - containerPort: 8001
   577  `
   578  
   579  // Useful if you ever want to play around with
   580  // deploying postgres
   581  const PostgresYAML = `
   582  apiVersion: v1
   583  kind: ConfigMap
   584  metadata:
   585    name: postgres-config
   586    labels:
   587      app: postgres
   588  data:
   589    POSTGRES_DB: postgresdb
   590    POSTGRES_USER: postgresadmin
   591    POSTGRES_PASSWORD: admin123
   592  ---
   593  kind: PersistentVolume
   594  apiVersion: v1
   595  metadata:
   596    name: postgres-pv-volume
   597    labels:
   598      type: local
   599      app: postgres
   600  spec:
   601    storageClassName: manual
   602    capacity:
   603      storage: 5Gi
   604    accessModes:
   605      - ReadWriteMany
   606    hostPath:
   607      path: "/mnt/data"
   608  ---
   609  kind: PersistentVolumeClaim
   610  apiVersion: v1
   611  metadata:
   612    name: postgres-pv-claim
   613    labels:
   614      app: postgres
   615  spec:
   616    storageClassName: manual
   617    accessModes:
   618      - ReadWriteMany
   619    resources:
   620      requests:
   621        storage: 1Gi
   622  ---
   623  apiVersion: apps/v1
   624  kind: StatefulSet
   625  metadata:
   626    name: postgres
   627  spec:
   628    serviceName: postgres
   629    replicas: 3
   630    selector:
   631      matchLabels:
   632        app: postgres
   633    template:
   634      metadata:
   635        labels:
   636          app: postgres
   637      selector:
   638      spec:
   639        updateStrategy:
   640          type: RollingUpdate
   641        containers:
   642          - name: postgres
   643            image: postgres:10.4
   644            imagePullPolicy: "IfNotPresent"
   645            ports:
   646              - containerPort: 5432
   647            envFrom:
   648              - configMapRef:
   649                  name: postgres-config
   650            volumeMounts:
   651              - mountPath: /var/lib/postgresql/data
   652                name: postgredb
   653        volumes:
   654          - name: postgredb
   655            persistentVolumeClaim:
   656              claimName: postgres-pv-claim
   657  ---
   658  apiVersion: v1
   659  kind: Service
   660  metadata:
   661    name: postgres
   662    labels:
   663      app: postgres
   664  spec:
   665    type: NodePort
   666    ports:
   667     - port: 5432
   668    selector:
   669     app: postgres
   670  `
   671  
   672  // Requires significant sorting to get to an order that's "safe" for applying (see kustomize/ordering.go)
   673  const OutOfOrderYaml = `
   674  apiVersion: batch/v1
   675  kind: Job
   676  metadata:
   677    name: blorg-job
   678  spec:
   679    template:
   680      spec:
   681        containers:
   682        - name: blorg-job
   683          image: gcr.io/blorg-dev/blorg-backend:devel-nick
   684          command: ["/app/server",  "-job=clean"]
   685        restartPolicy: Never
   686    backoffLimit: 4
   687  ---
   688  kind: PersistentVolumeClaim
   689  apiVersion: v1
   690  metadata:
   691    name: postgres-pv-claim
   692    labels:
   693      app: postgres
   694  spec:
   695    storageClassName: manual
   696    accessModes:
   697      - ReadWriteMany
   698    resources:
   699      requests:
   700        storage: 1Gi
   701  ---
   702  apiVersion: v1
   703  kind: Service
   704  metadata:
   705    name: postgres
   706    labels:
   707      app: postgres
   708  spec:
   709    type: NodePort
   710    ports:
   711     - port: 5432
   712    selector:
   713     app: postgres
   714  ---
   715  apiVersion: v1
   716  kind: Pod
   717  metadata:
   718   name: sleep
   719   labels:
   720     app: sleep
   721  spec:
   722    restartPolicy: OnFailure
   723    containers:
   724    - name: sleep
   725      image: gcr.io/windmill-public-containers/servantes/sleep
   726  ---
   727  apiVersion: v1
   728  kind: ConfigMap
   729  metadata:
   730    name: postgres-config
   731    labels:
   732      app: postgres
   733  data:
   734    POSTGRES_DB: postgresdb
   735    POSTGRES_USER: postgresadmin
   736    POSTGRES_PASSWORD: admin123
   737  ---
   738  kind: PersistentVolume
   739  apiVersion: v1
   740  metadata:
   741    name: postgres-pv-volume
   742    labels:
   743      type: local
   744      app: postgres
   745  spec:
   746    storageClassName: manual
   747    capacity:
   748      storage: 5Gi
   749    accessModes:
   750      - ReadWriteMany
   751    hostPath:
   752      path: "/mnt/data"
   753  ---
   754  
   755  apiVersion: apps/v1
   756  kind: StatefulSet
   757  metadata:
   758    name: postgres
   759  spec:
   760    serviceName: postgres
   761    replicas: 3
   762    selector:
   763      matchLabels:
   764        app: postgres
   765    template:
   766      metadata:
   767        labels:
   768          app: postgres
   769      selector:
   770      spec:
   771        updateStrategy:
   772          type: RollingUpdate
   773        containers:
   774          - name: postgres
   775            image: postgres:10.4
   776            imagePullPolicy: "IfNotPresent"
   777            ports:
   778              - containerPort: 5432
   779            envFrom:
   780              - configMapRef:
   781                  name: postgres-config
   782            volumeMounts:
   783              - mountPath: /var/lib/postgresql/data
   784                name: postgredb
   785        volumes:
   786          - name: postgredb
   787            persistentVolumeClaim:
   788              claimName: postgres-pv-claim
   789  
   790  `
   791  
   792  const DoggosDeploymentYaml = `
   793  apiVersion: apps/v1
   794  kind: Deployment
   795  metadata:
   796    name: doggos
   797    labels:
   798      app: doggos
   799      breed: corgi
   800      whosAGoodBoy: imAGoodBoy
   801    namespace: the-dog-zone
   802  spec:
   803    selector:
   804      matchLabels:
   805        app: doggos
   806        breed: corgi
   807        whosAGoodBoy: imAGoodBoy
   808    template:
   809      metadata:
   810        labels:
   811          app: doggos
   812          breed: corgi
   813          whosAGoodBoy: imAGoodBoy
   814          tier: web
   815      spec:
   816        containers:
   817        - name: doggos
   818          image: gcr.io/windmill-public-containers/servantes/doggos
   819          command: ["/go/bin/doggos"]
   820  `
   821  
   822  const DoggosServiceYaml = `
   823  apiVersion: v1
   824  kind: Service
   825  metadata:
   826    name: doggos
   827    labels:
   828      app: doggos
   829      whosAGoodBoy: imAGoodBoy
   830  spec:
   831    ports:
   832      - port: 80
   833        targetPort: 8083
   834        protocol: TCP
   835    selector:
   836      app: doggos
   837  `
   838  const (
   839  	DoggosName      = "doggos"
   840  	DoggosNamespace = "the-dog-zone"
   841  )
   842  
   843  const SnackYaml = `
   844  apiVersion: apps/v1
   845  kind: Deployment
   846  metadata:
   847    name: snack
   848    labels:
   849      app: snack
   850  spec:
   851    selector:
   852      matchLabels:
   853        app: snack
   854    template:
   855      metadata:
   856        labels:
   857          app: snack
   858      spec:
   859        containers:
   860        - name: snack
   861          image: gcr.io/windmill-public-containers/servantes/snack
   862          command: ["/go/bin/snack"]
   863  `
   864  const (
   865  	SnackName  = "snack"
   866  	SnackImage = "gcr.io/windmill-public-containers/servantes/snack"
   867  )
   868  
   869  const SnackYAMLPostConfig = `apiVersion: apps/v1
   870  kind: Deployment
   871  metadata:
   872    labels:
   873      app: snack
   874    name: snack
   875  spec:
   876    selector:
   877      matchLabels:
   878        app: snack
   879    strategy: {}
   880    template:
   881      metadata:
   882        labels:
   883          app: snack
   884      spec:
   885        containers:
   886        - command:
   887          - /go/bin/snack
   888          image: gcr.io/windmill-public-containers/servantes/snack
   889          name: snack
   890          resources: {}
   891  `
   892  
   893  const SecretName = "mysecret"
   894  const SecretYaml = `
   895  apiVersion: v1
   896  kind: Secret
   897  metadata:
   898    name: mysecret
   899  type: Opaque
   900  data:
   901    username: YWRtaW4=
   902    password: MWYyZDFlMmU2N2Rm
   903  `
   904  
   905  // Generated with
   906  // helm fetch stable/redis --version 5.1.3 --untar --untardir tmp && helm template tmp/redis --name test
   907  const HelmGeneratedRedisYAML = `
   908  ---
   909  # Source: redis/templates/secret.yaml
   910  apiVersion: v1
   911  kind: Secret
   912  metadata:
   913    name: test-redis
   914    labels:
   915      app: redis
   916      chart: redis-5.1.3
   917      release: "test"
   918      heritage: "Tiller"
   919  type: Opaque
   920  data:
   921    redis-password: "VnF0bkFrUks0cg=="
   922  ---
   923  # Source: redis/templates/configmap.yaml
   924  apiVersion: v1
   925  kind: ConfigMap
   926  metadata:
   927    labels:
   928      app: redis
   929      chart: redis-5.1.3
   930      heritage: Tiller
   931      release: test
   932    name: test-redis
   933  data:
   934    redis.conf: |-
   935      # User-supplied configuration:
   936      # maxmemory-policy volatile-lru
   937    master.conf: |-
   938      dir /data
   939      rename-command FLUSHDB ""
   940      rename-command FLUSHALL ""
   941    replica.conf: |-
   942      dir /data
   943      rename-command FLUSHDB ""
   944      rename-command FLUSHALL ""
   945  
   946  ---
   947  # Source: redis/templates/health-configmap.yaml
   948  apiVersion: v1
   949  kind: ConfigMap
   950  metadata:
   951    labels:
   952      app: redis
   953      chart: redis-5.1.3
   954      heritage: Tiller
   955      release: test
   956    name: test-redis-health
   957  data:
   958    ping_local.sh: |-
   959      response=$(
   960        redis-cli \
   961          -a $REDIS_PASSWORD \
   962          -h localhost \
   963          -p $REDIS_PORT \
   964          ping
   965      )
   966      if [ "$response" != "PONG" ]; then
   967        echo "$response"
   968        exit 1
   969      fi
   970    ping_master.sh: |-
   971      response=$(
   972        redis-cli \
   973          -a $REDIS_MASTER_PASSWORD \
   974          -h $REDIS_MASTER_HOST \
   975          -p $REDIS_MASTER_PORT_NUMBER \
   976          ping
   977      )
   978      if [ "$response" != "PONG" ]; then
   979        echo "$response"
   980        exit 1
   981      fi
   982    ping_local_and_master.sh: |-
   983      script_dir="$(dirname "$0")"
   984      exit_status=0
   985      "$script_dir/ping_local.sh" || exit_status=$?
   986      "$script_dir/ping_master.sh" || exit_status=$?
   987      exit $exit_status
   988  
   989  ---
   990  # Source: redis/templates/redis-master-svc.yaml
   991  apiVersion: v1
   992  kind: Service
   993  metadata:
   994    name: test-redis-master
   995    labels:
   996      app: redis
   997      chart: redis-5.1.3
   998      release: "test"
   999      heritage: "Tiller"
  1000  spec:
  1001    type: ClusterIP
  1002    ports:
  1003    - name: redis
  1004      port: 6379
  1005      targetPort: redis
  1006    selector:
  1007      app: redis
  1008      release: "test"
  1009      role: master
  1010  
  1011  ---
  1012  # Source: redis/templates/redis-slave-svc.yaml
  1013  
  1014  apiVersion: v1
  1015  kind: Service
  1016  metadata:
  1017    name: test-redis-slave
  1018    labels:
  1019      app: redis
  1020      chart: redis-5.1.3
  1021      release: "test"
  1022      heritage: "Tiller"
  1023  spec:
  1024    type: ClusterIP
  1025    ports:
  1026    - name: redis
  1027      port: 6379
  1028      targetPort: redis
  1029    selector:
  1030      app: redis
  1031      release: "test"
  1032      role: slave
  1033  
  1034  ---
  1035  # Source: redis/templates/redis-slave-deployment.yaml
  1036  
  1037  apiVersion: extensions/v1beta1
  1038  kind: Deployment
  1039  metadata:
  1040    name: test-redis-slave
  1041    labels:
  1042      app: redis
  1043      chart: redis-5.1.3
  1044      release: "test"
  1045      heritage: "Tiller"
  1046  spec:
  1047    replicas: 1
  1048    selector:
  1049      matchLabels:
  1050          release: "test"
  1051          role: slave
  1052          app: redis
  1053    template:
  1054      metadata:
  1055        labels:
  1056          release: "test"
  1057          chart: redis-5.1.3
  1058          role: slave
  1059          app: redis
  1060        annotations:
  1061          checksum/health: 0fb018ad71cf7f2bf0bc3482d40b88ccbe3df15cb2a0d51a1f75d02398661bfe
  1062          checksum/configmap: 3ba8fa67229e9f3c03390d9fb9d470d323c0f0f3e07d581e8f46f261945d241b
  1063          checksum/secret: a1edae0cd29184bb1b5065b2388ec3d8c9ccd21eaac533ffceae4fe5ff7ac159
  1064      spec:
  1065        securityContext:
  1066          fsGroup: 1001
  1067          runAsUser: 1001
  1068        serviceAccountName: "default"
  1069        containers:
  1070        - name: test-redis
  1071          image: docker.io/bitnami/redis:4.0.12
  1072          imagePullPolicy: "Always"
  1073          command:
  1074            - /run.sh
  1075  
  1076          args:
  1077          - "--port"
  1078          - "$(REDIS_PORT)"
  1079          - "--slaveof"
  1080          - "$(REDIS_MASTER_HOST)"
  1081          - "$(REDIS_MASTER_PORT_NUMBER)"
  1082          - "--requirepass"
  1083          - "$(REDIS_PASSWORD)"
  1084          - "--masterauth"
  1085          - "$(REDIS_MASTER_PASSWORD)"
  1086          - "--include"
  1087          - "/opt/bitnami/redis/etc/redis.conf"
  1088          - "--include"
  1089          - "/opt/bitnami/redis/etc/replica.conf"
  1090          env:
  1091          - name: REDIS_REPLICATION_MODE
  1092            value: slave
  1093          - name: REDIS_MASTER_HOST
  1094            value: test-redis-master
  1095          - name: REDIS_PORT
  1096            value: "6379"
  1097          - name: REDIS_MASTER_PORT_NUMBER
  1098            value: "6379"
  1099          - name: REDIS_PASSWORD
  1100            valueFrom:
  1101              secretKeyRef:
  1102                name: test-redis
  1103                key: redis-password
  1104          - name: REDIS_MASTER_PASSWORD
  1105            valueFrom:
  1106              secretKeyRef:
  1107                name: test-redis
  1108                key: redis-password
  1109          ports:
  1110          - name: redis
  1111            containerPort: 6379
  1112          livenessProbe:
  1113            initialDelaySeconds: 5
  1114            periodSeconds: 5
  1115            timeoutSeconds: 5
  1116            successThreshold: 1
  1117            failureThreshold: 5
  1118            exec:
  1119              command:
  1120              - sh
  1121              - -c
  1122              - /health/ping_local_and_master.sh
  1123          readinessProbe:
  1124            initialDelaySeconds: 5
  1125            periodSeconds: 5
  1126            timeoutSeconds: 1
  1127            successThreshold: 1
  1128            failureThreshold: 5
  1129            exec:
  1130              command:
  1131              - sh
  1132              - -c
  1133              - /health/ping_local_and_master.sh
  1134          resources:
  1135            null
  1136  
  1137          volumeMounts:
  1138          - name: health
  1139            mountPath: /health
  1140          - name: redis-data
  1141            mountPath: /data
  1142          - name: config
  1143            mountPath: /opt/bitnami/redis/etc
  1144        volumes:
  1145        - name: health
  1146          configMap:
  1147            name: test-redis-health
  1148            defaultMode: 0755
  1149        - name: config
  1150          configMap:
  1151            name: test-redis
  1152        - name: redis-data
  1153          emptyDir: {}
  1154  
  1155  ---
  1156  # Source: redis/templates/redis-master-statefulset.yaml
  1157  apiVersion: apps/v1beta2
  1158  kind: StatefulSet
  1159  metadata:
  1160    name: test-redis-master
  1161    labels:
  1162      app: redis
  1163      chart: redis-5.1.3
  1164      release: "test"
  1165      heritage: "Tiller"
  1166  spec:
  1167    selector:
  1168      matchLabels:
  1169        release: "test"
  1170        role: master
  1171        app: redis
  1172    serviceName: test-redis-master
  1173    template:
  1174      metadata:
  1175        labels:
  1176          release: "test"
  1177          chart: redis-5.1.3
  1178          role: master
  1179          app: redis
  1180        annotations:
  1181          checksum/health: 0fb018ad71cf7f2bf0bc3482d40b88ccbe3df15cb2a0d51a1f75d02398661bfe
  1182          checksum/configmap: 3ba8fa67229e9f3c03390d9fb9d470d323c0f0f3e07d581e8f46f261945d241b
  1183          checksum/secret: 4ce19ad3da007ff5f0c283389f765d43b33ed5fa4fcfb8e212308bedc33d62b2
  1184      spec:
  1185        securityContext:
  1186          fsGroup: 1001
  1187          runAsUser: 1001
  1188        serviceAccountName: "default"
  1189        containers:
  1190        - name: test-redis
  1191          image: "docker.io/bitnami/redis:4.0.12"
  1192          imagePullPolicy: "Always"
  1193          command:
  1194            - /run.sh
  1195  
  1196          args:
  1197          - "--port"
  1198          - "$(REDIS_PORT)"
  1199          - "--requirepass"
  1200          - "$(REDIS_PASSWORD)"
  1201          - "--include"
  1202          - "/opt/bitnami/redis/etc/redis.conf"
  1203          - "--include"
  1204          - "/opt/bitnami/redis/etc/master.conf"
  1205          env:
  1206          - name: REDIS_REPLICATION_MODE
  1207            value: master
  1208          - name: REDIS_PASSWORD
  1209            valueFrom:
  1210              secretKeyRef:
  1211                name: test-redis
  1212                key: redis-password
  1213          - name: REDIS_PORT
  1214            value: "6379"
  1215          ports:
  1216          - name: redis
  1217            containerPort: 6379
  1218          livenessProbe:
  1219            initialDelaySeconds: 5
  1220            periodSeconds: 5
  1221            timeoutSeconds: 5
  1222            successThreshold: 1
  1223            failureThreshold: 5
  1224            exec:
  1225              command:
  1226              - sh
  1227              - -c
  1228              - /health/ping_local.sh
  1229          readinessProbe:
  1230            initialDelaySeconds: 5
  1231            periodSeconds: 5
  1232            timeoutSeconds: 1
  1233            successThreshold: 1
  1234            failureThreshold: 5
  1235            exec:
  1236              command:
  1237              - sh
  1238              - -c
  1239              - /health/ping_local.sh
  1240          resources:
  1241            null
  1242  
  1243          volumeMounts:
  1244          - name: health
  1245            mountPath: /health
  1246          - name: redis-data
  1247            mountPath: /data
  1248            subPath:
  1249          - name: config
  1250            mountPath: /opt/bitnami/redis/etc
  1251        initContainers:
  1252        - name: volume-permissions
  1253          image: "docker.io/bitnami/minideb:latest"
  1254          imagePullPolicy: "IfNotPresent"
  1255          command: ["/bin/chown", "-R", "1001:1001", "/data"]
  1256          securityContext:
  1257            runAsUser: 0
  1258          volumeMounts:
  1259          - name: redis-data
  1260            mountPath: /data
  1261            subPath:
  1262        volumes:
  1263        - name: health
  1264          configMap:
  1265            name: test-redis-health
  1266            defaultMode: 0755
  1267        - name: config
  1268          configMap:
  1269            name: test-redis
  1270    volumeClaimTemplates:
  1271      - metadata:
  1272          name: redis-data
  1273          labels:
  1274            app: "redis"
  1275            component: "master"
  1276            release: "test"
  1277            heritage: "Tiller"
  1278        spec:
  1279          accessModes:
  1280            - "ReadWriteOnce"
  1281          resources:
  1282            requests:
  1283              storage: "8Gi"
  1284    updateStrategy:
  1285      type: RollingUpdate
  1286  
  1287  ---
  1288  # Source: redis/templates/metrics-deployment.yaml
  1289  
  1290  
  1291  ---
  1292  # Source: redis/templates/metrics-prometheus.yaml
  1293  
  1294  ---
  1295  # Source: redis/templates/metrics-svc.yaml
  1296  
  1297  
  1298  ---
  1299  # Source: redis/templates/networkpolicy.yaml
  1300  
  1301  
  1302  ---
  1303  # Source: redis/templates/redis-role.yaml
  1304  
  1305  ---
  1306  # Source: redis/templates/redis-rolebinding.yaml
  1307  
  1308  ---
  1309  # Source: redis/templates/redis-serviceaccount.yaml
  1310  `
  1311  
  1312  // Example CRD YAML from:
  1313  // https://github.com/martin-helmich/kubernetes-crd-example/tree/master/kubernetes
  1314  const CRDYAML = `
  1315  apiVersion: apiextensions.k8s.io/v1beta1
  1316  kind: CustomResourceDefinition
  1317  metadata:
  1318    name: projects.example.martin-helmich.de
  1319  spec:
  1320    group: example.martin-helmich.de
  1321    names:
  1322      kind: Project
  1323      plural: projects
  1324      singular: project
  1325    scope: Namespaced
  1326    validation:
  1327      openAPIV3Schema:
  1328        properties:
  1329          spec:
  1330            properties:
  1331              image: docker.io/bitnami/minideb:latest
  1332              replicas:
  1333                minimum: 1
  1334                type: integer
  1335            required:
  1336            - replicas
  1337        required:
  1338        - spec
  1339    version: v1alpha1
  1340  
  1341  ---
  1342  apiVersion: example.martin-helmich.de/v1alpha1
  1343  kind: Project
  1344  metadata:
  1345    name: example-project
  1346    namespace: default
  1347  spec:
  1348    replicas: 1
  1349  `
  1350  
  1351  const CRDImage = "docker.io/bitnami/minideb:latest"
  1352  
  1353  const MyNamespaceYAML = `apiVersion: v1
  1354  kind: Namespace
  1355  metadata:
  1356    name: mynamespace
  1357  `
  1358  
  1359  const RedisStatefulSetYAML = `
  1360  # Modified from: redis/templates/redis-master-statefulset.yaml
  1361  apiVersion: apps/v1beta2
  1362  kind: StatefulSet
  1363  metadata:
  1364    name: test-redis-master
  1365    labels:
  1366      app: redis
  1367      chart: redis-5.1.3
  1368      release: "test"
  1369      heritage: "Tiller"
  1370  spec:
  1371    selector:
  1372      matchLabels:
  1373        release: "test"
  1374        role: master
  1375        app: redis
  1376    serviceName: test-redis-master
  1377    template:
  1378      metadata:
  1379        labels:
  1380          release: "test"
  1381          chart: redis-5.1.3
  1382          role: master
  1383          app: redis
  1384      spec:
  1385        securityContext:
  1386          fsGroup: 1001
  1387          runAsUser: 1001
  1388        serviceAccountName: "default"
  1389        containers:
  1390        - name: test-redis
  1391          image: "docker.io/bitnami/redis:4.0.12"
  1392          imagePullPolicy: "Always"
  1393          command:
  1394            - /run.sh
  1395  
  1396          args:
  1397          - "--port"
  1398          - "$(REDIS_PORT)"
  1399          - "--requirepass"
  1400          - "$(REDIS_PASSWORD)"
  1401          - "--include"
  1402          - "/opt/bitnami/redis/etc/redis.conf"
  1403          - "--include"
  1404          - "/opt/bitnami/redis/etc/master.conf"
  1405          env:
  1406          - name: REDIS_REPLICATION_MODE
  1407            value: master
  1408          - name: REDIS_PASSWORD
  1409            valueFrom:
  1410              secretKeyRef:
  1411                name: test-redis
  1412                key: redis-password
  1413          - name: REDIS_PORT
  1414            value: "6379"
  1415          ports:
  1416          - name: redis
  1417            containerPort: 6379
  1418          volumeMounts:
  1419          - name: health
  1420            mountPath: /health
  1421          - name: redis-data
  1422            mountPath: /data
  1423            subPath:
  1424          - name: config
  1425            mountPath: /opt/bitnami/redis/etc
  1426        initContainers:
  1427        - name: volume-permissions
  1428          image: "docker.io/bitnami/minideb:latest"
  1429          imagePullPolicy: "IfNotPresent"
  1430          command: ["/bin/chown", "-R", "1001:1001", "/data"]
  1431          securityContext:
  1432            runAsUser: 0
  1433          volumeMounts:
  1434          - name: redis-data
  1435            mountPath: /data
  1436            subPath:
  1437        volumes:
  1438        - name: health
  1439          configMap:
  1440            name: test-redis-health
  1441            defaultMode: 0755
  1442        - name: config
  1443          configMap:
  1444            name: test-redis
  1445    volumeClaimTemplates:
  1446      - metadata:
  1447          name: redis-data
  1448          labels:
  1449            app: "redis"
  1450            component: "master"
  1451            release: "test"
  1452            heritage: "Tiller"
  1453        spec:
  1454          accessModes:
  1455            - "ReadWriteOnce"
  1456          resources:
  1457            requests:
  1458              storage: "8Gi"
  1459    updateStrategy:
  1460      type: RollingUpdate
  1461  `
  1462  
  1463  func Deployment(name string, imageName string) string {
  1464  	result := `
  1465  apiVersion: apps/v1
  1466  kind: Deployment
  1467  metadata:
  1468    name: NAME
  1469    labels:
  1470      app: NAME
  1471  spec:
  1472    replicas: 1
  1473    selector:
  1474      matchLabels:
  1475        app: NAME
  1476    template:
  1477      metadata:
  1478        labels:
  1479          app: NAME
  1480      spec:
  1481        containers:
  1482        - name: NAME
  1483          image: IMAGE
  1484  `
  1485  	result = strings.Replace(result, "NAME", name, -1)
  1486  	result = strings.Replace(result, "IMAGE", imageName, -1)
  1487  	return result
  1488  }
  1489  
  1490  const PodDisruptionBudgetYAML = `
  1491  apiVersion: policy/v1beta1
  1492  kind: PodDisruptionBudget
  1493  metadata:
  1494    labels:
  1495      app: zookeeper
  1496    name: infra-kafka-zookeeper
  1497  spec:
  1498    maxUnavailable: 1
  1499    selector:
  1500      matchLabels:
  1501        app: zookeeper
  1502        component: server
  1503        release: infra-kafka
  1504  `
  1505  
  1506  const DoggosListYAML = `
  1507  apiVersion: v1
  1508  kind: List
  1509  items:
  1510  - apiVersion: v1
  1511    kind: Service
  1512    metadata:
  1513      name: doggos
  1514      labels:
  1515        app: doggos
  1516        whosAGoodBoy: imAGoodBoy
  1517    spec:
  1518      ports:
  1519        - port: 80
  1520          targetPort: 8083
  1521          protocol: TCP
  1522      selector:
  1523        app: doggos
  1524  - apiVersion: apps/v1
  1525    kind: Deployment
  1526    metadata:
  1527      name: doggos
  1528      labels:
  1529        app: doggos
  1530        breed: corgi
  1531        whosAGoodBoy: imAGoodBoy
  1532      namespace: the-dog-zone
  1533    spec:
  1534      selector:
  1535        matchLabels:
  1536          app: doggos
  1537          breed: corgi
  1538          whosAGoodBoy: imAGoodBoy
  1539      template:
  1540        metadata:
  1541          labels:
  1542            app: doggos
  1543            breed: corgi
  1544            whosAGoodBoy: imAGoodBoy
  1545            tier: web
  1546        spec:
  1547          containers:
  1548          - name: doggos
  1549            image: gcr.io/windmill-public-containers/servantes/doggos
  1550            command: ["/go/bin/doggos"]
  1551  `