From 85e7f5b4b8934638259edcece25fbe85ae71305e Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Thu, 15 Oct 2020 08:23:45 -0700 Subject: [PATCH] Ensure ConditionCheck container names are DNS-safe. My recent change uncovered a latent bug where especially long test names result in especially long container names, which fails certain validations. Unfortunately it slipped in because the test was expected to fail. This leverages the names.SimpleNameGenerator.RestrictLength helper to solve this problem. Fixes: https://github.com/tektoncd/pipeline/issues/3393 --- .../pipelinerun/resources/conditionresolution.go | 3 ++- .../resources/conditionresolution_test.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/reconciler/pipelinerun/resources/conditionresolution.go b/pkg/reconciler/pipelinerun/resources/conditionresolution.go index 973988b1d07..c63de3c861d 100644 --- a/pkg/reconciler/pipelinerun/resources/conditionresolution.go +++ b/pkg/reconciler/pipelinerun/resources/conditionresolution.go @@ -25,6 +25,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/apis/resource" resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" + "github.com/tektoncd/pipeline/pkg/names" corev1 "k8s.io/api/core/v1" ) @@ -96,7 +97,7 @@ func (state TaskConditionCheckState) IsSuccess() bool { // ConditionToTaskSpec creates a TaskSpec from a given Condition func (rcc *ResolvedConditionCheck) ConditionToTaskSpec() (*v1beta1.TaskSpec, error) { if rcc.Condition.Spec.Check.Name == "" { - rcc.Condition.Spec.Check.Name = unnamedCheckNamePrefix + rcc.Condition.Name + rcc.Condition.Spec.Check.Name = names.SimpleNameGenerator.RestrictLength(unnamedCheckNamePrefix + rcc.Condition.Name) } t := &v1beta1.TaskSpec{ diff --git a/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go b/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go index 422d31626ee..c92d3182300 100644 --- a/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go @@ -215,6 +215,18 @@ func TestResolvedConditionCheck_ConditionToTaskSpec(t *testing.T) { Image: "ubuntu", }}}, }, + }, { + name: "default-container-name", + cond: tbv1alpha1.Condition("very-very-very-very-very-very-very-very-very-very-very-long-name", tbv1alpha1.ConditionSpec( + tbv1alpha1.ConditionSpecCheck("", "ubuntu"), + )), + want: v1beta1.TaskSpec{ + Steps: []v1beta1.Step{{Container: corev1.Container{ + // Shortened via: names.SimpleNameGenerator.RestrictLength + Name: "condition-check-very-very-very-very-very-very-very-very-very-ve", + Image: "ubuntu", + }}}, + }, }, { name: "with-input-params", cond: tbv1alpha1.Condition("bar", tbv1alpha1.ConditionSpec(