-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEP-0060 adds remote resource resolution to Tekton Pipelines, allowing PipelineRuns and TaskRuns to reference Pipelines and Tasks in remote places like git repos. This PR adds the initial alpha syntax for the remote resolution feature to the v1beta1.TaskRef and v1beta1.PipelineRef types along with validation for them. Some initial documentation is added describing the syntax for remote tasks and pipelines.
- Loading branch information
1 parent
2b3a0db
commit 5d3f23e
Showing
16 changed files
with
632 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
Copyright 2022 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/go-containerregistry/pkg/name" | ||
"github.com/tektoncd/pipeline/pkg/apis/config" | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
// Validate ensures that a supplied PipelineRef field is populated | ||
// correctly. No errors are returned for a nil PipelineRef. | ||
func (ref *PipelineRef) Validate(ctx context.Context) (errs *apis.FieldError) { | ||
cfg := config.FromContextOrDefaults(ctx) | ||
if ref == nil { | ||
return | ||
} | ||
if cfg.FeatureFlags.EnableAPIFields == config.AlphaAPIFields { | ||
errs = errs.Also(ref.validateAlphaRef(ctx)) | ||
} else { | ||
errs = errs.Also(ref.validateInTreeRef(ctx)) | ||
} | ||
return | ||
} | ||
|
||
// validateInTreeRef returns errors if the given pipelineRef is not | ||
// valid for Pipelines' built-in resolution machinery. | ||
func (ref *PipelineRef) validateInTreeRef(ctx context.Context) (errs *apis.FieldError) { | ||
cfg := config.FromContextOrDefaults(ctx) | ||
if ref.Resolver != "" { | ||
errs = errs.Also(apis.ErrDisallowedFields("resolver")) | ||
} | ||
if ref.Resource != nil { | ||
errs = errs.Also(apis.ErrDisallowedFields("resource")) | ||
} | ||
if ref.Name == "" { | ||
errs = errs.Also(apis.ErrMissingField("name")) | ||
} | ||
if cfg.FeatureFlags.EnableTektonOCIBundles { | ||
if ref.Bundle != "" && ref.Name == "" { | ||
errs = errs.Also(apis.ErrMissingField("name")) | ||
} | ||
if ref.Bundle != "" { | ||
if _, err := name.ParseReference(ref.Bundle); err != nil { | ||
errs = errs.Also(apis.ErrInvalidValue("invalid bundle reference", "bundle", err.Error())) | ||
} | ||
} | ||
} else if ref.Bundle != "" { | ||
errs = errs.Also(apis.ErrDisallowedFields("bundle")) | ||
} | ||
return | ||
} | ||
|
||
// validateAlphaRef ensures that the user has passed either a | ||
// valid remote resource reference or a valid in-tree resource reference, | ||
// but not both. | ||
func (ref *PipelineRef) validateAlphaRef(ctx context.Context) (errs *apis.FieldError) { | ||
switch { | ||
case ref.Resolver == "" && ref.Resource != nil: | ||
errs = errs.Also(apis.ErrMissingField("resolver")) | ||
case ref.Resolver == "": | ||
errs = errs.Also(ref.validateInTreeRef(ctx)) | ||
default: | ||
if ref.Name != "" { | ||
errs = errs.Also(apis.ErrMultipleOneOf("name", "resolver")) | ||
} | ||
if ref.Bundle != "" { | ||
errs = errs.Also(apis.ErrMultipleOneOf("bundle", "resolver")) | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.