Skip to content

Errors adding environment variables and mounting secret volumes to services #793

@andrewbelu

Description

@andrewbelu

The override examples don't seem to be working for me.

With the latest operator code, applying an environment variable override (to add an environment variable as per https://temporal-operator.pages.dev/features/overrides/#example-add-an-environment-variable-to-the-worker-pod

apiVersion: temporal.io/v1beta1
kind: TemporalCluster
metadata:
  name: prod
  namespace: demo
spec:
  version: 1.23.0
  numHistoryShards: 1
  persistence:
    defaultStore:
      sql:
        user: temporal
        pluginName: postgres
        databaseName: temporal
        connectAddr: postgres.demo.svc.cluster.local:5432
        connectProtocol: tcp
      passwordSecretRef:
        name: postgres-password
        key: PASSWORD
    visibilityStore:
      sql:
        user: temporal
        pluginName: postgres
        databaseName: temporal_visibility
        connectAddr: postgres.demo.svc.cluster.local:5432
        connectProtocol: tcp
      passwordSecretRef:
        name: postgres-password
        key: PASSWORD
  services:
    worker:
      overrides:
        deployment:
          spec:
            template:
              spec:
                containers:
                  - name: service
                    env:
                      - name: HTTP_PROXY
                        value: example.com

causes the following error:

2024-08-29T16:34:20.751752301Z 2024-08-29T16:34:20Z     DEBUG   events  failed to create resource prod-worker of Type *v1.Deployment{"type": "Warning", "object": {"kind":"TemporalCluster","namespace":"demo","name":"prod","uid":"c246e4c8-fe32-4fef-8845-03a3f42a6b14","apiVersion":"temporal.io/v1beta1","resourceVersion":"5760"}, "reason": "RessourceCreateError"}
2024-08-29T16:34:20.751760515Z 2024-08-29T16:34:20Z     DEBUG   events  Deployment.apps "prod-worker" is invalid: [spec.template.spec.containers[0].env[0].valueFrom: Invalid value: "": may not be specified when `value` is not empty, spec.template.spec.containers[0].env[1].valueFrom: Invalid value: "": may not be specified when `value` is not empty, spec.template.spec.containers[0].env[2].valueFrom: Invalid value: "": may not be specified when `value` is not empty]   {"type": "Warning", "object": {"kind":"TemporalCluster","namespace":"demo","name":"prod","uid":"c246e4c8-fe32-4fef-8845-03a3f42a6b14","apiVersion":"temporal.io/v1beta1","resourceVersion":"5760"}, "reason": "ProcessingError"}

Additionally, adding an additional volume causes an error as well (taken from https://temporal-operator.pages.dev/features/overrides/#example-mount-an-extra-volume-to-the-frontend-pod)

apiVersion: temporal.io/v1beta1
kind: TemporalCluster
metadata:
  name: prod
  namespace: demo
spec:
  version: 1.23.0
  numHistoryShards: 1
  persistence:
    defaultStore:
      sql:
        user: temporal
        pluginName: postgres
        databaseName: temporal
        connectAddr: postgres.demo.svc.cluster.local:5432
        connectProtocol: tcp
      passwordSecretRef:
        name: postgres-password
        key: PASSWORD
    visibilityStore:
      sql:
        user: temporal
        pluginName: postgres
        databaseName: temporal_visibility
        connectAddr: postgres.demo.svc.cluster.local:5432
        connectProtocol: tcp
      passwordSecretRef:
        name: postgres-password
        key: PASSWORD
  services:
    frontend:
      overrides:
        deployment:
          spec:
            template:
              spec:
                containers:
                  - name: service
                    volumeMounts:
                      - name: extra-volume
                        mountPath: /etc/extra
                volumes:
                  - name: extra-volume
                    secret:
                      secretName: test-secret
---
apiVersion: v1
kind: Secret
metadata:
  name: test-secret
  namespace: demo
type: Opaque
data:
  TEST: TEST

results in the following error in starting the pod:

2024-08-29T16:55:27.928266623Z 2024-08-29T16:55:27Z     DEBUG   events  Deployment.apps "prod-frontend" is invalid: [spec.template.spec.volumes[0].configMap: Forbidden: may not specify more than 1 volume type, spec.template.spec.containers[0].volumeMounts[0].name: Not found: "extra-volume"]       {"type": "Warning", "object": {"kind":"TemporalCluster","namespace":"demo","name":"prod","uid":"c246e4c8-fe32-4fef-8845-03a3f42a6b14","apiVersion":"temporal.io/v1beta1","resourceVersion":"8330"}, "reason": "ProcessingError"}

I think this is due to some of the limitations to StrategicMergePatch with the default object, where the override replaces the existing object at index 0 with something that conflicts on a key, so there may be other fields where the same limitations applies. For example, env can have either the value field or the valueFrom field. When the operator does the StrategicMergePatch call, the result has a value field in index 0 where there was previously a valueFrom field. When kubernetes tries to apply this, it fails, probably similar to the issue in: kubernetes-sigs/kustomize#2734 (comment). The volumes is similar story, it is an array with objects that cannot have both configMap and secret set, so when the first index is overridden with another type it causes this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions