forked from openshift/api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
193 lines (167 loc) · 6.21 KB
/
util.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package features
import (
"fmt"
configv1 "github.com/openshift/api/config/v1"
)
// FeatureGateDescription is a golang-only interface used to contains details for a feature gate.
type FeatureGateDescription struct {
// FeatureGateAttributes is the information that appears in the API
FeatureGateAttributes configv1.FeatureGateAttributes
// OwningJiraComponent is the jira component that owns most of the impl and first assignment for the bug.
// This is the team that owns the feature long term.
OwningJiraComponent string
// ResponsiblePerson is the person who is on the hook for first contact. This is often, but not always, a team lead.
// It is someone who can make the promise on the behalf of the team.
ResponsiblePerson string
// OwningProduct is the product that owns the lifecycle of the gate.
OwningProduct OwningProduct
}
type FeatureGateEnabledDisabled struct {
Enabled []FeatureGateDescription
Disabled []FeatureGateDescription
}
type ClusterProfileName string
var (
Hypershift = ClusterProfileName("include.release.openshift.io/ibm-cloud-managed")
SelfManaged = ClusterProfileName("include.release.openshift.io/self-managed-high-availability")
AllClusterProfiles = []ClusterProfileName{Hypershift, SelfManaged}
)
type OwningProduct string
var (
ocpSpecific = OwningProduct("OCP")
kubernetes = OwningProduct("Kubernetes")
)
type featureGateBuilder struct {
name string
owningJiraComponent string
responsiblePerson string
owningProduct OwningProduct
statusByClusterProfileByFeatureSet map[ClusterProfileName]map[configv1.FeatureSet]bool
}
// newFeatureGate featuregate are disabled in every FeatureSet and selectively enabled
func newFeatureGate(name string) *featureGateBuilder {
b := &featureGateBuilder{
name: name,
statusByClusterProfileByFeatureSet: map[ClusterProfileName]map[configv1.FeatureSet]bool{},
}
for _, clusterProfile := range AllClusterProfiles {
byFeatureSet := map[configv1.FeatureSet]bool{}
for _, featureSet := range configv1.AllFixedFeatureSets {
byFeatureSet[featureSet] = false
}
b.statusByClusterProfileByFeatureSet[clusterProfile] = byFeatureSet
}
return b
}
func (b *featureGateBuilder) reportProblemsToJiraComponent(owningJiraComponent string) *featureGateBuilder {
b.owningJiraComponent = owningJiraComponent
return b
}
func (b *featureGateBuilder) contactPerson(responsiblePerson string) *featureGateBuilder {
b.responsiblePerson = responsiblePerson
return b
}
func (b *featureGateBuilder) productScope(owningProduct OwningProduct) *featureGateBuilder {
b.owningProduct = owningProduct
return b
}
func (b *featureGateBuilder) enableIn(featureSets ...configv1.FeatureSet) *featureGateBuilder {
for clusterProfile := range b.statusByClusterProfileByFeatureSet {
for _, featureSet := range featureSets {
b.statusByClusterProfileByFeatureSet[clusterProfile][featureSet] = true
}
}
return b
}
func (b *featureGateBuilder) enableForClusterProfile(clusterProfile ClusterProfileName, featureSets ...configv1.FeatureSet) *featureGateBuilder {
for _, featureSet := range featureSets {
b.statusByClusterProfileByFeatureSet[clusterProfile][featureSet] = true
}
return b
}
func (b *featureGateBuilder) register() (configv1.FeatureGateName, error) {
if len(b.name) == 0 {
return "", fmt.Errorf("missing name")
}
if len(b.owningJiraComponent) == 0 {
return "", fmt.Errorf("missing owningJiraComponent")
}
if len(b.responsiblePerson) == 0 {
return "", fmt.Errorf("missing responsiblePerson")
}
if len(b.owningProduct) == 0 {
return "", fmt.Errorf("missing owningProduct")
}
featureGateName := configv1.FeatureGateName(b.name)
description := FeatureGateDescription{
FeatureGateAttributes: configv1.FeatureGateAttributes{
Name: featureGateName,
},
OwningJiraComponent: b.owningJiraComponent,
ResponsiblePerson: b.responsiblePerson,
OwningProduct: b.owningProduct,
}
// statusByClusterProfileByFeatureSet is initialized by constructor to be false for every combination
for clusterProfile, byFeatureSet := range b.statusByClusterProfileByFeatureSet {
for featureSet, enabled := range byFeatureSet {
if _, ok := allFeatureGates[clusterProfile]; !ok {
allFeatureGates[clusterProfile] = map[configv1.FeatureSet]*FeatureGateEnabledDisabled{}
}
if _, ok := allFeatureGates[clusterProfile][featureSet]; !ok {
allFeatureGates[clusterProfile][featureSet] = &FeatureGateEnabledDisabled{}
}
if enabled {
allFeatureGates[clusterProfile][featureSet].Enabled = append(allFeatureGates[clusterProfile][featureSet].Enabled, description)
} else {
allFeatureGates[clusterProfile][featureSet].Disabled = append(allFeatureGates[clusterProfile][featureSet].Disabled, description)
}
}
}
return featureGateName, nil
}
func (b *featureGateBuilder) mustRegister() configv1.FeatureGateName {
ret, err := b.register()
if err != nil {
panic(err)
}
return ret
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *FeatureGateEnabledDisabled) DeepCopyInto(out *FeatureGateEnabledDisabled) {
*out = *in
if in.Enabled != nil {
in, out := &in.Enabled, &out.Enabled
*out = make([]FeatureGateDescription, len(*in))
copy(*out, *in)
}
if in.Disabled != nil {
in, out := &in.Disabled, &out.Disabled
*out = make([]FeatureGateDescription, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FeatureGateEnabledDisabled.
func (in *FeatureGateEnabledDisabled) DeepCopy() *FeatureGateEnabledDisabled {
if in == nil {
return nil
}
out := new(FeatureGateEnabledDisabled)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *FeatureGateDescription) DeepCopyInto(out *FeatureGateDescription) {
*out = *in
out.FeatureGateAttributes = in.FeatureGateAttributes
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FeatureGateDescription.
func (in *FeatureGateDescription) DeepCopy() *FeatureGateDescription {
if in == nil {
return nil
}
out := new(FeatureGateDescription)
in.DeepCopyInto(out)
return out
}