Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧪 adds manifest tests #761

Merged
merged 9 commits into from
Jun 27, 2024

Conversation

bpsoos
Copy link
Contributor

@bpsoos bpsoos commented Jun 27, 2024

resolves #752

This PR adds a make target test-manifests that runs a kubeconform based test to validate the kubernetes/kustomize manifests against their schemas.

Signed-off-by: bpsoos <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.16%. Comparing base (c9ed948) to head (66c6367).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #761   +/-   ##
=======================================
  Coverage   56.16%   56.16%           
=======================================
  Files          31       31           
  Lines        3105     3105           
=======================================
  Hits         1744     1744           
  Misses       1222     1222           
  Partials      139      139           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chengfang
Copy link
Collaborator

How about running the script directly in github actions workflow, without building or running images? For local run, we can require users to install kubeconform before running.

Can you also share some negative test results?

@bpsoos
Copy link
Contributor Author

bpsoos commented Jun 27, 2024

@chengfang Negative test results:

docker run --rm \
		-v `pwd`/manifests:/home/manifests \
		-v `pwd`/scripts:/home/scripts \
		manifest-tester-argocd-image-updater \
		scripts/test_manifests.sh
/home/manifests/base/config/argocd-image-updater-cm.yaml - ConfigMap argocd-image-updater-config is valid
/home/manifests/base/config/argocd-image-updater-ssh-config.yaml - ConfigMap argocd-image-updater-ssh-config is valid
/home/manifests/base/config/argocd-image-updater-secret.yaml - Secret argocd-image-updater-secret is valid
/home/manifests/base/deployment/kustomization.yaml - Kustomization  is valid
/home/manifests/base/kustomization.yaml - Kustomization  is valid
/home/manifests/base/config/kustomization.yaml - Kustomization  is valid
/home/manifests/base/deployment/argocd-image-updater-deployment.yaml - Deployment argocd-image-updater is invalid: problem validating schema. Check JSON formatting: jsonschema: '/spec' does not validate with https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master-standalone/deployment-apps-v1.json#/properties/spec/required: missing properties: 'selector'
/home/manifests/base/rbac/kustomization.yaml - Kustomization  is valid
/home/manifests/base/rbac/argocd-image-updater-rolebinding.yaml - RoleBinding argocd-image-updater is valid
/home/manifests/base/rbac/argocd-image-updater-role.yaml - Role argocd-image-updater is valid
/home/manifests/install.yaml - RoleBinding argocd-image-updater is valid
/home/manifests/install.yaml - ConfigMap argocd-image-updater-config is valid
/home/manifests/install.yaml - ConfigMap argocd-image-updater-ssh-config is valid
/home/manifests/install.yaml - Secret argocd-image-updater-secret is valid
/home/manifests/install.yaml - failed validation: error unmarshalling resource: error converting YAML to JSON: yaml: line 158: mapping values are not allowed in this context
/home/manifests/install.yaml - Role argocd-image-updater is valid
/home/manifests/base/rbac/argocd-image-updater-sa.yaml - ServiceAccount argocd-image-updater is valid
/home/manifests/install.yaml - ServiceAccount argocd-image-updater is valid
make: *** [test-manifests] Error 1

Modifications made to make the test fail:

diff --git a/manifests/base/deployment/argocd-image-updater-deployment.yaml b/manifests/base/deployment/argocd-image-updater-deployment.yaml
index 5a38be1..7a11376 100644
--- a/manifests/base/deployment/argocd-image-updater-deployment.yaml
+++ b/manifests/base/deployment/argocd-image-updater-deployment.yaml
@@ -7,7 +7,7 @@ metadata:
     app.kubernetes.io/component: controller
   name: argocd-image-updater
 spec:
-  selector:
+  selectorr:
    matchLabels:
     app.kubernetes.io/name: argocd-image-updater
   strategy:
diff --git a/manifests/install.yaml b/manifests/install.yaml
index 39282cb..000e255 100644
--- a/manifests/install.yaml
+++ b/manifests/install.yaml
@@ -238,7 +238,7 @@ spec:
         name: ssh-known-hosts
       - configMap:
           name: argocd-image-updater-ssh-config
-          optional: true
+            optional: true
         name: ssh-config
       - name: ssh-signing-key
         secret:

@bpsoos
Copy link
Contributor Author

bpsoos commented Jun 27, 2024

@chengfang

How about running the script directly in github actions workflow, without building or running images? For local run, we can require users to install kubeconform before running.

Okay, I can make these modifications

chengfang
chengfang previously approved these changes Jun 27, 2024
@chengfang chengfang dismissed their stale review June 27, 2024 17:33

there are CI failures.

@bpsoos
Copy link
Contributor Author

bpsoos commented Jun 27, 2024

@chengfang what do you think about this version?

also, in CI this what it looks like now if a manifest is incorrect: https://github.com/argoproj-labs/argocd-image-updater/actions/runs/9701702056/job/26775909356

Copy link
Collaborator

@chengfang chengfang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chengfang chengfang merged commit 89f3bd1 into argoproj-labs:master Jun 27, 2024
10 checks passed
@chengfang
Copy link
Collaborator

@bpsoos thanks!

sribiere-jellysmack pushed a commit to sribiere-jellysmack/argocd-image-updater that referenced this pull request Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tests to validate manifests against schemas
3 participants