diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ce1c4e4bf9c7c37bf5fa128361cd89938c5e6d2f..5d1c07a58ae1dbf7ca6586baf15f9f29322465ce 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,14 +1,21 @@ image: gitlab-registry.cern.ch/linuxsupport/alma9-base +include: + - project : 'ci-tools/container-image-ci-templates' + file : 'helm.gitlab-ci.yml' + ref: master + stages: - lint - test - build - - tag - - release + - deploy docs_lint: stage: lint + rules: + - if: '$CI_COMMIT_TAG' + when: never script: - dnf install -y python-pip - python3 -m pip install linkcheckmd @@ -17,6 +24,9 @@ docs_lint: yaml_lint: stage: lint + rules: + - if: '$CI_COMMIT_TAG' + when: never script: - dnf install -y epel-release - dnf install -y yamllint @@ -24,6 +34,9 @@ yaml_lint: helm_lint: stage: lint + rules: + - if: '$CI_COMMIT_TAG' + when: never image: alpine/helm script: - helm dep update . @@ -32,112 +45,41 @@ helm_lint: version_test: stage: test rules: - - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "qa"' - changes: - paths: - - Chart.yaml - - values.yaml - - templates/* + - if: '$CI_COMMIT_TAG' script: | - dnf install -y python3-pip - pip install yq - MASTER_VERSION=$(curl https://gitlab.cern.ch/monitoring/helm-charts/kubernetes-monitoring/-/raw/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME/Chart.yaml?ref_type=heads | yq .version) - LOCAL_VERSION=$(cat Chart.yaml | yq .version) - if [ $MASTER_VERSION == $LOCAL_VERSION ]; then - echo "Please, update Chart.yaml version before merge." - exit -1 + # Installing helm... + dnf install -y diffutils wget tar + wget https://get.helm.sh/helm-v3.15.3-linux-386.tar.gz + tar -zxvf helm-v3.15.3-linux-386.tar.gz + mv linux-386/helm /usr/local/bin/helm + rm helm-v3.15.3-linux-386.tar.gz + rm -rf linux-386 + + # Check if the tag already exists in harbor to avoid overrides. + if helm pull oci://registry.cern.ch/monit/cern-it-monitoring-kubernetes --version $CI_COMMIT_TAG; then + # Command was successful (exit code 0), so the tag exists + echo "The tag $TAG already exists in harbor. Please update it." + exit 1 # Exit with non-zero status to indicate tag exists else - echo "Chart version changed from $MASTER_VERSION to $LOCAL_VERSION." + # Command failed (non-zero exit code), so the tag does not exist + echo "The tag $TAG does not exist in harbor. All ok..." + exit 0 # Exit with 0 status fi -helm_test: - stage: test +helm_deploy: + stage: deploy + needs: + - version_test rules: - - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"' - changes: - paths: - - Chart.yaml - - values.yaml - - templates/* + - if: '$CI_COMMIT_TAG' script: | - dnf install -y python3-pip - pip install yq - dnf install -y python3-setuptools - dnf install -y gcc - dnf install -y python3-devel - dnf install -y epel-release dnf install -y diffutils wget tar wget https://get.helm.sh/helm-v3.15.3-linux-386.tar.gz tar -zxvf helm-v3.15.3-linux-386.tar.gz mv linux-386/helm /usr/local/bin/helm rm helm-v3.15.3-linux-386.tar.gz rm -rf linux-386 - - curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" - install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl - rm kubectl - - pip install python-openstackclient - pip install python-magnumclient - dnf install openssl - - export OS_AUTH_URL=$CI_OS_AUTH_URL - export OS_PROJECT_ID=$CI_OS_PROJECT_ID - export OS_PROJECT_NAME=$CI_OS_PROJECT_NAME - export OS_USER_DOMAIN_NAME=$CI_OS_USER_DOMAIN_NAME - export OS_USERNAME=$CI_OS_USERNAME - export OS_PASSWORD=$CI_OS_PASSWORD - export OS_REGION_NAME=$CI_OS_REGION_NAME - export OS_INTERFACE=$CI_OS_INTERFACE - export OS_IDENTITY_API_VERSION=$CI_OS_IDENTITY_API_VERSION - - echo "OpenStack configured as:" - echo "OS_AUTH_URL $OS_AUTH_URL" - echo "OS_PROJECT_ID $OS_PROJECT_ID" - echo "OS_PROJECT_NAME $OS_PROJECT_NAME" - echo "OS_USER_DOMAIN_NAME $OS_USER_DOMAIN_NAME" - echo "OS_USERNAME $OS_USERNAME" - echo "OS_PASSWORD $OS_PASSWORD" - echo "OS_REGION_NAME $OS_REGION_NAME" - echo "OS_INTERFACE $OS_INTERFACE" - echo "OS_IDENTITY_API_VERSION $OS_IDENTITY_API_VERSION" - - CLUSTER_NAME=test-cluster-$(openssl rand -hex 2) - echo "Creating cluster $CLUSTER_NAME..." - - openstack coe cluster create \ - --cluster-template kubernetes-1.30.2-1 \ - --node-count 1 \ - --flavor m2.medium \ - --merge-labels \ - --labels eos_enabled=false \ - --labels cern_enabled=false \ - $CLUSTER_NAME - sleep 10 - - - STATUS=$(openstack coe cluster show $CLUSTER_NAME -c status -f value) - while [ "${STATUS}" != "CREATE_COMPLETE" ] && [ "${STATUS}" != "CREATE_FAILED" ] - do - STATUS=$(openstack coe cluster show $CLUSTER_NAME -c status -f value) - echo "Current cluster status ... $STATUS $(date)" - sleep 10 - done - - echo "Cluster $CLUSTER_NAME CREATED. Configuring credentials." - openstack coe cluster config --force $CLUSTER_NAME 2> /dev/null || true - echo "Exporting Kubeconfig..." - export KUBECONFIG=$(pwd)/config - - echo "Installing and testing helm chart" - LOCAL_VERSION=$(cat Chart.yaml | yq -r .version) - kubectl delete -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/bundle.yaml || true - helm dependency update + sed -i "s/^version:.*/version: ${CI_COMMIT_TAG}/" Chart.yaml helm package . - ls -all - helm install cern-it-kubernetes-monitoring-crds https://gitlab.cern.ch/monitoring/helm-charts/kubernetes-monitoring-crds/-/archive/v0.1.0/kubernetes-monitoring-crds-v0.1.0.tar.gz -n monitoring --create-namespace - helm install cern-it-kubernetes-monitoring ./cern-it-kubernetes-monitoring-$LOCAL_VERSION.tgz -f values.yaml -n monitoring --create-namespace - helm test --logs cern-it-kubernetes-monitoring -n monitoring - - echo "Deleting temporal cluster." - openstack coe cluster delete $CLUSTER_NAME + echo $REGISTRY_PASSWORD | helm registry login https://registry.cern.ch/v2/ -u $REGISTRY_USER --password-stdin + helm push cern-it-monitoring-kubernetes-$CI_COMMIT_TAG.tgz oci://registry.cern.ch/monit diff --git a/Chart.yaml b/Chart.yaml index cbb8dfc0a6e88a731c3a85d4714edde55798a80c..562067da79ba4080f1c6e8d38a8a0f825d0b523b 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 -name: cern-it-kubernetes-monitoring +name: cern-it-monitoring-kubernetes +version: 0.0.0 # DO NOT UPDATE MANUALLY! type: application -version: 0.2.0 kubeVersion: ">=1.27.0-0" description: Helm Chart provided by IT Monitoring Service to install and configure required components to gather and send monitoring data from kubernetes clusters to central service. home: https://cern.ch/monitoring