Skip to content

Commit e62f1a3

Browse files
committed
Use kmeta.ChildName to create DNS-safe names.
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 an upstream helper we created to solve ~exactly this problem. You get DNS-safe short names based on an input name and a suffix, which are deterministic, and are friendly for suitably short inputs. Fixes: #3393
1 parent 2436f0d commit e62f1a3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pkg/reconciler/pipelinerun/resources/conditionresolution.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/tektoncd/pipeline/pkg/apis/resource"
2727
resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
2828
corev1 "k8s.io/api/core/v1"
29+
"knative.dev/pkg/kmeta"
2930
)
3031

3132
const (
@@ -96,7 +97,7 @@ func (state TaskConditionCheckState) IsSuccess() bool {
9697
// ConditionToTaskSpec creates a TaskSpec from a given Condition
9798
func (rcc *ResolvedConditionCheck) ConditionToTaskSpec() (*v1beta1.TaskSpec, error) {
9899
if rcc.Condition.Spec.Check.Name == "" {
99-
rcc.Condition.Spec.Check.Name = unnamedCheckNamePrefix + rcc.Condition.Name
100+
rcc.Condition.Spec.Check.Name = kmeta.ChildName(unnamedCheckNamePrefix, rcc.Condition.Name)
100101
}
101102

102103
t := &v1beta1.TaskSpec{

pkg/reconciler/pipelinerun/resources/conditionresolution_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ func TestResolvedConditionCheck_ConditionToTaskSpec(t *testing.T) {
215215
Image: "ubuntu",
216216
}}},
217217
},
218+
}, {
219+
name: "default-container-name",
220+
cond: tbv1alpha1.Condition("very-very-very-very-very-very-very-very-very-very-very-long-name", tbv1alpha1.ConditionSpec(
221+
tbv1alpha1.ConditionSpecCheck("", "ubuntu"),
222+
)),
223+
want: v1beta1.TaskSpec{
224+
Steps: []v1beta1.Step{{Container: corev1.Container{
225+
// from: kmeta.ChildName("condition-check-", "very-very-very-very-very-very-very-very-very-very-very-long-name"),
226+
Name: "condition-check-1305b14e3f3bb99ff83cbb3a68020520very-very-very",
227+
Image: "ubuntu",
228+
}}},
229+
},
218230
}, {
219231
name: "with-input-params",
220232
cond: tbv1alpha1.Condition("bar", tbv1alpha1.ConditionSpec(

0 commit comments

Comments
 (0)