I am trying to deploy changes to my cluster using `kubectl apply -k ./` in a pipeline. My pipeline looks like this:
pipelines:
custom:
update-ref:
- step:
script:
- sed -E -i "s|([^-]- image:[^:]+).*|\1:$APP_COMMIT|g" deployments/app.yaml
- git add deployments/app.yaml
- git commit -m "[skip ci] Updating deployments/app.yaml with latest build number."
- git push
- pipe: atlassian/kubectl-run:1.1.6
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: 'apply'
KUBECTL_ARGS:
- '-k'
RESOURCE_PATH: './'
# WITH_DEFAULT_LABELS: 'false'
But I get the following error:
Status: Downloaded newer image for bitbucketpipelines/kubectl-run:1.1.6
Traceback (most recent call last):
File "/pipe.py", line 121, in <module>
pipe.run()
File "/pipe.py", line 112, in run
self.handle_apply()
File "/pipe.py", line 77, in handle_apply
self.update_labels_in_metadata(template_file, labels)
File "/pipe.py", line 31, in update_labels_in_metadata
yaml_doc['metadata'].setdefault('labels', {}).update(labels)
KeyError: 'metadata'
I have also tried turning off default labels.
After reviewing the code for kubectl-run I found that if the command is "apply" the -f parameter will be forced and it will only parse yaml-files (not directories).
Since I supplied a directory it would try to parse all the yaml-files inside, looking for metadata in each. kustomization.yaml does not have any metadata and this would lead to the error.
But if I added my whole command it would be parsed as any other command.
I updated my pipeline to the following:
pipelines:
custom:
update-ref:
- step:
script:
- sed -E -i "s|([^-]- image:[^:]+).*|\1:$APP_COMMIT|g" deployments/app.yaml
- git add deployments/app.yaml
- git commit -m "[skip ci] Updating deployments/app.yaml with latest build number."
- git push
- pipe: atlassian/kubectl-run:1.1.6
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: 'apply -k ./'
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.