Skip to content

Commit

Permalink
feat: add display for kubernetes resource check
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Aug 29, 2024
1 parent 7788711 commit 7ce839a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/v1/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,16 @@ type KubernetesResourceCheck struct {
WaitFor KubernetesResourceCheckWaitFor `json:"waitFor,omitempty"`
}

func (c KubernetesResourceCheck) GetDisplayTemplate() Template {
if !c.Templatable.Display.IsEmpty() {
return c.Templatable.Display
}

return Template{
Expression: "display.keys().map(k, k + ': ' + display[k]).join('\n')",
}
}

func (c KubernetesResourceCheck) TotalResources() int {
return len(c.Resources) + len(c.StaticResources)
}
Expand Down
1 change: 1 addition & 0 deletions canary-checker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
# check.disabled.tcp=false

# topology.runNow=true
log.level.db=warn
8 changes: 8 additions & 0 deletions checks/kubernetes_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func (c *KubernetesResourceChecker) Check(ctx context.Context, check v1.Kubernet
}

ctx.Logger.V(4).Infof("found %d checks to run", len(check.Checks))

displayPerCheck := map[string]string{}
for _, c := range check.Checks {
virtualCanary := v1.Canary{
ObjectMeta: ctx.Canary.ObjectMeta,
Expand Down Expand Up @@ -167,13 +169,19 @@ func (c *KubernetesResourceChecker) Check(ctx context.Context, check v1.Kubernet
}
}

for _, r := range res {
displayPerCheck[r.Check.GetName()] = r.Message
}
return nil
})
if retryErr != nil {
return results.Failf(retryErr.Error())
}
}

result.AddData(map[string]any{
"display": displayPerCheck,
})
return results
}

Expand Down
3 changes: 3 additions & 0 deletions fixtures/k8s/kubernetes_resource_pod_exit_code_pass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ spec:
- name: "pod exit code"
description: "Create pod & check its exit code"
namespace: default
display:
expr: |
"Result of check 'exit-code-check': " + display["exit-code-check"]
resources:
- apiVersion: v1
kind: Pod
Expand Down

0 comments on commit 7ce839a

Please sign in to comment.