Duplicate environment variables giving errors with the Deployment Config in RHOCP 4

Solution Verified - Updated -

Environment

  • Red Hat OpenShift Container Platform (RHOCP)
    • ≥ 4.14

Issue

  • The DeploymentConfig initially had the ENV variable listed twice with different values but now it's not working
  • Getting below error on pod when there are multiple values for Environment Variable:
error: couldn't assign source annotation to deployment <dc-name>: failed to create manager for existing fields: failed to convert new object (<ns>/<rs_name>; /v1, Kind=ReplicationController) to smd typed: .spec.template.spec.containers[name="<container-name>"].env: duplicate entries for key [name="DUP_ENV_KEY"]
  • DeploymentConfig is failing when duplicate environment variables are existing in DeploymentConfig yaml.

Resolution

  • Remove the duplicate entries to fix the issue.

Root Cause

  • The deployer pod uses also the apply operation similar to kubectl apply (beware of a difference server-side vs client side). This is tracked in k8s-issue-58477.
    The reason behind the bug is described in this comment.
  • The validation lets you create the ReplicationController with multiple same ENV vars (with a warning) for compatibility reason with the old apply. Or the objects were persisted in etcd before the validation was put in place. Nevertheless the validation will error out with the server-side apply.

Diagnostic Steps

  • Check the failing pods over the application namespace:
$ oc get pod <podname-1>
NAME                    READY   STATUS   RESTARTS   AGE
<podname-1>     0/1     Error    0          2d
  • Check the error message in the pod yaml:
$ oc get pod <podname-1> -oyaml 
    state:
      terminated:
        containerID: cri-o://xxx....
        exitCode: 1
        finishedAt: "2024-11-08T23:26:15Z"
        message: |
          error: couldn't assign source annotation to deployment <dc-name>: failed to create manager for existing fields: failed to convert new object (<ns>/<rs_name>; /v1, Kind=ReplicationController) to smd typed: .spec.template.spec.containers[name="<container-name>"].env: duplicate entries for key [name="DUP_ENV_KEY"]
        reason: Error
        startedAt: "2024-11-08T23:26:15Z"
  • Verify that the RC has the duplicate entries:
        - name: DUP_ENV_KEY
          value: Value_1
        [...]
        - name: DUP_ENV_KEY
          value: Value_2

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments