Skip to content

Commit

Permalink
allow dot character in resource names
Browse files Browse the repository at this point in the history
  • Loading branch information
psschwei committed Apr 22, 2021
1 parent 4de53b7 commit 2ce1061
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 138 deletions.
8 changes: 4 additions & 4 deletions examples/v1beta1/pipelineruns/pipelinerun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ roleRef:
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: unit-tests
name: "unit.tests"
spec:
workspaces:
- name: source
Expand Down Expand Up @@ -222,7 +222,7 @@ spec:
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: demo-pipeline
name: "demo.pipeline"
spec:
params:
- name: image-registry
Expand All @@ -244,7 +244,7 @@ spec:
- name: skaffold-unit-tests
runAfter: [fetch-from-git]
taskRef:
name: unit-tests
name: "unit.tests"
workspaces:
- name: source
workspace: git-source
Expand Down Expand Up @@ -313,7 +313,7 @@ metadata:
name: demo-pipeline-run-1
spec:
pipelineRef:
name: demo-pipeline
name: "demo.pipeline"
serviceAccountName: 'default'
workspaces:
- name: git-source
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/condition_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func TestCondition_Invalid(t *testing.T) {
}{{
name: "invalid meta",
cond: &v1alpha1.Condition{
ObjectMeta: metav1.ObjectMeta{Name: "invalid.,name"},
ObjectMeta: metav1.ObjectMeta{Name: "invalid,name"},
},
expectedError: apis.FieldError{
Message: "Invalid resource name: special character . must not be present",
Message: `invalid resource name "invalid,name": must be a valid DNS label`,
Paths: []string{"metadata.name"},
},
}, {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func TestPipeline_Validate(t *testing.T) {
},
failureExpected: false,
}, {
name: "period in name",
name: "comma in name",
p: &v1alpha1.Pipeline{
ObjectMeta: metav1.ObjectMeta{Name: "pipe.line"},
ObjectMeta: metav1.ObjectMeta{Name: "pipe,line"},
Spec: v1alpha1.PipelineSpec{
Tasks: []v1alpha1.PipelineTask{{
Name: "foo",
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ func TestPipelineRun_Invalidate(t *testing.T) {
name: "invalid pipelinerun metadata",
pr: v1alpha1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinerun.name",
Name: "pipelinerun,name",
},
},
want: &apis.FieldError{
Message: "Invalid resource name: special character . must not be present",
Message: `invalid resource name "pipelinerun,name": must be a valid DNS label`,
Paths: []string{"metadata.name"},
},
}, {
name: "no pipeline reference",
pr: v1alpha1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinelineName",
Name: "pipelinelinename",
},
Spec: v1alpha1.PipelineRunSpec{
ServiceAccountName: "foo",
Expand All @@ -70,7 +70,7 @@ func TestPipelineRun_Invalidate(t *testing.T) {
name: "negative pipeline timeout",
pr: v1alpha1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinelineName",
Name: "pipelinelinename",
},
Spec: v1alpha1.PipelineRunSpec{
PipelineRef: &v1alpha1.PipelineRef{
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestPipelineRun_Validate(t *testing.T) {
name: "normal case",
pr: v1alpha1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinelineName",
Name: "pipelinelinename",
},
Spec: v1alpha1.PipelineRunSpec{
PipelineRef: &v1alpha1.PipelineRef{
Expand All @@ -114,7 +114,7 @@ func TestPipelineRun_Validate(t *testing.T) {
name: "no timeout",
pr: v1alpha1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinelineName",
Name: "pipelinelinename",
},
Spec: v1alpha1.PipelineRunSpec{
PipelineRef: &v1alpha1.PipelineRef{
Expand Down
43 changes: 34 additions & 9 deletions pkg/apis/pipeline/v1alpha1/run_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,18 @@ func TestRun_Invalid(t *testing.T) {
want *apis.FieldError
}{{
name: "missing spec",
run: &v1alpha1.Run{},
want: apis.ErrMissingField("spec"),
}, {
name: "invalid metadata",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{Name: "run.name"},
},
want: &apis.FieldError{
Message: "Invalid resource name: special character . must not be present",
Paths: []string{"metadata.name"},
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
},
want: apis.ErrMissingField("spec"),
}, {
name: "missing ref",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{
Ref: nil,
},
Expand All @@ -58,6 +56,9 @@ func TestRun_Invalid(t *testing.T) {
}, {
name: "missing apiVersion",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{
Ref: &v1alpha1.TaskRef{
APIVersion: "",
Expand All @@ -68,6 +69,9 @@ func TestRun_Invalid(t *testing.T) {
}, {
name: "missing kind",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{
Ref: &v1alpha1.TaskRef{
APIVersion: "blah",
Expand All @@ -79,6 +83,9 @@ func TestRun_Invalid(t *testing.T) {
}, {
name: "non-unique params",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{
Ref: &v1alpha1.TaskRef{
APIVersion: "blah",
Expand Down Expand Up @@ -111,6 +118,9 @@ func TestRun_Valid(t *testing.T) {
}{{
name: "no params",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{
Ref: &v1alpha1.TaskRef{
APIVersion: "blah",
Expand All @@ -122,6 +132,9 @@ func TestRun_Valid(t *testing.T) {
}, {
name: "unnamed",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{
Ref: &v1alpha1.TaskRef{
APIVersion: "blah",
Expand All @@ -132,6 +145,9 @@ func TestRun_Valid(t *testing.T) {
}, {
name: "unique params",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{
Ref: &v1alpha1.TaskRef{
APIVersion: "blah",
Expand All @@ -149,6 +165,9 @@ func TestRun_Valid(t *testing.T) {
}, {
name: "valid workspace",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{
Ref: &v1alpha1.TaskRef{
APIVersion: "blah",
Expand Down Expand Up @@ -177,6 +196,9 @@ func TestRun_Workspaces_Invalid(t *testing.T) {
}{{
name: "make sure WorkspaceBinding validation invoked",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{
Ref: &v1alpha1.TaskRef{
APIVersion: "blah",
Expand All @@ -194,6 +216,9 @@ func TestRun_Workspaces_Invalid(t *testing.T) {
}, {
name: "bind same workspace twice",
run: &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.RunSpec{
Ref: &v1alpha1.TaskRef{
APIVersion: "blah",
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func TestTaskRun_Invalid(t *testing.T) {
want: apis.ErrMissingField("spec"),
}, {
name: "invalid taskrun metadata",
task: tb.TaskRun("task.name"),
task: tb.TaskRun("task,name"),
want: &apis.FieldError{
Message: "Invalid resource name: special character . must not be present",
Message: `invalid resource name "task,name": must be a valid DNS label`,
Paths: []string{"metadata.name"},
},
}}
Expand Down
9 changes: 5 additions & 4 deletions pkg/apis/pipeline/v1beta1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestPipeline_Validate_Success(t *testing.T) {
}, {
name: "pipelinetask custom task references",
p: &Pipeline{
ObjectMeta: metav1.ObjectMeta{Name: "pipeline"},
Spec: PipelineSpec{
Tasks: []PipelineTask{{Name: "foo", TaskRef: &TaskRef{APIVersion: "example.dev/v0", Kind: "Example", Name: ""}}},
},
Expand Down Expand Up @@ -134,15 +135,15 @@ func TestPipeline_Validate_Failure(t *testing.T) {
expectedError apis.FieldError
wc func(context.Context) context.Context
}{{
name: "period in name",
name: "comma in name",
p: &Pipeline{
ObjectMeta: metav1.ObjectMeta{Name: "pipe.line"},
ObjectMeta: metav1.ObjectMeta{Name: "pipe,line"},
Spec: PipelineSpec{
Tasks: []PipelineTask{{Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}}},
},
},
expectedError: apis.FieldError{
Message: `Invalid resource name: special character . must not be present`,
Message: `invalid resource name "pipe,line": must be a valid DNS label`,
Paths: []string{"metadata.name"},
},
}, {
Expand All @@ -154,7 +155,7 @@ func TestPipeline_Validate_Failure(t *testing.T) {
},
},
expectedError: apis.FieldError{
Message: `Invalid resource name: length must be no more than 63 characters`,
Message: "Invalid resource name: length must be no more than 63 characters",
Paths: []string{"metadata.name"},
},
}, {
Expand Down
Loading

0 comments on commit 2ce1061

Please sign in to comment.