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

Kubernetes Resource - Display Messages Not Working #2086

Closed
dmorrowjc opened this issue Aug 23, 2024 · 1 comment · Fixed by #2093
Closed

Kubernetes Resource - Display Messages Not Working #2086

dmorrowjc opened this issue Aug 23, 2024 · 1 comment · Fixed by #2093
Assignees
Labels
bug Something isn't working

Comments

@dmorrowjc
Copy link

The display formatting for Kubernetes Resource checks does not appear to be working.

If I setup a basic Kubernetes check and format the display, it seems to work fine:

apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
  name: kube-system-checks
spec:
  interval: 30
  kubernetes:
    - namespace: kube-system
      name: kube-system
      kind: Pod
      resource:
        labelSelector: k8s-app=kube-dns
      namespaceSelector:
        name: kube-system
      display:
        expr: |
          dyn(results).all(x, k8s.isHealthy(x))

However, if I use a check like this within the Kubernetes Resource check, nothing is displayed:

apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
  name: daemonset-checks
  namespace: canary-checker
spec:
  schedule: "@every 1m"
  kubernetesResource:
    - name: daemonset
      namespace: canary-checker
      description: "Create a daemonset and check that it's healthy"
      waitFor:
        expr: 'dyn(resources).all(r, k8s.isHealthy(r))'
        interval: 60s
        timeout: 5m

      resources:
        - apiVersion: apps/v1
          kind: DaemonSet
          metadata:
            name: canary-daemonset
            namespace: canary-checker
            labels:
              app: canary-daemonset
          spec:
            selector:
              matchLabels:
                app: canary-daemonset
            template:
              metadata:
                labels:
                  app: canary-daemonset
              spec:
                containers:
                - name: pause
                  image: "gcr.io/google-containers/pause:3.2" 

      checks:
        - kubernetes:
            - name: canary-daemonset
              namespace: canary-checker

              kind: DaemonSet
              healthy: true
              namespaceSelector:
                name: canary-checker
              display:
                expr: |
                  dyn(results).all(x, k8s.isHealthy(x))
              test:
                expr: dyn(results).all(x, k8s.isHealthy(x))

image

If I instead try to configure the display message for the Kubernetes Resource check at the scope of the Canary, I am able to do so...

apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
  name: daemonset-checks
  namespace: canary-checker
spec:
  schedule: "@every 1m"
  kubernetesResource:
    - name: daemonset
      namespace: canary-checker
      description: "Create a daemonset and check that it's healthy"
      waitFor:
        expr: 'dyn(resources).all(r, k8s.isHealthy(r))'
        interval: 60s
        timeout: 5m

      resources:
        - apiVersion: apps/v1
          kind: DaemonSet
          metadata:
            name: canary-daemonset
            namespace: canary-checker
            labels:
              app: canary-daemonset
          spec:
            selector:
              matchLabels:
                app: canary-daemonset
            template:
              metadata:
                labels:
                  app: canary-daemonset
              spec:
                containers:
                - name: pause
                  image: "gcr.io/google-containers/pause:3.2" 

      display:
        expr: string("a test display")                  

      checks:
        - kubernetes:
            - name: canary-daemonset
              namespace: canary-checker

              kind: DaemonSet
              healthy: true
              namespaceSelector:
                name: canary-checker
              test:
                expr: dyn(results).all(x, k8s.isHealthy(x))

image

...however, I am not able to access any meaningful information about my resources:

apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
  name: daemonset-checks
  namespace: canary-checker
spec:
  schedule: "@every 1m"
  kubernetesResource:
    - name: daemonset
      namespace: canary-checker
      description: "Create a daemonset and check that it's healthy"
      waitFor:
        expr: 'dyn(resources).all(r, k8s.isHealthy(r))'
        interval: 60s
        timeout: 5m

      resources:
        - apiVersion: apps/v1
          kind: DaemonSet
          metadata:
            name: canary-daemonset
            namespace: canary-checker
            labels:
              app: canary-daemonset
          spec:
            selector:
              matchLabels:
                app: canary-daemonset
            template:
              metadata:
                labels:
                  app: canary-daemonset
              spec:
                containers:
                - name: pause
                  image: "gcr.io/google-containers/pause:3.2" 

      display:
        expr: dyn(results).map(x, k8s.getHealth(x).message)

      checks:
        - kubernetes:
            - name: canary-daemonset
              namespace: canary-checker

              kind: DaemonSet
              healthy: true
              namespaceSelector:
                name: canary-checker
              test:
                expr: dyn(results).all(x, k8s.isHealthy(x))

image

I'm also generally struggling to figure out which variables are available to me when using CEL expressions. From examples in the docs I can infer that resources is available in the waitFor expression and results should be available in the display expression, but it's unclear if those are all the variables that I can reference. In my example with a DaemonSet above I can't tell if I'm using the wrong variable or if the display itself is buggy because all I can see is an empty map getting returned.

@adityathebe
Copy link
Member

@dmorrowjc Thanks for reporting. A fix for this has been released in v1.0.260-beta.179

See the comments on the PR for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants