From 57738a43653ded5b1489f7c4162621adea61fe3b Mon Sep 17 00:00:00 2001 From: Adam Kaplan Date: Wed, 11 Dec 2024 15:05:43 -0500 Subject: [PATCH] fix: Set TektonConfig Pruner Starting in Tekton Operator v0.58.0, TektonConfig objects must set a value for `keep` or `keepSince` if the pruner is enabled [1]. If Shipwright bootstraps the TektonConfig object and does not set a value for `.spec.pruner.keep` (or `.keepSince`), it risks failing to reconcile the TektonConfig instance or worse [2]. Fixing by setting the `keep` value to match the Tekton operator default. Fixes #231 [1] https://github.com/tektoncd/operator/pull/410 [2] https://github.com/tektoncd/operator/issues/2450 Signed-off-by: Adam Kaplan --- pkg/tekton/tekton.go | 7 +++++++ pkg/tekton/tekton_test.go | 2 ++ 2 files changed, 9 insertions(+) diff --git a/pkg/tekton/tekton.go b/pkg/tekton/tekton.go index 51491ee46..b3ede3698 100644 --- a/pkg/tekton/tekton.go +++ b/pkg/tekton/tekton.go @@ -102,6 +102,9 @@ func IsTektonConfigPresent(ctx context.Context, client tektonoperatorclientv1alp // CreateTektonConfigWithProfileAndTargetNamespace creates a TektonConfig object with the given // profile and target namespace for Tekton components. func CreateTektonConfigWithProfileAndTargetNamespace(ctx context.Context, client tektonoperatorclientv1alpha1.OperatorV1alpha1Interface, profile string, targetNamepsace string) (*tektonoperatorv1alpha1.TektonConfig, error) { + // If creating a TektonConfig, enable the pruner with default keep of 100 + // This matches the Tekton operator default + keep := uint(100) tektonConfig := &tektonoperatorv1alpha1.TektonConfig{ ObjectMeta: metav1.ObjectMeta{ Name: "config", @@ -111,6 +114,10 @@ func CreateTektonConfigWithProfileAndTargetNamespace(ctx context.Context, client CommonSpec: tektonoperatorv1alpha1.CommonSpec{ TargetNamespace: targetNamepsace, }, + Pruner: tektonoperatorv1alpha1.Prune{ + Disabled: false, + Keep: &keep, + }, }, } return client.TektonConfigs().Create(ctx, tektonConfig, metav1.CreateOptions{}) diff --git a/pkg/tekton/tekton_test.go b/pkg/tekton/tekton_test.go index 2b3a91f51..ae1abe3e7 100644 --- a/pkg/tekton/tekton_test.go +++ b/pkg/tekton/tekton_test.go @@ -153,6 +153,8 @@ func TestReconcileTekton(t *testing.T) { g.Expect(tektonConfig.Name).To(o.Equal("config")) g.Expect(tektonConfig.Spec.Profile).To(o.Equal("lite")) g.Expect(tektonConfig.Spec.TargetNamespace).To(o.Equal("tekton-pipelines")) + g.Expect(tektonConfig.Spec.Pruner.Disabled).To(o.Equal(false)) + g.Expect(tektonConfig.Spec.Pruner.Keep).NotTo(o.BeNil()) } }) }