Pipeline fails
Asked by Brad Vrabete:

The pipe configuration below fails:

*** ** * ** ***

- echo "Kustomize the deployment"  
- pipe: atlassian/aws-eks-kubectl-run:2.1.0 # runs kubectl apply -k against the specific folder; basically patching the initial files in base directory  
variables:  
AWS_ACCESS_KEY_ID: "$AWS_DEV_ACCESS_KEY_ID"  
AWS_SECRET_ACCESS_KEY: "$AWS_DEV_SECRET_ACCESS_KEY"  
AWS_DEFAULT_REGION: "$AWS_DEV_DEFAULT_REGION"  
CLUSTER_NAME: "$AWS_CLUSTER_NAME"  
KUBECTL_COMMAND: "apply"  
KUBECTL_ARGS:  
- "--dry-run=server"  
RESOURCE_PATH: "k8s/deploy/aws-dev"  
KUBECTL_APPLY_ARGS: "-k"  
LABELS:  
- "test.label=Test-deployment"  
WITH_DEFAULT_LABELS: "False"  
DEBUG: "True"  

*** ** * ** ***

<br />

The error is:  

INFO: Successfully updated the kube config.  
Traceback (most recent call last):  
File "/pipe.py", line 47, in <module>  
[pipe.run](http://pipe.run/)()  
File "/root/.local/lib/python3.8/site-packages/kubectl_run/pipe.py", line 157, in run  
self.handle_apply()  
File "/root/.local/lib/python3.8/site-packages/kubectl_run/pipe.py", line 114, in handle_apply  
self.update_labels_in_metadata(template_file, labels)  
File "/root/.local/lib/python3.8/site-packages/kubectl_run/pipe.py", line 37, in update_labels_in_metadata  
yaml_doc['metadata'].setdefault('labels', {}).update(labels)  
TypeError: 'NoneType' object is not iterable

*** ** * ** ***

<br />

A label is defined so this should work. What can I do to fix it?


Answers:
author: Igor Stoyanov
body: [@Brad Vrabete](/t5/user/viewprofilepage/user-id/4061397) Hi. Thanks for your question. This error can occur only if \`LABELS\` is empty. We will try investigate this case and give you feedback soon.  

<br />

Regards, Igor.

comments: author: Brad Vrabete
body: Thanks, Igor. I tried to disable the labels as the branch name was longer than 63 characters accepted by Kubectl for a label.   

Now, if you can see the script, LABELS is definitely not empty:  
LABELS:  
- "test.label=Test-deployment"  
So how would label need to be defined?


author: Igor Stoyanov
body: [@Brad Vrabete](/t5/user/viewprofilepage/user-id/4061397) Seems like you doing it right and the problem on our side.   

The only one temporary solution i can provide is to pass labels directly to your template file "k8s/deploy/aws-dev" under \`kind: Deployment metadata\`.  
Example of the template:

```
template = """
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  <pass your custom labels here>
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:1.7.9
        name: nginx
        ports:
        - containerPort: 80
"""
```


author: Brad Vrabete
body: I actually found an easier way:

script:  
# shrink bitbucket branch name to less than 63 characters  
**-****branch="${BITBUCKET_BRANCH}"**  
**- export BITBUCKET_BRANCH=${branch:0:62}**  
- pipe: atlassian/aws-eks-kubectl-run:2.1.0 # runs kubectl apply -k against the specific folder; basically patching the initial files in base directory  
variables:  
AWS_ACCESS_KEY_ID: "$AWS_DEV_ACCESS_KEY_ID"  
AWS_SECRET_ACCESS_KEY: "$AWS_DEV_SECRET_ACCESS_KEY"  
AWS_DEFAULT_REGION: "$AWS_DEV_DEFAULT_REGION"  
CLUSTER_NAME: "$AWS_DEV_CLUSTER_NAME"  
KUBECTL_COMMAND: "apply"  
KUBECTL_ARGS:  
- "--dry-run=server"  
RESOURCE_PATH: "k8s/deploy/aws-dev"  
KUBECTL_APPLY_ARGS: "-k"  
WITH_DEFAULT_LABELS: "True"


author: Igor Stoyanov
body: Good to know you found a solution for your case. Anyway, thanks for your feedback about problem with LABELS you have found.


author: Igor Stoyanov
body: Hi [@Brad Vrabete](/t5/user/viewprofilepage/user-id/4061397) . The issue with LABELS fixed in [aws-eks-kubectl-run:2.3.0 pipe](https://bitbucket.org/atlassian/aws-eks-kubectl-run/src/2.3.0/) .  

Regards, Igor


Tags: aws

bitbucket-pipelines

cloud

kubernetes