From f6fcbdd2b12bd31c083df661512a71c20102042f Mon Sep 17 00:00:00 2001 From: Anand Francis Joseph Date: Wed, 30 Oct 2024 23:38:39 +0530 Subject: [PATCH 1/3] Added linter for checking if latest changes to Argo CD are already available in the PR Signed-off-by: Anand Francis Joseph --- .github/workflows/lint-argocd-crd.yml | 16 +++++++ Makefile | 6 ++- ...er-manager-metrics-service_v1_service.yaml | 4 +- ...d-operator-webhook-service_v1_service.yaml | 2 +- ...argocd-operator.clusterserviceversion.yaml | 8 ++-- .../manifests/argoproj.io_applications.yaml | 7 --- .../argoproj.io_applicationsets.yaml | 7 --- bundle/manifests/argoproj.io_appprojects.yaml | 7 --- hack/check-argocd-crds.sh | 45 +++++++++++++++++++ 9 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/lint-argocd-crd.yml create mode 100755 hack/check-argocd-crds.sh diff --git a/.github/workflows/lint-argocd-crd.yml b/.github/workflows/lint-argocd-crd.yml new file mode 100644 index 000000000..f8136b723 --- /dev/null +++ b/.github/workflows/lint-argocd-crd.yml @@ -0,0 +1,16 @@ +name: Lint Argo CD CRDs +on: + pull_request: + branches: + - 'master' + - 'release-*' + - 'rhos-*' +jobs: + lint_code: + name: Run golangci-lint on PR + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run linter + run: make lint-argocd-crds \ No newline at end of file diff --git a/Makefile b/Makefile index 45c02a62f..a44a44489 100644 --- a/Makefile +++ b/Makefile @@ -199,7 +199,6 @@ bundle: operator-sdk manifests kustomize ## Generate bundle manifests and metada cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) $(OPERATOR_SDK) bundle validate ./bundle - sed -i 's/control-plane: argocd-operator/control-plane: controller-manager/g' bundle/manifests/argocd-operator-webhook-service_v1_service.yaml bundle/manifests/argocd-operator-controller-manager-metrics-service_v1_service.yaml bundle/manifests/argocd-operator.clusterserviceversion.yaml rm -fr deploy/olm-catalog/argocd-operator/$(VERSION) mkdir -p deploy/olm-catalog/argocd-operator/$(VERSION) cp -r bundle/manifests/* deploy/olm-catalog/argocd-operator/$(VERSION)/ @@ -282,3 +281,8 @@ catalog-build: opm ## Build a catalog image. .PHONY: catalog-push catalog-push: ## Push a catalog image. $(MAKE) docker-push IMG=$(CATALOG_IMG) + +# Lint Argo CD CRDs for the version specified in go.mod. +.PHONY: lint-argocd-crds +lint-argocd-crds: + $(SHELL) hack/check-argocd-crds.sh \ No newline at end of file diff --git a/bundle/manifests/argocd-operator-controller-manager-metrics-service_v1_service.yaml b/bundle/manifests/argocd-operator-controller-manager-metrics-service_v1_service.yaml index f23604e16..8d1547d9a 100644 --- a/bundle/manifests/argocd-operator-controller-manager-metrics-service_v1_service.yaml +++ b/bundle/manifests/argocd-operator-controller-manager-metrics-service_v1_service.yaml @@ -3,7 +3,7 @@ kind: Service metadata: creationTimestamp: null labels: - control-plane: controller-manager + control-plane: argocd-operator name: argocd-operator-controller-manager-metrics-service spec: ports: @@ -11,6 +11,6 @@ spec: port: 8443 targetPort: 8080 selector: - control-plane: controller-manager + control-plane: argocd-operator status: loadBalancer: {} diff --git a/bundle/manifests/argocd-operator-webhook-service_v1_service.yaml b/bundle/manifests/argocd-operator-webhook-service_v1_service.yaml index 101e0db27..f5dda7bc9 100644 --- a/bundle/manifests/argocd-operator-webhook-service_v1_service.yaml +++ b/bundle/manifests/argocd-operator-webhook-service_v1_service.yaml @@ -9,6 +9,6 @@ spec: protocol: TCP targetPort: 9443 selector: - control-plane: controller-manager + control-plane: argocd-operator status: loadBalancer: {} diff --git a/bundle/manifests/argocd-operator.clusterserviceversion.yaml b/bundle/manifests/argocd-operator.clusterserviceversion.yaml index a924e19ed..7f90f5145 100644 --- a/bundle/manifests/argocd-operator.clusterserviceversion.yaml +++ b/bundle/manifests/argocd-operator.clusterserviceversion.yaml @@ -247,7 +247,7 @@ metadata: capabilities: Deep Insights categories: Integration & Delivery certified: "false" - createdAt: "2024-10-16T08:53:24Z" + createdAt: "2024-10-30T17:57:12Z" description: Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes. operators.operatorframework.io/builder: operator-sdk-v1.35.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v4 @@ -1874,20 +1874,20 @@ spec: serviceAccountName: argocd-operator-controller-manager deployments: - label: - control-plane: controller-manager + control-plane: argocd-operator name: argocd-operator-controller-manager spec: replicas: 1 selector: matchLabels: - control-plane: controller-manager + control-plane: argocd-operator strategy: {} template: metadata: annotations: kubectl.kubernetes.io/default-container: manager labels: - control-plane: controller-manager + control-plane: argocd-operator spec: containers: - args: diff --git a/bundle/manifests/argoproj.io_applications.yaml b/bundle/manifests/argoproj.io_applications.yaml index fc06983e5..55abcb203 100644 --- a/bundle/manifests/argoproj.io_applications.yaml +++ b/bundle/manifests/argoproj.io_applications.yaml @@ -1,7 +1,6 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - creationTimestamp: null labels: app.kubernetes.io/name: applications.argoproj.io app.kubernetes.io/part-of: argocd @@ -4998,9 +4997,3 @@ spec: served: true storage: true subresources: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: null - storedVersions: null diff --git a/bundle/manifests/argoproj.io_applicationsets.yaml b/bundle/manifests/argoproj.io_applicationsets.yaml index cc4e2130e..8b33949da 100644 --- a/bundle/manifests/argoproj.io_applicationsets.yaml +++ b/bundle/manifests/argoproj.io_applicationsets.yaml @@ -1,7 +1,6 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - creationTimestamp: null labels: app.kubernetes.io/name: applicationsets.argoproj.io app.kubernetes.io/part-of: argocd @@ -15378,9 +15377,3 @@ spec: storage: true subresources: status: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: null - storedVersions: null diff --git a/bundle/manifests/argoproj.io_appprojects.yaml b/bundle/manifests/argoproj.io_appprojects.yaml index a9d3b475d..2ebe3c2f4 100644 --- a/bundle/manifests/argoproj.io_appprojects.yaml +++ b/bundle/manifests/argoproj.io_appprojects.yaml @@ -1,7 +1,6 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - creationTimestamp: null labels: app.kubernetes.io/name: appprojects.argoproj.io app.kubernetes.io/part-of: argocd @@ -329,9 +328,3 @@ spec: type: object served: true storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: null - storedVersions: null diff --git a/hack/check-argocd-crds.sh b/hack/check-argocd-crds.sh new file mode 100755 index 000000000..3eaa0ee14 --- /dev/null +++ b/hack/check-argocd-crds.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Pre-requisites +# go +# awk +# bash +# wget + +set -e + +ARGOCD_VERSION=$(go list -mod=readonly -m github.com/argoproj/argo-cd/v2 | awk '{print $2}') +ARGOCD_CRD_FILES="application-crd.yaml applicationset-crd.yaml appproject-crd.yaml" + +check_for_sem_ver() { + if [[ $ARGOCD_VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9])?$ ]]; then + echo "Valid argo-cd version: $ARGOCD_VERSION" + return + else + echo "[WARN] argo-cd module version from go.mod does not match the semver pattern." + exit 1 + fi +} + +download_manifests() { + for argocd_crd_file in $ARGOCD_CRD_FILES;do + output_file=argoproj.io_$(echo "${argocd_crd_file}" | sed -e s/-crd.yaml/s.yaml/g) + wget https://raw.githubusercontent.com/argoproj/argo-cd/refs/tags/${ARGOCD_VERSION}/manifests/crds/${argocd_crd_file} -O bundle/manifests/${output_file} + done +} + +check_for_local_changes() { + local_modified_files=$(git status --porcelain | grep "bundle/manifests/argoproj.io_app") + if [[ ! -z "${local_modified_files}" ]]; then + echo "[WARN] There are unexpected local changes to the argo-cd CRD manifests." + echo "${local_modified_files}" + echo "Please update the CRDs from the argo-cd repository, ensure that there are no diffs and re-submit" + exit 1 + else + echo "No local changes to argo-cd CRD manifests" + fi +} + +check_for_sem_ver +download_manifests +check_for_local_changes \ No newline at end of file From ea5d2f0fe942c30bb7414f8ebb94c6e4098a0444 Mon Sep 17 00:00:00 2001 From: Anand Francis Joseph Date: Thu, 31 Oct 2024 08:22:15 +0530 Subject: [PATCH 2/3] Fix argocd cr linting code to avoid errors when grep fails Signed-off-by: Anand Francis Joseph --- hack/check-argocd-crds.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hack/check-argocd-crds.sh b/hack/check-argocd-crds.sh index 3eaa0ee14..deb38aa35 100755 --- a/hack/check-argocd-crds.sh +++ b/hack/check-argocd-crds.sh @@ -13,7 +13,7 @@ ARGOCD_CRD_FILES="application-crd.yaml applicationset-crd.yaml appproject-crd.ya check_for_sem_ver() { if [[ $ARGOCD_VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9])?$ ]]; then - echo "Valid argo-cd version: $ARGOCD_VERSION" + echo "argo-cd version from go.mod: $ARGOCD_VERSION" return else echo "[WARN] argo-cd module version from go.mod does not match the semver pattern." @@ -29,7 +29,7 @@ download_manifests() { } check_for_local_changes() { - local_modified_files=$(git status --porcelain | grep "bundle/manifests/argoproj.io_app") + local_modified_files=$(git status --porcelain | grep "bundle/manifests/argoproj.io_app" | cat) if [[ ! -z "${local_modified_files}" ]]; then echo "[WARN] There are unexpected local changes to the argo-cd CRD manifests." echo "${local_modified_files}" @@ -42,4 +42,4 @@ check_for_local_changes() { check_for_sem_ver download_manifests -check_for_local_changes \ No newline at end of file +check_for_local_changes From 77092792e8ef6d36af660d8ae24cdf1c2769e2df Mon Sep 17 00:00:00 2001 From: Anand Francis Joseph Date: Thu, 31 Oct 2024 09:43:07 +0530 Subject: [PATCH 3/3] Fixed the linter for argocd CRDs and added option to update ArgoCD CRDs Signed-off-by: Anand Francis Joseph --- Makefile | 7 ++++++- ...k-argocd-crds.sh => manage-argocd-crds.sh} | 21 +++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) rename hack/{check-argocd-crds.sh => manage-argocd-crds.sh} (66%) diff --git a/Makefile b/Makefile index a44a44489..afd69a8f7 100644 --- a/Makefile +++ b/Makefile @@ -285,4 +285,9 @@ catalog-push: ## Push a catalog image. # Lint Argo CD CRDs for the version specified in go.mod. .PHONY: lint-argocd-crds lint-argocd-crds: - $(SHELL) hack/check-argocd-crds.sh \ No newline at end of file + $(SHELL) hack/manage-argocd-crds.sh lint + +# Update Argo CD CRDs for the version specified in go.mod. +.PHONY: update-argocd-crds +update-argocd-crds: + $(SHELL) hack/manage-argocd-crds.sh diff --git a/hack/check-argocd-crds.sh b/hack/manage-argocd-crds.sh similarity index 66% rename from hack/check-argocd-crds.sh rename to hack/manage-argocd-crds.sh index deb38aa35..5edb35314 100755 --- a/hack/check-argocd-crds.sh +++ b/hack/manage-argocd-crds.sh @@ -24,22 +24,35 @@ check_for_sem_ver() { download_manifests() { for argocd_crd_file in $ARGOCD_CRD_FILES;do output_file=argoproj.io_$(echo "${argocd_crd_file}" | sed -e s/-crd.yaml/s.yaml/g) - wget https://raw.githubusercontent.com/argoproj/argo-cd/refs/tags/${ARGOCD_VERSION}/manifests/crds/${argocd_crd_file} -O bundle/manifests/${output_file} + wget -q "https://raw.githubusercontent.com/argoproj/argo-cd/refs/tags/${ARGOCD_VERSION}/manifests/crds/${argocd_crd_file}" -O bundle/manifests/${output_file} done } check_for_local_changes() { - local_modified_files=$(git status --porcelain | grep "bundle/manifests/argoproj.io_app" | cat) - if [[ ! -z "${local_modified_files}" ]]; then + local_modified_files=$(git status --porcelain) + if [[ ! -z "${local_modified_files}" && "${local_modified_files}}" =~ "bundle/manifests/argoproj.io_app" ]]; then echo "[WARN] There are unexpected local changes to the argo-cd CRD manifests." echo "${local_modified_files}" echo "Please update the CRDs from the argo-cd repository, ensure that there are no diffs and re-submit" exit 1 else echo "No local changes to argo-cd CRD manifests" + return fi } +LINT="false" +if [[ $# > 0 ]]; then + if [[ $1 == "lint" ]];then + LINT="true" + else + echo "Invalid option $1" + exit 0 + fi +fi + check_for_sem_ver download_manifests -check_for_local_changes +if [[ "${LINT}" == "true" ]]; then + check_for_local_changes +fi