From 9d6144d07f1bade65c2b96f5cdaa33b75002da11 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Wed, 3 Apr 2024 17:10:08 +0545 Subject: [PATCH] fix: kubernetes resource fixture to test ingress --- checks/kubernetes_resource.go | 4 +-- fixtures/k8s/kubernetes_resource.yaml | 48 ++++++++++++++++++++++++--- fixtures/k8s/kustomization.yaml | 1 + pkg/db/canary.go | 2 ++ 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/checks/kubernetes_resource.go b/checks/kubernetes_resource.go index 056d93268..a3d0e34f0 100644 --- a/checks/kubernetes_resource.go +++ b/checks/kubernetes_resource.go @@ -162,8 +162,8 @@ func (c *KubernetesResourceChecker) Check(ctx *context.Context, check v1.Kuberne templater := gomplate.StructTemplater{ Values: map[string]any{ - "staticResource": check.StaticResources, - "resources": check.Resources, + "staticResources": check.StaticResources, + "resources": check.Resources, }, ValueFunctions: true, DelimSets: []gomplate.Delims{ diff --git a/fixtures/k8s/kubernetes_resource.yaml b/fixtures/k8s/kubernetes_resource.yaml index 83986ab4a..1d6236c35 100644 --- a/fixtures/k8s/kubernetes_resource.yaml +++ b/fixtures/k8s/kubernetes_resource.yaml @@ -7,13 +7,31 @@ metadata: labels: "Expected-Fail": "false" spec: - schedule: '@every 5m' + schedule: "@every 5m" kubernetesResource: - - name: ingress-accessibility-check + - name: ingress-accessibility-check namespace: default - description: "deploy an nginx pod" - waitForReady: true + description: "deploy an nginx pod & check that it's accessible via ingress" + waitForReady: true timeout: 10m + staticResources: + - apiVersion: networking.k8s.io/v1 + kind: Ingress + metadata: + name: nginx-pod-ingress + namespace: default + spec: + rules: + - host: nginx.test.flanksource.com + http: + paths: + - pathType: Prefix + path: / + backend: + service: + name: nginx + port: + number: 80 resources: - apiVersion: v1 kind: Pod @@ -26,3 +44,25 @@ spec: image: nginx:1.24.0-alpine-slim ports: - containerPort: 80 + - apiVersion: v1 + kind: Service + metadata: + name: nginx + namespace: default + spec: + selector: + name: nginx-pod + ports: + - port: 80 + targetPort: 80 + checks: + - http: + - url: "http://ingress-nginx.ingress-nginx.svc" + headers: + - name: Host + value: "nginx.test.flanksource.com" + # - url: "http://localhost:1337" + # headers: + # - name: host + # value: "nginx.test.flanksource.com" + # value: "{{(index (index .staticResources 0).spec.rules 0).host}}" diff --git a/fixtures/k8s/kustomization.yaml b/fixtures/k8s/kustomization.yaml index 6669086ee..d757f301c 100644 --- a/fixtures/k8s/kustomization.yaml +++ b/fixtures/k8s/kustomization.yaml @@ -9,3 +9,4 @@ resources: - pod_fail.yaml - pod_pass.yaml - kubernetes_bundle.yaml + - kuberenetes_resource.yaml diff --git a/pkg/db/canary.go b/pkg/db/canary.go index 9cd55404b..cde1a1bb7 100644 --- a/pkg/db/canary.go +++ b/pkg/db/canary.go @@ -220,6 +220,8 @@ func DeleteCanary(ctx context.Context, id string) error { } metrics.UnregisterGauge(ctx, checkIDs) + // TODO: delete all the static resources + if err := DeleteCheckComponentRelationshipsForCanary(ctx.DB(), id); err != nil { return err }