From 69d0364a1a085191b69907f9da07782b94acdb8c Mon Sep 17 00:00:00 2001 From: Rafael Felix Correa Date: Wed, 21 Aug 2024 12:09:36 +0200 Subject: [PATCH] CRIB-317 - Use the kyverno's label instead of kube-janitor's annotation for clean up --- k8s/TUTORIAL.md | 2 +- k8s/environment/environment.go | 5 +++-- k8s/pkg/alias/alias.go | 2 +- k8s/pkg/common.go | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/k8s/TUTORIAL.md b/k8s/TUTORIAL.md index d31335af8..db85091a2 100644 --- a/k8s/TUTORIAL.md +++ b/k8s/TUTORIAL.md @@ -450,7 +450,7 @@ const ( ```golang // Config is an environment common configuration, labels, annotations, connection types, readiness check, etc. type Config struct { - // TTL is time to live for the environment, used with kube-janitor + // TTL is time to live for the environment, used with kyverno TTL time.Duration // NamespacePrefix is a static namespace prefix NamespacePrefix string diff --git a/k8s/environment/environment.go b/k8s/environment/environment.go index 5fee8b687..6505e8f52 100644 --- a/k8s/environment/environment.go +++ b/k8s/environment/environment.go @@ -70,7 +70,7 @@ type ConnectedChart interface { // Config is an environment common configuration, labels, annotations, connection types, readiness check, etc. type Config struct { - // TTL is time to live for the environment, used with kube-janitor + // TTL is time to live for the environment, used with kyverno TTL time.Duration // NamespacePrefix is a static namespace prefix NamespacePrefix string @@ -272,11 +272,12 @@ func (m *Environment) initApp() error { } } + m.Cfg.Labels = append(m.Cfg.Labels, fmt.Sprintf("%s=%s", pkg.TTLLabelKey, *a.ShortDur(m.Cfg.TTL))) nsLabels, err := a.ConvertLabels(m.Cfg.Labels) if err != nil { return err } - defaultNamespaceAnnotations[pkg.TTLLabelKey] = a.ShortDur(m.Cfg.TTL) + m.root = cdk8s.NewChart(m.App, ptr.Ptr(fmt.Sprintf("root-chart-%s", m.Cfg.Namespace)), &cdk8s.ChartProps{ Labels: nsLabels, Namespace: ptr.Ptr(m.Cfg.Namespace), diff --git a/k8s/pkg/alias/alias.go b/k8s/pkg/alias/alias.go index 5808fbc45..bc262a4dc 100644 --- a/k8s/pkg/alias/alias.go +++ b/k8s/pkg/alias/alias.go @@ -9,7 +9,7 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/utils/ptr" ) -// ShortDur is a helper method for kube-janitor duration format +// ShortDur is a helper method for kyverno duration format func ShortDur(d time.Duration) *string { s := d.String() if strings.HasSuffix(s, "m0s") { diff --git a/k8s/pkg/common.go b/k8s/pkg/common.go index 8b394ee56..d3619856d 100644 --- a/k8s/pkg/common.go +++ b/k8s/pkg/common.go @@ -4,7 +4,7 @@ import "github.com/smartcontractkit/chainlink-testing-framework/utils/ptr" // Common labels for k8s envs const ( - TTLLabelKey = "janitor/ttl" + TTLLabelKey = "cleanup.kyverno.io/ttl" NamespaceLabelKey = "namespace" )