-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathtektonconfig_defaults.go
97 lines (81 loc) · 2.89 KB
/
tektonconfig_defaults.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
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"
"strings"
"knative.dev/pkg/logging"
"knative.dev/pkg/ptr"
)
func (tc *TektonConfig) SetDefaults(ctx context.Context) {
if tc.Spec.Profile == "" {
tc.Spec.Profile = ProfileBasic
}
tc.Spec.Pipeline.setDefaults()
tc.Spec.Trigger.setDefaults()
if IsOpenShiftPlatform() {
if tc.Spec.Platforms.OpenShift.PipelinesAsCode == nil {
tc.Spec.Platforms.OpenShift.PipelinesAsCode = &PipelinesAsCode{
Enable: ptr.Bool(true),
PACSettings: PACSettings{
Settings: map[string]string{},
},
}
} else {
tc.Spec.Addon.EnablePAC = nil
}
// check if PAC is disabled through addon before enabling through OpenShiftPipelinesAsCode
if tc.Spec.Addon.EnablePAC != nil && !*tc.Spec.Addon.EnablePAC {
tc.Spec.Platforms.OpenShift.PipelinesAsCode.Enable = ptr.Bool(false)
tc.Spec.Platforms.OpenShift.PipelinesAsCode.PACSettings.Settings = nil
}
// pac defaulting
if *tc.Spec.Platforms.OpenShift.PipelinesAsCode.Enable {
logger := logging.FromContext(ctx)
tc.Spec.Platforms.OpenShift.PipelinesAsCode.PACSettings.setPACDefaults(logger)
}
// SCC defaulting
if tc.Spec.Platforms.OpenShift.SCC == nil {
tc.Spec.Platforms.OpenShift.SCC = &SCC{}
}
if tc.Spec.Platforms.OpenShift.SCC.Default == "" {
tc.Spec.Platforms.OpenShift.SCC.Default = PipelinesSCC
}
setAddonDefaults(&tc.Spec.Addon)
} else {
tc.Spec.Addon = Addon{}
tc.Spec.Platforms.OpenShift = OpenShift{}
}
// earlier pruner was disabled with empty schedule or empty resources
// now empty schedule, disables only the global cron job,
// if a namespace has prune schedule annotation, a cron job will be created for that
// to disable the pruner feature, "disabled" should be set as "true"
if !tc.Spec.Pruner.Disabled {
// if keep and keep-since is nil, update default keep value
if tc.Spec.Pruner.Keep == nil && tc.Spec.Pruner.KeepSince == nil {
keep := PrunerDefaultKeep
tc.Spec.Pruner.Keep = &keep
}
// if empty resources, update default resources
if len(tc.Spec.Pruner.Resources) == 0 {
tc.Spec.Pruner.Resources = PruningDefaultResources
}
// trim space and to lower case resource names
for index := range tc.Spec.Pruner.Resources {
value := tc.Spec.Pruner.Resources[index]
value = strings.TrimSpace(value)
value = strings.ToLower(value)
tc.Spec.Pruner.Resources[index] = value
}
}
}