From 1307f0da84419d00409e3ee1794fd5bb5c14533f Mon Sep 17 00:00:00 2001 From: Shivam Mukhade Date: Mon, 6 Sep 2021 12:50:42 +0530 Subject: [PATCH] Handle upgrade from older version which has pruner defaults Before webhook we had default value for pruner's keep as 1 but we expect user to define all values now so if a user has installed prev version and has not enabled pruner then `keep` will have a value 1 and after upgrading to newer version, webhook will fail if keep has a value and other fields are not defined this handles that case by removing the default for keep if other pruner fields are not defined Signed-off-by: Shivam Mukhade --- .../operator/v1alpha1/tektonconfig_defaults.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/apis/operator/v1alpha1/tektonconfig_defaults.go b/pkg/apis/operator/v1alpha1/tektonconfig_defaults.go index bab02b76e2..8048aa2e4c 100644 --- a/pkg/apis/operator/v1alpha1/tektonconfig_defaults.go +++ b/pkg/apis/operator/v1alpha1/tektonconfig_defaults.go @@ -26,4 +26,20 @@ func (tc *TektonConfig) SetDefaults(ctx context.Context) { } tc.Spec.Pipeline.PipelineProperties.setDefaults() + + // before webhook we had default value for pruner's keep as 1 + // but we expect user to define all values now + // so if a user has installed prev version and has not enabled + // pruner then `keep` will have a value 1 and after upgrading + // to newer version webhook will fail if keep has a value and + // other fields are not defined + // this handles that case by removing the default for keep if + // other pruner fields are not defined + if len(tc.Spec.Pruner.Resources) == 0 { + tc.Spec.Pruner.Keep = nil + tc.Spec.Pruner.Schedule = "" + } else if tc.Spec.Pruner.Schedule == "" { + tc.Spec.Pruner.Keep = nil + tc.Spec.Pruner.Resources = []string{} + } }