apiVersion: v1
kind: List
metadata:
  name: mustachetemplate-controller-list
  annotations:
    version: "{{{TRAVIS_COMMIT}}}"
    razee.io/git-repo: "{{{GIT_REMOTE}}}"
    razee.io/commit-sha: "{{{TRAVIS_COMMIT}}}"
type: array
items:
  - apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: mustachetemplate-controller
      annotations:
        razee.io/git-repo: "{{{GIT_REMOTE}}}"
        razee.io/commit-sha: "{{{TRAVIS_COMMIT}}}"
      labels:
        razee/watch-resource: "lite"
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: mustachetemplate-controller
      strategy:
        type: RollingUpdate
      template:
        metadata:
          labels:
            app: mustachetemplate-controller
            razee/watch-resource: "lite"
          name: mustachetemplate-controller
        spec:
          serviceAccountName: razeedeploy-sa
          securityContext:
            runAsUser: {{{NODE_USER_ID}}}
            runAsGroup: {{{NODE_GROUP_ID}}}
            fsGroup: {{{NODE_GROUP_ID}}}
          containers:
            - image: "quay.io/razee/mustachetemplate:{{{TRAVIS_TAG}}}"
              resources:
                limits:
                  memory: 200Mi
                  cpu: 100m
                requests:
                  memory: 75Mi
                  cpu: 40m
              env:
                - name: USER_AGENT_NAME
                  value: razee-io/mustachetemplate
                - name: USER_AGENT_VERSION
                  value: "{{{TRAVIS_TAG}}}"
                - name: FETCHENVS_CACHE_SIZE
                  valueFrom:
                    configMapKeyRef:
                      name: razeedeploy-overrides
                      key: FETCHENVS_CACHE_SIZE
                      optional: true
                - name: MTP_RECONCILE_BY_DEFAULT
                  valueFrom:
                    configMapKeyRef:
                      name: razeedeploy-overrides
                      key: MTP_RECONCILE_BY_DEFAULT
                      optional: true
                - name: CRD_WATCH_TIMEOUT_SECONDS
                  valueFrom:
                    configMapKeyRef:
                      name: razeedeploy-overrides
                      key: CRD_WATCH_TIMEOUT_SECONDS
                      optional: true
                - name: WATCH_RESOURCE_REFERENCES
                  valueFrom:
                    configMapKeyRef:
                      name: razeedeploy-overrides
                      key: WATCH_RESOURCE_REFERENCES
                      optional: true
              imagePullPolicy: IfNotPresent
              name: mustachetemplate-controller
              livenessProbe:
                exec:
                  command:
                    - sh/liveness.sh
                initialDelaySeconds: 30
                periodSeconds: 150
                timeoutSeconds: 30
                failureThreshold: 1
              volumeMounts:
                - mountPath: /home/node/config
                  name: razeedeploy-config
          volumes:
            - name: razeedeploy-config
              configMap:
                name: razeedeploy-config
                defaultMode: 400
                optional: true
  - apiVersion: apiextensions.k8s.io/v1
    kind: CustomResourceDefinition
    metadata:
      # name must match the spec fields below, and be in the form: <plural>.<group>
      name: mustachetemplates.deploy.razee.io
      annotations:
        razee.io/git-repo: "{{{GIT_REMOTE}}}"
        razee.io/commit-sha: "{{{TRAVIS_COMMIT}}}"
      labels:
        deploy.razee.io/Reconcile: "false"
    spec:
      # group name to use for REST API: /apis/<group>/<version>
      group: deploy.razee.io
      # either Namespaced or Cluster
      scope: Namespaced
      names:
        # plural name to be used in the URL: /apis/<group>/<version>/<plural>
        plural: mustachetemplates
        # singular name to be used as an alias on the CLI and for display
        singular: mustachetemplate
        # kind is normally the CamelCased singular type. Your resource manifests use this.
        kind: MustacheTemplate
        # shortNames allow shorter string to match your resource on the CLI
        shortNames:
          - mtp
      # list of versions supported by this CustomResourceDefinition
      versions:
        - name: v1alpha2
          # Each version can be enabled/disabled by Served flag.
          served: true
          # One and only one version must be marked as the storage version.
          storage: true
          subresources:
            # status enables the status subresource.
            status: {}
          schema:
            # openAPIV3Schema is the schema for validating custom objects.
            openAPIV3Schema:
              type: object
              required: [spec]
              properties:
                spec:
                  type: object
                  allOf:
                    - anyOf:
                        - required: [templates]
                        - required: [strTemplates]
                    - anyOf:
                        - required: [envFrom]
                        - required: [env]
                  properties:
                    clusterAuth:
                      type: object
                      properties:
                        impersonateUser:
                          type: string
                    templateEngine:
                      type: string
                      pattern: "^mustache$|^handlebars$"
                    custom-tags:
                      type: array
                      maxItems: 2
                      minItems: 2
                      items:
                        type: string
                        maxLength: 3
                        minLength: 2
                    envFrom:
                      type: array
                      items:
                        type: object
                        oneOf:
                          - required: [configMapRef]
                          - required: [secretMapRef]
                          - required: [genericMapRef]
                        properties:
                          optional:
                            type: boolean
                          configMapRef:
                            type: object
                            required: [name]
                            properties:
                              name:
                                type: string
                              namespace:
                                type: string
                          secretMapRef:
                            type: object
                            required: [name]
                            properties:
                              name:
                                type: string
                              namespace:
                                type: string
                          genericMapRef:
                            type: object
                            required: [apiVersion, kind, name]
                            properties:
                              apiVersion:
                                type: string
                              kind:
                                type: string
                              name:
                                type: string
                              namespace:
                                type: string
                    env:
                      type: array
                      items:
                        type: object
                        allOf:
                          - required: [name]
                          - # all array items should be oneOf ['value', 'valueFrom']
                            oneOf:
                              - required: [value]
                                # if 'value', neither 'optional' nor 'default' may be used
                                not:
                                  anyOf:
                                    - required: [default]
                                    - required: [optional]
                              - required: [valueFrom]
                                # if 'valueFrom', you must define oneOf:
                                oneOf:
                                  - # neither 'optional' nor 'default' is used
                                    not:
                                      anyOf:
                                        - required: [default]
                                        - required: [optional]
                                  - # 'optional' is used by itself
                                    required: [optional]
                                    not:
                                      required: [default]
                                  - # 'optional' and 'default' are used together IFF optional == true
                                    required: [optional, default]
                                    properties:
                                      optional:
                                        enum: [true]
                        properties:
                          optional:
                            type: boolean
                          default:
                            x-kubernetes-int-or-string: true
                          name:
                            type: string
                          overrideStrategy:
                            type: string
                            pattern: "^merge$|^replace$"
                          value:
                            x-kubernetes-int-or-string: true
                          valueFrom:
                            type: object
                            oneOf:
                              - required: [configMapKeyRef]
                              - required: [secretKeyRef]
                              - required: [genericKeyRef]
                            properties:
                              configMapKeyRef:
                                type: object
                                oneOf:
                                  - required: [key, name]
                                  - required: [key, matchLabels]
                                properties:
                                  name:
                                    type: string
                                  key:
                                    type: string
                                  namespace:
                                    type: string
                                  type:
                                    type: string
                                    enum: [number, boolean, json, jsonString, base64]
                                  matchLabels:
                                    type: object
                                    x-kubernetes-preserve-unknown-fields: true
                                    additionalProperties: true
                              secretKeyRef:
                                type: object
                                oneOf:
                                  - required: [key, name]
                                  - required: [key, matchLabels]
                                properties:
                                  name:
                                    type: string
                                  key:
                                    type: string
                                  namespace:
                                    type: string
                                  type:
                                    type: string
                                    enum: [number, boolean, json, jsonString, base64]
                                  matchLabels:
                                    type: object
                                    x-kubernetes-preserve-unknown-fields: true
                                    additionalProperties: true
                              genericKeyRef:
                                type: object
                                oneOf:
                                  - required: [apiVersion, kind, name, key]
                                  - required: [apiVersion, kind, matchLabels, key]
                                properties:
                                  apiVersion:
                                    type: string
                                  kind:
                                    type: string
                                  name:
                                    type: string
                                  key:
                                    type: string
                                  namespace:
                                    type: string
                                  type:
                                    type: string
                                    enum: [number, boolean, json, jsonString, base64]
                                  matchLabels:
                                    type: object
                                    x-kubernetes-preserve-unknown-fields: true
                                    additionalProperties: true
                    templates:
                      type: array
                      items:
                        type: object
                        x-kubernetes-embedded-resource: true
                        x-kubernetes-preserve-unknown-fields: true
                    strTemplates:
                      type: array
                      items:
                        type: string
                status:
                  type: object
                  x-kubernetes-preserve-unknown-fields: true
