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

[Feature] For loop in a test #1143

Open
1 task done
sandert-k8s opened this issue Apr 3, 2024 · 1 comment
Open
1 task done

[Feature] For loop in a test #1143

sandert-k8s opened this issue Apr 3, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@sandert-k8s
Copy link
Contributor

sandert-k8s commented Apr 3, 2024

Problem Statement

When checking the status of a lot of components, where only the name differs, it can be useful to be able to create a for loop. So you only have to declare once the assertion you want to check, and a list with names. For example in this simple check:

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: running-deployments
spec:
  template: true
  timeouts:
    assert: 120s
  steps:
    - try:
        - assert:
            resource:
              apiVersion: apps/v1
              kind: Deployment
              metadata:
                name: app1
              status:
                (readyReplicas == replicas): true
                (conditions[?type == 'Available']):
                  - status: 'True'
    - try:
        - assert:
            resource:
              apiVersion: apps/v1
              kind: Deployment
              metadata:
                  name: app2
              status:
                (readyReplicas == replicas): true
                (conditions[?type == 'Available']):
                  - status: 'True'

Solution Description

There are many ways this could be implemented. This is just a idea

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: running-deployments
spec:
  bindings:  <-- Because bindings is already a option in Chainsaw, maybe its good to use it also for lists
  - name: deployments
    values: app1, app2
  template: true
  timeouts:
    assert: 120s
  steps:
    for deploy in ($deployments) <-- Start for loop
    - try:
        - assert:
            resource:
              apiVersion: apps/v1
              kind: Deployment
              metadata:
                name: ($deploy) <-- The selected deployment
              status:
                (readyReplicas == replicas): true
                (conditions[?type == 'Available']):
                  - status: 'True'

Alternatives

No response

Additional Context

No response

Slack discussion

No response

Research

  • I have searched other issues in this repository and mine is not recorded.
@sandert-k8s sandert-k8s added the enhancement New feature or request label Apr 3, 2024
@nkuacac
Copy link

nkuacac commented Aug 6, 2024

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: app.tolerations
spec:
  template: true
  description: checking tolerations
  namespace: default
  steps:
    - description: "step-1"
      try:
        - description: "toleration"
          script:
            content: kubectl get pods  -ojson
            outputs:
              - name: podList
                value: (json_parse($stdout))
        - assert:
            resource:
              ($podList):
                ~.(items):
                  spec:
                    tolerations:
                      - effect: NoExecute
                        key: node.kubernetes.io/unreachable
                        operator: Exists
                        tolerationSeconds: 30
                      - effect: NoExecute
                        key: node.kubernetes.io/not-ready
                        operator: Exists
                        tolerationSeconds: 30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants