Skip to content

Commit

Permalink
Ensure ConditionCheck container names are DNS-safe.
Browse files Browse the repository at this point in the history
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: #3393
  • Loading branch information
mattmoor authored and tekton-robot committed Oct 15, 2020
1 parent 2436f0d commit d876923
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/reconciler/pipelinerun/resources/conditionresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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{
Expand Down
12 changes: 12 additions & 0 deletions pkg/reconciler/pipelinerun/resources/conditionresolution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d876923

Please sign in to comment.