Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Apr 4, 2024
1 parent e290443 commit d237150
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 6 deletions.
3 changes: 2 additions & 1 deletion checks/kubernetes_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

const (
// maximum number of static & non static resources a canary can have
maxResourcesAllowed = 10
defaultMaxResourcesAllowed = 10

// resourceWaitTimeout is the default timeout to wait for all resources
// to be ready. Timeout on the spec will take precedence over this.
Expand Down Expand Up @@ -89,6 +89,7 @@ func (c *KubernetesResourceChecker) Check(ctx *context.Context, check v1.Kuberne
}

totalResources := len(check.StaticResources) + len(check.Resources)
maxResourcesAllowed := ctx.Properties().Int("checks.kubernetesResource.maxResources", defaultMaxResourcesAllowed)
if totalResources > maxResourcesAllowed {
return results.Failf("too many resources (%d). only %d allowed", totalResources, maxResourcesAllowed)
}
Expand Down
1 change: 1 addition & 0 deletions checks/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (c *NamespaceChecker) getConditionTimes(ns *v1.Namespace, pod *v1.Pod) (tim
func (c *NamespaceChecker) Check(ctx *context.Context, extConfig external.Check) pkg.Results {
check := extConfig.(canaryv1.NamespaceCheck)
result := pkg.Success(check, ctx.Canary)
result.AppendMsgf("namespace check is deprecated. Please use the kubernetes resource check")
var results pkg.Results
results = append(results, result)
if !c.lock.TryAcquire(1) {
Expand Down
1 change: 1 addition & 0 deletions checks/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (c *PodChecker) Check(ctx *context.Context, extConfig external.Check) pkg.R
}

result := pkg.Success(podCheck, ctx.Canary)
result.AppendMsgf("pod check is deprecated. Please use the kubernetes resource check")
var results pkg.Results
results = append(results, result)
startTimer := NewTimer()
Expand Down
70 changes: 70 additions & 0 deletions fixtures/k8s/kubernetes_resource_ingress_pass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: ingress-test
namespace: default
labels:
"Expected-Fail": "false"
spec:
schedule: "@every 5m"
kubernetesResource:
- name: ingress-accessibility-check
namespace: default
description: "deploy httpbin & check that it's accessible via ingress"
waitForReady: true
timeout: 10m
staticResources:
- apiVersion: v1
kind: Namespace
metadata:
name: development
- apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: httpbin
namespace: development
spec:
rules:
- host: "httpbin.127.0.0.1.nip.io"
http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: httpbin
port:
number: 80
resources:
- apiVersion: v1
kind: Pod
metadata:
name: httpbin
namespace: development
labels:
app: httpbin
spec:
containers:
- name: httpbin
image: "kennethreitz/httpbin:latest"
ports:
- containerPort: 80
- apiVersion: v1
kind: Service
metadata:
name: httpbin
namespace: development
spec:
selector:
app: httpbin
ports:
- port: 80
targetPort: 80
checks:
- http:
- name: Call httpbin via ingress
url: "http://ingress-nginx.ingress-nginx.svc"
headers:
- name: Host
value: "{{(index ((index .staticResources 0).Object.spec.rules) 0).host}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: ingress-test
name: ingress-test-2
namespace: default
labels:
"Expected-Fail": "false"
"Expected-Fail": "true"
spec:
schedule: "@every 5m"
kubernetesResource:
- name: ingress-accessibility-check
- name: ingress-accessibility-check-2
namespace: default
description: "deploy httpbin & check that it's accessible via ingress"
waitForReady: true
Expand All @@ -21,6 +21,7 @@ spec:
name: httpbin
namespace: default
spec:
ingressClassName: traefik # non-existing ingress class
rules:
- host: "httpbin.127.0.0.1.nip.io"
http:
Expand Down
5 changes: 3 additions & 2 deletions fixtures/k8s/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ resources:
- pod_fail.yaml
- pod_pass.yaml
- kubernetes_bundle.yaml
- kubernetes_resource_ingress.yaml
- kubernetes_resource_service.yaml
- kubernetes_resource_ingress_pass.yaml
- kubernetes_resource_ingress_fail.yaml
- kubernetes_resource_service_pass.yaml
9 changes: 9 additions & 0 deletions pkg/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,15 @@ func (result CheckResult) String() string {
return fmt.Sprintf("%s duration=%d %s %s", console.Redf("FAIL"), result.Duration, result.Message, result.Error)
}

func (result *CheckResult) AppendMsgf(msg string, args ...any) {
if result.Message == "" {
result.Message = fmt.Sprintf(msg, args...)
return
}

result.Message += "\n" + fmt.Sprintf(msg, args...)
}

type GenericCheck struct {
v1.Description `yaml:",inline" json:",inline"`
Type string
Expand Down

0 comments on commit d237150

Please sign in to comment.