Skip to content

Commit

Permalink
wip: checks on kubernetes resource
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
adityathebe committed Apr 1, 2024
1 parent 84f0e09 commit 1fafac7
Show file tree
Hide file tree
Showing 8 changed files with 908 additions and 5 deletions.
8 changes: 6 additions & 2 deletions api/v1/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,10 @@ type KubernetesGenericCheckTestResultSelector struct {
PodSelector string `json:"podSelector,omitempty"`
}

type KubernetesResourceChecks struct {
CanarySpec `yaml:",inline" json:",inline"`
}

type KubernetesResourceCheck struct {
Description `yaml:",inline" json:",inline"`
Templatable `yaml:",inline" json:",inline"`
Expand All @@ -799,8 +803,8 @@ type KubernetesResourceCheck struct {
// +kubebuilder:pruning:PreserveUnknownFields
Resources []unstructured.Unstructured `json:"resources"`

// Checks to run agains the kubernetes resources
// Checks []CanarySpec `json:"checks,omitempty"`
// Checks to run against the kubernetes resources
Checks []KubernetesResourceChecks `json:"what,omitempty"`

// Kubeconfig is the kubeconfig or the path to the kubeconfig file.
Kubeconfig *types.EnvVar `yaml:"kubeconfig,omitempty" json:"kubeconfig,omitempty"`
Expand Down
23 changes: 23 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions checks/kubernetes_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
// maximum number of static & non static resources a canary can have
maxResourcesAllowed = 10

// resourceWaitTimeout is the default timeout to wait for alll resources
// resourceWaitTimeout is the default timeout to wait for all resources
// to be ready. Timeout on the spec will take precedence over this.
resourceWaitTimeout = time.Minute * 10

Expand Down Expand Up @@ -146,7 +146,21 @@ func (c *KubernetesResourceChecker) Check(ctx *context.Context, check v1.Kuberne
}
}

// run the actual check now
// run the actual check now. We need to run this in a canary-checker pod as well
for _, c := range check.Checks {
virtualCanary := v1.Canary{
ObjectMeta: ctx.Canary.ObjectMeta,
Spec: c.CanarySpec,
}

return nil
checkCtx := context.New(ctx.Context, virtualCanary)
res, err := Exec(checkCtx)
if err != nil {
return results.Failf("%v", err)
}

results = append(results, res...)
}

return results
}
5 changes: 5 additions & 0 deletions config/deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5128,6 +5128,11 @@ spec:
type: string
waitForReady:
type: boolean
what:
description: Checks to run against the kubernetes resources
items:
type: object
type: array
required:
- name
- resources
Expand Down
5 changes: 5 additions & 0 deletions config/deploy/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5127,6 +5127,11 @@ spec:
type: string
waitForReady:
type: boolean
what:
description: Checks to run against the kubernetes resources
items:
type: object
type: array
required:
- name
- resources
Expand Down
Loading

0 comments on commit 1fafac7

Please sign in to comment.