Skip to content

Commit

Permalink
Update feature flags for pipeline
Browse files Browse the repository at this point in the history
This will update feature flags of pipeline component to
be compatible with latest 0.54 release of pipeline
  • Loading branch information
piyush-garg committed Dec 5, 2023
1 parent f1cf325 commit 684504d
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 1 deletion.
39 changes: 39 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonpipeline_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,42 @@ func (p *Pipeline) setDefaults() {
// Deprecated: set to nil, remove in further release
p.ScopeWhenExpressionsToTask = nil

if p.EnforceNonfalsifiability == "" {
p.EnforceNonfalsifiability = config.DefaultEnforceNonfalsifiability
}

if p.EnableKeepPodOnCancel == nil {
p.EnableKeepPodOnCancel = ptr.Bool(config.DefaultEnableKeepPodOnCancel)
}

if p.ResultExtractionMethod == "" {
p.ResultExtractionMethod = config.DefaultResultExtractionMethod
}

if p.MaxResultSize == nil {
p.MaxResultSize = ptr.Int32(config.DefaultMaxResultSize)
}

if p.SetSecurityContext == nil {
p.SetSecurityContext = ptr.Bool(config.DefaultSetSecurityContext)
}

if p.Coschedule == "" {
p.Coschedule = config.DefaultCoschedule
}

if p.EnableCELInWhenExpression == nil {
p.EnableCELInWhenExpression = ptr.Bool(config.DefaultEnableCELInWhenExpression)
}

if p.EnableStepActions == nil {
p.EnableStepActions = ptr.Bool(config.DefaultEnableStepActions)
}

if p.EnableParamEnum == nil {
p.EnableParamEnum = ptr.Bool(config.DefaultEnableParamEnum)
}

if p.MetricsPipelinerunDurationType == "" {
p.MetricsPipelinerunDurationType = config.DefaultDurationPipelinerunType
}
Expand All @@ -89,6 +125,9 @@ func (p *Pipeline) setDefaults() {
if p.MetricsTaskrunLevel == "" {
p.MetricsTaskrunLevel = config.DefaultTaskrunLevel
}
if p.CountWithReason == nil {
p.CountWithReason = ptr.Bool(false)
}

// Resolvers
if p.EnableBundlesResolver == nil {
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonpipeline_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,21 @@ func Test_SetDefaults_PipelineProperties(t *testing.T) {
SendCloudEventsForRuns: ptr.Bool(false),
VerificationNoMatchPolicy: config.DefaultNoMatchPolicyConfig,
EnableProvenanceInStatus: ptr.Bool(true),
EnforceNonfalsifiability: config.DefaultEnforceNonfalsifiability,
EnableKeepPodOnCancel: ptr.Bool(config.DefaultEnableKeepPodOnCancel),
ResultExtractionMethod: config.DefaultResultExtractionMethod,
MaxResultSize: ptr.Int32(config.DefaultMaxResultSize),
SetSecurityContext: ptr.Bool(config.DefaultSetSecurityContext),
Coschedule: config.DefaultCoschedule,
EnableCELInWhenExpression: ptr.Bool(config.DefaultEnableCELInWhenExpression),
EnableStepActions: ptr.Bool(config.DefaultEnableStepActions),
EnableParamEnum: ptr.Bool(config.DefaultEnableParamEnum),
PipelineMetricsProperties: PipelineMetricsProperties{
MetricsPipelinerunDurationType: "histogram",
MetricsPipelinerunLevel: "pipeline",
MetricsTaskrunDurationType: "histogram",
MetricsTaskrunLevel: "task",
CountWithReason: ptr.Bool(false),
},
Resolvers: Resolvers{
EnableBundlesResolver: ptr.Bool(true),
Expand Down
15 changes: 14 additions & 1 deletion pkg/apis/operator/v1alpha1/tektonpipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,18 @@ type PipelineProperties struct {

// ScopeWhenExpressionsToTask Deprecated: remove in next release
ScopeWhenExpressionsToTask *bool `json:"scope-when-expressions-to-task,omitempty"`
PipelineMetricsProperties `json:",inline"`

EnforceNonfalsifiability string `json:"enforce-nonfalsifiability,omitempty"`
EnableKeepPodOnCancel *bool `json:"keep-pod-on-cancel,omitempty"`
ResultExtractionMethod string `json:"results-from,omitempty"`
MaxResultSize *int32 `json:"max-result-size,omitempty"`
SetSecurityContext *bool `json:"set-security-context,omitempty"`
Coschedule string `json:"coschedule,omitempty"`
EnableCELInWhenExpression *bool `json:"enable-cel-in-whenexpression,omitempty"`
EnableStepActions *bool `json:"enable-step-actions,omitempty"`
EnableParamEnum *bool `json:"enable-param-enum,omitempty"`

PipelineMetricsProperties `json:",inline"`
// +optional
OptionalPipelineProperties `json:",inline"`
// +optional
Expand All @@ -128,6 +139,7 @@ type OptionalPipelineProperties struct {
DefaultTaskRunWorkspaceBinding string `json:"default-task-run-workspace-binding,omitempty"`
DefaultMaxMatrixCombinationsCount string `json:"default-max-matrix-combinations-count,omitempty"`
DefaultForbiddenEnv string `json:"default-forbidden-env,omitempty"`
DefaultResolverType string `json:"default-resolver-type,omitempty"`
}

// PipelineMetricsProperties defines the fields which are configurable for
Expand All @@ -137,6 +149,7 @@ type PipelineMetricsProperties struct {
MetricsTaskrunDurationType string `json:"metrics.taskrun.duration-type,omitempty"`
MetricsPipelinerunLevel string `json:"metrics.pipelinerun.level,omitempty"`
MetricsPipelinerunDurationType string `json:"metrics.pipelinerun.duration-type,omitempty"`
CountWithReason *bool `json:"metrics.count.enable-reason,omitempty"`
}

// Resolvers defines the fields to configure resolvers
Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonpipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (
var (
validatePipelineAllowedApiFields = sets.NewString("", config.AlphaAPIFields, config.BetaAPIFields, config.StableAPIFields)
validatePipelineVerificationNoMatchPolicy = sets.NewString("", config.FailNoMatchPolicy, config.WarnNoMatchPolicy, config.IgnoreNoMatchPolicy)
validatePipelineResultExtractionMethod = sets.NewString("", config.ResultExtractionMethodTerminationMessage, config.ResultExtractionMethodSidecarLogs)
validatePipelineEnforceNonFalsifiability = sets.NewString("", config.EnforceNonfalsifiabilityNone, config.EnforceNonfalsifiabilityWithSpire)
validatePipelineCoschedule = sets.NewString("", config.CoscheduleDisabled, config.CoscheduleWorkspaces, config.CoschedulePipelineRuns, config.CoscheduleIsolatePipelineRun)
)

func (tp *TektonPipeline) Validate(ctx context.Context) (errs *apis.FieldError) {
Expand Down Expand Up @@ -59,11 +62,29 @@ func (p *PipelineProperties) validate(path string) (errs *apis.FieldError) {
}
}

if p.MaxResultSize != nil {
if *p.MaxResultSize >= 1572864 {
errs = errs.Also(apis.ErrInvalidValue(p.MaxResultSize, path+".max-result-size"))
}
}

// validate trusted-resources-verification-no-match-policy
if !validatePipelineVerificationNoMatchPolicy.Has(p.VerificationNoMatchPolicy) {
errs = errs.Also(apis.ErrInvalidValue(p.VerificationNoMatchPolicy, fmt.Sprintf("%s.trusted-resources-verification-no-match-policy", path)))
}

if !validatePipelineResultExtractionMethod.Has(p.ResultExtractionMethod) {
errs = errs.Also(apis.ErrInvalidValue(p.ResultExtractionMethod, fmt.Sprintf("%s.results-from", path)))
}

if !validatePipelineEnforceNonFalsifiability.Has(p.EnforceNonfalsifiability) {
errs = errs.Also(apis.ErrInvalidValue(p.EnforceNonfalsifiability, fmt.Sprintf("%s.enforce-nonfalsifiability", path)))
}

if !validatePipelineCoschedule.Has(p.Coschedule) {
errs = errs.Also(apis.ErrInvalidValue(p.Coschedule, fmt.Sprintf("%s.coschedule", path)))
}

// validate performance properties
errs = errs.Also(p.Performance.validate(fmt.Sprintf("%s.performance", path)))

Expand Down
101 changes: 101 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonpipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,107 @@ func TestValidateTektonPipelineVerificationNoMatchPolicy(t *testing.T) {
}
}

func TestValidateTektonPipelineResultExtractionMethod(t *testing.T) {
tp := &TektonPipeline{
ObjectMeta: metav1.ObjectMeta{
Name: "pipeline",
Namespace: "tekton-pipelines-ns",
},
Spec: TektonPipelineSpec{
CommonSpec: CommonSpec{
TargetNamespace: "tekton-pipelines-ns",
},
},
}

tests := []struct {
name string
method string
err string
}{
{name: "method-empty-value", method: "", err: ""},
{name: "method-sidecar", method: config.ResultExtractionMethodSidecarLogs, err: ""},
{name: "method-termination", method: config.ResultExtractionMethodTerminationMessage, err: ""},
{name: "method-invalid", method: "hello", err: "invalid value: hello: spec.results-from"},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tp.Spec.Pipeline.ResultExtractionMethod = test.method
errs := tp.Validate(context.TODO())
assert.Equal(t, test.err, errs.Error())
})
}
}

func TestValidateTektonPipelineEnforceNonFalsifiability(t *testing.T) {
tp := &TektonPipeline{
ObjectMeta: metav1.ObjectMeta{
Name: "pipeline",
Namespace: "tekton-pipelines-ns",
},
Spec: TektonPipelineSpec{
CommonSpec: CommonSpec{
TargetNamespace: "tekton-pipelines-ns",
},
},
}

tests := []struct {
name string
falsifiability string
err string
}{
{name: "falsifiability-empty-value", falsifiability: "", err: ""},
{name: "falsifiability-none", falsifiability: config.EnforceNonfalsifiabilityNone, err: ""},
{name: "falsifiability-spire", falsifiability: config.EnforceNonfalsifiabilityWithSpire, err: ""},
{name: "falsifiability-invalid", falsifiability: "hello", err: "invalid value: hello: spec.enforce-nonfalsifiability"},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tp.Spec.Pipeline.EnforceNonfalsifiability = test.falsifiability
errs := tp.Validate(context.TODO())
assert.Equal(t, test.err, errs.Error())
})
}
}

func TestValidateTektonPipelineCoschedule(t *testing.T) {
tp := &TektonPipeline{
ObjectMeta: metav1.ObjectMeta{
Name: "pipeline",
Namespace: "tekton-pipelines-ns",
},
Spec: TektonPipelineSpec{
CommonSpec: CommonSpec{
TargetNamespace: "tekton-pipelines-ns",
},
},
}

tests := []struct {
name string
coschedule string
err string
}{
{name: "coschedule-empty-value", coschedule: "", err: ""},
{name: "coschedule-disabled", coschedule: config.CoscheduleDisabled, err: ""},
{name: "coschedule-workspaces", coschedule: config.CoscheduleWorkspaces, err: ""},
{name: "coschedule-pipelineruns", coschedule: config.CoschedulePipelineRuns, err: ""},
{name: "coschedule-isolate-pipelineruns", coschedule: config.CoscheduleIsolatePipelineRun, err: ""},
{name: "coschedule-invalid", coschedule: "hello", err: "invalid value: hello: spec.coschedule"},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tp.Spec.Pipeline.Coschedule = test.coschedule
errs := tp.Validate(context.TODO())
assert.Equal(t, test.err, errs.Error())
})
}
}

func Test_ValidateTektonPipeline_OnDelete(t *testing.T) {

td := &TektonPipeline{
Expand Down

0 comments on commit 684504d

Please sign in to comment.