How to fix 'map[] does not contain declared merge key: name' error when I edit and save the pod yaml?
Asked Answered
U

4

9

I 'm trying to pull an image from a private registry. But the status of pod is 'ImagePullBackOff', which means I need to add a secret to the pod.

Events:
  Type     Reason   Age                  From                                          Message
  ----     ------   ----                 ----                                          -------
  Normal   Pulling  52m (x255 over 22h)  kubelet, cn-huhehaote.i-hp3fkfzlcf1u9cigq2h7  pulling image "xxx/fcp"
  Normal   BackOff  8m (x5597 over 22h)  kubelet, cn-huhehaote.i-hp3fkfzlcf1u9cigq2h7  Back-off pulling image "xxx/fcp"
  Warning  Failed   3m (x5618 over 22h)  kubelet, cn-huhehaote.i-hp3fkfzlcf1u9cigq2h7  Error: ImagePullBackOff

So I added the following code in pod yaml.

spec:
      containers:
      - name: private-reg-container
        image: <your-private-image>
      imagePullSecrets:
      - name: my-secret

Then I got

error: map: map[] does not contain declared merge key: name

The solution I searched out is to delete 'imagePullSecret', which doesn't work for me. I wonder how to fix the error. Can anyone help me?

kubectl version is

 kubectl version
Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.5", GitCommit:"753b2dbc622f5cc417845f0ff8a77f539a4213ea", GitTreeState:"clean", BuildDate:"2018-11-26T14:41:50Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.5", GitCommit:"753b2dbc622f5cc417845f0ff8a77f539a4213ea", GitTreeState:"clean", BuildDate:"2018-11-26T14:31:35Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}

Undesirable answered 17/4, 2019 at 8:40 Comment(7)
Can you share which version of Kubernetes you are using? Paste the output for kubectl version. Also, instead of a snippet, can you share your full Pod yaml code?Cuomo
I just paste the output please check. The pod is controller-manager pod. I haven't edited the yaml code before. I failed to initialize federation control plane. Kubefed init says "waiting for the federation control plane to come up" but it never comes up, so I checked the pod status and found this error.Undesirable
So you are trying to use your custom version for the controller-manager?Cuomo
@fiunchinho Yes, I follow the direction Building Kubernetes cluster federation, but can't pull the image.Undesirable
Not helpful, but it looks like cluster federation is deprecated kubernetes.io/docs/tasks/federation/…Cuomo
Thank you all the same. I've followed this guide before and found kubefed init failed because the image given is not available.Undesirable
Added community wiki answer for futureNew
M
9

I've stumbled with the same problem (using helm) and I've found out, that it is not allowed to edit the imagePullSecret section in the deployment...

The solution was to delete the deployment and recreate it.

Micropyle answered 20/11, 2019 at 10:45 Comment(2)
As far as I know, It is possible to use patch syntax for this. For example: kubectl -n example patch deployment mydeployment -p '{"imagePullSecrets": [{"name": "registry"}]}', if deployment deletion is not the case.Stay
@DariyN and --force flag (I'm not sure if it's kubectl or oc extension), but generally, helm fail in that case...Micropyle
S
1

Things may be different now in early 2023. I didn't have to delete the deployment (fortunately).

I had to delete the existing (empty) imagePullSecrets and then patch them. So:

# Delete existing imagePullSecret
kubectl patch deployment my-deploy \
  --type=json \
  -p='[{"op": "remove", "path": "/spec/template/spec/imagePullSecrets"}]'

# Now add the correct one
kubectl patch deployment my-deploy \
  --patch '{"spec": {"template": {"spec": {"imagePullSecrets": [{"name": "my-registry-creds"}]}}}}'
Suzannasuzanne answered 11/1, 2023 at 21:58 Comment(0)
P
0

Recently, I encountered the same issue in ArgoCD while deploying an application.yaml using Helm, after investigating several options, I discovered that two issues were related when the state of certain resources, such as Secret or ConfigMap, does not synchronize correctly and appears as 'Unknown', ArgoCD also generates the ComparisonError message:

Failed to compare desired state to live state: failed to calculate diff: map: map[] does not contain declared merge key: name

"Failed to compare desired state to live state: failed to calculate diff: map: map[] does not contain declared merge key: name"

To resolve both issues, I accessed the ArgoCD web interface and navigated to the affected application and I selected the ConfigMap in the 'Unknown' state and delete it using the 'Foreground Delete' (option) since this ensures that all dependent resources are completely removed before completing the operation.

ConfigMap in the 'Unknown' state deleted using using the 'Foreground Delete' (option)

After ArgoCD detected the deletion of the ConfigMap and automatically recreated it, synchronizing the repository and updating the state of the resources.

The 'Unknown' state of the resources was correctly updated, and also the 'ComparisonError' disappeared, allowing ArgoCD to correctly compare the desired state with the actual state.

Perceval answered 30/8 at 3:50 Comment(0)
N
-2

As @fiunchinho mentioned in comments and as per Federation with Kubefed - cluster federation is deprecated.

Use of Federation v1 is strongly discouraged. Federation V1 never achieved GA status and is no longer under active development. Documentation is for historical purposes only.

The solution is to use Kubernetes Federation v2. For more details you can refer to Federation v2 user guide and Federation v development guide

New answered 17/4, 2019 at 8:41 Comment(2)
I fail to see the connection between that answer and the question....Micropyle
"I just paste the output please check. The pod is controller-manager pod. I haven't edited the yaml code before. I failed to initialize federation control plane. Kubefed init says "waiting for the federation control plane to come up" but it never comes up, so I checked the pod status and found this error. – Xiang Li Apr 17 at 9:56 "New

© 2022 - 2024 — McMap. All rights reserved.