/*
Copyright 2021 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 v1alpha1

import (
	"context"
)

func (tc *TektonConfig) SetDefaults(ctx context.Context) {
	if tc.Spec.Profile == "" {
		tc.Spec.Profile = ProfileBasic
	}

	tc.Spec.Pipeline.PipelineProperties.setDefaults()

	setAddonDefaults(&tc.Spec.Addon.Params)
}

/*
Copyright 2021 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 v1alpha1

import (
	"context"
)

func (tc *TektonConfig) SetDefaults(ctx context.Context) {
	if tc.Spec.Profile == "" {
		tc.Spec.Profile = ProfileBasic
	}

	tc.Spec.Pipeline.PipelineProperties.setDefaults()

	setAddonDefaults(&tc.Spec.Addon.Params)

	// before adding webhook we had default value for pruner's keep as 1
	// but we expect user to define all values now otherwise webhook reject
	// request so if a user has installed prev version and has not enabled
	// pruner then `keep` will have a value 1 and after upgrading
	// to newer version webhook will fail if keep has a value and
	// other fields are not defined
	// this handles that case by removing the default for keep if
	// other pruner fields are not defined
	if len(tc.Spec.Pruner.Resources) == 0 {
		tc.Spec.Pruner.Keep = nil
		tc.Spec.Pruner.Schedule = ""
	} else if tc.Spec.Pruner.Schedule == "" {
		tc.Spec.Pruner.Keep = nil
		tc.Spec.Pruner.Resources = []string{}
	}
}

Add param to enable/disable servicemonitor
[OpenShift] Add param to enable/disable servicemonitor

This adds a param in TektonConfig & TektonPipeline  to disable service monitor
which is a part of TektonPipelines for OpenShift.
Param will be added by default, user can change the value in TektonConfig
to false to disable.

Value is added in openshift extension and not in webhook as this is
platform specific param.

If invalid value is passed then	default	value is set for param to avoid
installation failure. Users can	pass valid values and change the param.

Signed-off-by: Shivam Mukhade <330299940dbe3b9a5e12a3de6ca29752465435c4@redhat.com>
