-
Notifications
You must be signed in to change notification settings - Fork 889
Expand file tree
/
Copy pathutil.go
More file actions
227 lines (195 loc) · 7.93 KB
/
Copy pathutil.go
File metadata and controls
227 lines (195 loc) · 7.93 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package features
import (
"fmt"
"net/url"
"strings"
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
// EnhancementPR is the PR for the enhancement.
EnhancementPR string
}
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
enhancementPRURL string
statusByClusterProfileByFeatureSet map[ClusterProfileName]map[configv1.FeatureSet]bool
}
const (
legacyFeatureGateWithoutEnhancement = "FeatureGate predates 4.18"
)
// 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) enhancementPR(url string) *featureGateBuilder {
b.enhancementPRURL = url
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")
}
_, enhancementPRErr := url.Parse(b.enhancementPRURL)
switch {
case b.enhancementPRURL == legacyFeatureGateWithoutEnhancement:
if !legacyFeatureGates.Has(b.name) {
return "", fmt.Errorf("FeatureGate/%s is a new feature gate, not an existing one. It must have an enhancementPR with GA Graduation Criteria like https://github.com/openshift/enhancements/pull/#### or https://github.com/kubernetes/enhancements/issues/####", b.name)
}
case len(b.enhancementPRURL) == 0:
return "", fmt.Errorf("FeatureGate/%s is missing an enhancementPR with GA Graduation Criteria like https://github.com/openshift/enhancements/pull/#### or https://github.com/kubernetes/enhancements/issues/####", b.name)
case !strings.HasPrefix(b.enhancementPRURL, "https://github.com/openshift/enhancements/pull/") &&
!strings.HasPrefix(b.enhancementPRURL, "https://github.com/kubernetes/enhancements/issues/") &&
!strings.HasPrefix(b.enhancementPRURL, "https://github.com/ovn-kubernetes/ovn-kubernetes/pull/"):
return "", fmt.Errorf("FeatureGate/%s enhancementPR format is incorrect; must be like https://github.com/openshift/enhancements/pull/#### or https://github.com/kubernetes/enhancements/issues/#### or https://github.com/ovn-kubernetes/ovn-kubernetes/pull/####", b.name)
case enhancementPRErr != nil:
return "", fmt.Errorf("FeatureGate/%s is enhancementPR is invalid: %w", b.name, enhancementPRErr)
}
featureGateName := configv1.FeatureGateName(b.name)
description := FeatureGateDescription{
FeatureGateAttributes: configv1.FeatureGateAttributes{
Name: featureGateName,
},
OwningJiraComponent: b.owningJiraComponent,
ResponsiblePerson: b.responsiblePerson,
OwningProduct: b.owningProduct,
EnhancementPR: b.enhancementPRURL,
}
// 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
}