hgop / syllabus-2022

0 stars 1 forks source link

CircleCi pipeline fails due to namespace error #18

Closed piotr20a closed 2 years ago

piotr20a commented 2 years ago

Expected Behavior

I am trying to run the pipeline config script in my CircleCi. The script runs fully, til the Kubernetes deployment part.

Output

The Kubernetes deployment script fails due to a namespace error in the merged files.

Context

The output of the error and part of the script that fails: Screenshot_2022-11-24_at_10 19 14

Error from server (Invalid): error when applying patch:
{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"smackmytest"},"name":"smackmytest","namespace":"default"},"spec":{"ports":[{"name":"http","port":8000,"targetPort":3000}],"selector":{"app":"smackmytest---"}}}\n"}},"spec":{"selector":{"app":"smackmytest---"}}}
to:
Resource: "/v1, Resource=services", GroupVersionKind: "/v1, Kind=Service"
Name: "smackmytest", Namespace: "default"
for: "connect4-client.yaml": error when patching "connect4-client.yaml": Service "smackmytest" is invalid: spec.selector: Invalid value: "smackmytest---": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'myvalue',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9.])?[A-Za-z0-9])?')
Error from server (Invalid): error when applying patch:
{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"httpbin"},"name":"httpbin","namespace":"default"},"spec":{"ports":[{"name":"http","port":8000,"targetPort":80}],"selector":{"app":"httpbin---"}}}\n"}},"spec":{"selector":{"app":"httpbin---"}}}
to:
Resource: "/v1, Resource=services", GroupVersionKind: "/v1, Kind=Service"
Name: "httpbin", Namespace: "default"
for: "httpbin.yaml": error when patching "httpbin.yaml": Service "httpbin" is invalid: spec.selector: Invalid value: "httpbin---": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'myvalue',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9.])?[A-Za-z0-9])?')

Exited with code exit status 1
Screenshot 2022-11-24 at 10 40 13
arnarthor commented 2 years ago

Why is the name of the httpbin app set to httpbin---. The error states that the selector is invalid and the name of the app must start and end with a alphanumeric character, therefore httpbin--- is invalid.

Name: "httpbin", Namespace: "default"
for: "httpbin.yaml": error when patching "httpbin.yaml": Service "httpbin" is invalid: spec.selector: Invalid value: "httpbin---": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'myvalue',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9.])?[A-Za-z0-9])?')

Do your httpbin kubernetes templates have the name set to httpbin---, if so, you'll need to change them to httpbin

Fanneyyy commented 2 years ago

Correct, the issue is the "---" should be on the next line, could you make sure this is the script you're running:

#!/bin/bash

set -euo pipefail

DIRECTORY="$1"

yamls="$(ls -1 "${DIRECTORY}")"

for yaml in ${yamls}; do
    cat "${DIRECTORY}/${yaml}"
    echo $'\n---'
done

exit 0
piotr20a commented 2 years ago

That is indeed correct, did not realize that changes were pushed toward the main course branch about that fix. It works not, therefore the issue can be closed.

siggibjarna commented 2 years ago

If anyone has trouble because they added extra files to the k8s folder, then here is a fix. This way the script only merges *.yaml files and skips other files, such as the markdown file I added for information purposes.

#!/bin/bash

set -euo pipefail

DIRECTORY="$1"

yamls="$(ls -1 "${DIRECTORY}")"

for yaml in ${yamls}; do
    if [[ "${yaml}" == *.yaml ]]; then
        cat "${DIRECTORY}/${yaml}"
        echo $'\n---'
    fi
done

exit 0