@@ -22,7 +22,7 @@ import (
22
22
"strings"
23
23
"time"
24
24
25
- apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
25
+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
26
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
27
)
28
28
@@ -56,24 +56,24 @@ const (
56
56
57
57
// GetAPIApprovalState returns the state of the API approval and reason for that state
58
58
func GetAPIApprovalState (annotations map [string ]string ) (state APIApprovalState , reason string ) {
59
- annotation := annotations [apiextensions .KubeAPIApprovedAnnotation ]
59
+ annotation := annotations [apiextensionsv1 .KubeAPIApprovedAnnotation ]
60
60
61
61
// we use the result of this parsing in the switch/case below
62
62
url , annotationURLParseErr := url .ParseRequestURI (annotation )
63
63
switch {
64
64
case len (annotation ) == 0 :
65
- return APIApprovalMissing , fmt .Sprintf ("protected groups must have approval annotation %q, see https://github.com/kubernetes/enhancements/pull/1111" , apiextensions .KubeAPIApprovedAnnotation )
65
+ return APIApprovalMissing , fmt .Sprintf ("protected groups must have approval annotation %q, see https://github.com/kubernetes/enhancements/pull/1111" , apiextensionsv1 .KubeAPIApprovedAnnotation )
66
66
case strings .HasPrefix (annotation , "unapproved" ):
67
67
return APIApprovalBypassed , fmt .Sprintf ("not approved: %q" , annotation )
68
68
case annotationURLParseErr == nil && url != nil && len (url .Host ) > 0 && len (url .Scheme ) > 0 :
69
69
return APIApproved , fmt .Sprintf ("approved in %v" , annotation )
70
70
default :
71
- return APIApprovalInvalid , fmt .Sprintf ("protected groups must have approval annotation %q with either a URL or a reason starting with \" unapproved\" , see https://github.com/kubernetes/enhancements/pull/1111" , apiextensions .KubeAPIApprovedAnnotation )
71
+ return APIApprovalInvalid , fmt .Sprintf ("protected groups must have approval annotation %q with either a URL or a reason starting with \" unapproved\" , see https://github.com/kubernetes/enhancements/pull/1111" , apiextensionsv1 .KubeAPIApprovedAnnotation )
72
72
}
73
73
}
74
74
75
75
// SetCRDCondition sets the status condition. It either overwrites the existing one or creates a new one.
76
- func SetCRDCondition (crd * apiextensions .CustomResourceDefinition , newCondition apiextensions .CustomResourceDefinitionCondition ) {
76
+ func SetCRDCondition (crd * apiextensionsv1 .CustomResourceDefinition , newCondition apiextensionsv1 .CustomResourceDefinitionCondition ) {
77
77
newCondition .LastTransitionTime = metav1 .NewTime (time .Now ())
78
78
79
79
existingCondition := FindCRDCondition (crd , newCondition .Type )
@@ -92,8 +92,8 @@ func SetCRDCondition(crd *apiextensions.CustomResourceDefinition, newCondition a
92
92
}
93
93
94
94
// RemoveCRDCondition removes the status condition.
95
- func RemoveCRDCondition (crd * apiextensions .CustomResourceDefinition , conditionType apiextensions .CustomResourceDefinitionConditionType ) {
96
- newConditions := []apiextensions .CustomResourceDefinitionCondition {}
95
+ func RemoveCRDCondition (crd * apiextensionsv1 .CustomResourceDefinition , conditionType apiextensionsv1 .CustomResourceDefinitionConditionType ) {
96
+ newConditions := []apiextensionsv1 .CustomResourceDefinitionCondition {}
97
97
for _ , condition := range crd .Status .Conditions {
98
98
if condition .Type != conditionType {
99
99
newConditions = append (newConditions , condition )
@@ -103,7 +103,7 @@ func RemoveCRDCondition(crd *apiextensions.CustomResourceDefinition, conditionTy
103
103
}
104
104
105
105
// FindCRDCondition returns the condition you're looking for or nil.
106
- func FindCRDCondition (crd * apiextensions .CustomResourceDefinition , conditionType apiextensions .CustomResourceDefinitionConditionType ) * apiextensions .CustomResourceDefinitionCondition {
106
+ func FindCRDCondition (crd * apiextensionsv1 .CustomResourceDefinition , conditionType apiextensionsv1 .CustomResourceDefinitionConditionType ) * apiextensionsv1 .CustomResourceDefinitionCondition {
107
107
for i := range crd .Status .Conditions {
108
108
if crd .Status .Conditions [i ].Type == conditionType {
109
109
return & crd .Status .Conditions [i ]
@@ -114,17 +114,17 @@ func FindCRDCondition(crd *apiextensions.CustomResourceDefinition, conditionType
114
114
}
115
115
116
116
// IsCRDConditionTrue indicates if the condition is present and strictly true.
117
- func IsCRDConditionTrue (crd * apiextensions .CustomResourceDefinition , conditionType apiextensions .CustomResourceDefinitionConditionType ) bool {
118
- return IsCRDConditionPresentAndEqual (crd , conditionType , apiextensions .ConditionTrue )
117
+ func IsCRDConditionTrue (crd * apiextensionsv1 .CustomResourceDefinition , conditionType apiextensionsv1 .CustomResourceDefinitionConditionType ) bool {
118
+ return IsCRDConditionPresentAndEqual (crd , conditionType , apiextensionsv1 .ConditionTrue )
119
119
}
120
120
121
121
// IsCRDConditionFalse indicates if the condition is present and false.
122
- func IsCRDConditionFalse (crd * apiextensions .CustomResourceDefinition , conditionType apiextensions .CustomResourceDefinitionConditionType ) bool {
123
- return IsCRDConditionPresentAndEqual (crd , conditionType , apiextensions .ConditionFalse )
122
+ func IsCRDConditionFalse (crd * apiextensionsv1 .CustomResourceDefinition , conditionType apiextensionsv1 .CustomResourceDefinitionConditionType ) bool {
123
+ return IsCRDConditionPresentAndEqual (crd , conditionType , apiextensionsv1 .ConditionFalse )
124
124
}
125
125
126
126
// IsCRDConditionPresentAndEqual indicates if the condition is present and equal to the given status.
127
- func IsCRDConditionPresentAndEqual (crd * apiextensions .CustomResourceDefinition , conditionType apiextensions .CustomResourceDefinitionConditionType , status apiextensions .ConditionStatus ) bool {
127
+ func IsCRDConditionPresentAndEqual (crd * apiextensionsv1 .CustomResourceDefinition , conditionType apiextensionsv1 .CustomResourceDefinitionConditionType , status apiextensionsv1 .ConditionStatus ) bool {
128
128
for _ , condition := range crd .Status .Conditions {
129
129
if condition .Type == conditionType {
130
130
return condition .Status == status
@@ -134,7 +134,7 @@ func IsCRDConditionPresentAndEqual(crd *apiextensions.CustomResourceDefinition,
134
134
}
135
135
136
136
// IsCRDConditionEquivalent returns true if the lhs and rhs are equivalent except for times.
137
- func IsCRDConditionEquivalent (lhs , rhs * apiextensions .CustomResourceDefinitionCondition ) bool {
137
+ func IsCRDConditionEquivalent (lhs , rhs * apiextensionsv1 .CustomResourceDefinitionCondition ) bool {
138
138
if lhs == nil && rhs == nil {
139
139
return true
140
140
}
@@ -146,7 +146,7 @@ func IsCRDConditionEquivalent(lhs, rhs *apiextensions.CustomResourceDefinitionCo
146
146
}
147
147
148
148
// CRDHasFinalizer returns true if the finalizer is in the list.
149
- func CRDHasFinalizer (crd * apiextensions .CustomResourceDefinition , needle string ) bool {
149
+ func CRDHasFinalizer (crd * apiextensionsv1 .CustomResourceDefinition , needle string ) bool {
150
150
for _ , finalizer := range crd .Finalizers {
151
151
if finalizer == needle {
152
152
return true
@@ -157,7 +157,7 @@ func CRDHasFinalizer(crd *apiextensions.CustomResourceDefinition, needle string)
157
157
}
158
158
159
159
// CRDRemoveFinalizer removes the finalizer if present.
160
- func CRDRemoveFinalizer (crd * apiextensions .CustomResourceDefinition , needle string ) {
160
+ func CRDRemoveFinalizer (crd * apiextensionsv1 .CustomResourceDefinition , needle string ) {
161
161
newFinalizers := []string {}
162
162
for _ , finalizer := range crd .Finalizers {
163
163
if finalizer != needle {
@@ -168,7 +168,7 @@ func CRDRemoveFinalizer(crd *apiextensions.CustomResourceDefinition, needle stri
168
168
}
169
169
170
170
// HasServedCRDVersion returns true if the given version is in the list of CRD's versions and the Served flag is set.
171
- func HasServedCRDVersion (crd * apiextensions .CustomResourceDefinition , version string ) bool {
171
+ func HasServedCRDVersion (crd * apiextensionsv1 .CustomResourceDefinition , version string ) bool {
172
172
for _ , v := range crd .Spec .Versions {
173
173
if v .Name == version {
174
174
return v .Served
@@ -178,18 +178,18 @@ func HasServedCRDVersion(crd *apiextensions.CustomResourceDefinition, version st
178
178
}
179
179
180
180
// GetCRDStorageVersion returns the storage version for given CRD.
181
- func GetCRDStorageVersion (crd * apiextensions .CustomResourceDefinition ) (string , error ) {
181
+ func GetCRDStorageVersion (crd * apiextensionsv1 .CustomResourceDefinition ) (string , error ) {
182
182
for _ , v := range crd .Spec .Versions {
183
183
if v .Storage {
184
184
return v .Name , nil
185
185
}
186
186
}
187
187
// This should not happened if crd is valid
188
- return "" , fmt .Errorf ("invalid apiextensions .CustomResourceDefinition, no storage version" )
188
+ return "" , fmt .Errorf ("invalid apiextensionsv1 .CustomResourceDefinition, no storage version" )
189
189
}
190
190
191
191
// IsStoredVersion returns whether the given version is the storage version of the CRD.
192
- func IsStoredVersion (crd * apiextensions .CustomResourceDefinition , version string ) bool {
192
+ func IsStoredVersion (crd * apiextensionsv1 .CustomResourceDefinition , version string ) bool {
193
193
for _ , v := range crd .Status .StoredVersions {
194
194
if version == v {
195
195
return true
@@ -199,27 +199,27 @@ func IsStoredVersion(crd *apiextensions.CustomResourceDefinition, version string
199
199
}
200
200
201
201
// GetSchemaForVersion returns the validation schema for the given version or nil.
202
- func GetSchemaForVersion (crd * apiextensions .CustomResourceDefinition , version string ) (* apiextensions .CustomResourceValidation , error ) {
202
+ func GetSchemaForVersion (crd * apiextensionsv1 .CustomResourceDefinition , version string ) (* apiextensionsv1 .CustomResourceValidation , error ) {
203
203
for _ , v := range crd .Spec .Versions {
204
204
if version == v .Name {
205
205
return v .Schema , nil
206
206
}
207
207
}
208
- return nil , fmt .Errorf ("version %s not found in apiextensions .CustomResourceDefinition: %v" , version , crd .Name )
208
+ return nil , fmt .Errorf ("version %s not found in apiextensionsv1 .CustomResourceDefinition: %v" , version , crd .Name )
209
209
}
210
210
211
211
// GetSubresourcesForVersion returns the subresources for given version or nil.
212
- func GetSubresourcesForVersion (crd * apiextensions .CustomResourceDefinition , version string ) (* apiextensions .CustomResourceSubresources , error ) {
212
+ func GetSubresourcesForVersion (crd * apiextensionsv1 .CustomResourceDefinition , version string ) (* apiextensionsv1 .CustomResourceSubresources , error ) {
213
213
for _ , v := range crd .Spec .Versions {
214
214
if version == v .Name {
215
215
return v .Subresources , nil
216
216
}
217
217
}
218
- return nil , fmt .Errorf ("version %s not found in apiextensions .CustomResourceDefinition: %v" , version , crd .Name )
218
+ return nil , fmt .Errorf ("version %s not found in apiextensionsv1 .CustomResourceDefinition: %v" , version , crd .Name )
219
219
}
220
220
221
221
// HasPerVersionSchema returns true if a CRD uses per-version schema.
222
- func HasPerVersionSchema (versions []apiextensions .CustomResourceDefinitionVersion ) bool {
222
+ func HasPerVersionSchema (versions []apiextensionsv1 .CustomResourceDefinitionVersion ) bool {
223
223
for _ , v := range versions {
224
224
if v .Schema != nil {
225
225
return true
@@ -229,7 +229,7 @@ func HasPerVersionSchema(versions []apiextensions.CustomResourceDefinitionVersio
229
229
}
230
230
231
231
// HasPerVersionSubresources returns true if a CRD uses per-version subresources.
232
- func HasPerVersionSubresources (versions []apiextensions .CustomResourceDefinitionVersion ) bool {
232
+ func HasPerVersionSubresources (versions []apiextensionsv1 .CustomResourceDefinitionVersion ) bool {
233
233
for _ , v := range versions {
234
234
if v .Subresources != nil {
235
235
return true
@@ -239,7 +239,7 @@ func HasPerVersionSubresources(versions []apiextensions.CustomResourceDefinition
239
239
}
240
240
241
241
// HasPerVersionColumns returns true if a CRD uses per-version columns.
242
- func HasPerVersionColumns (versions []apiextensions .CustomResourceDefinitionVersion ) bool {
242
+ func HasPerVersionColumns (versions []apiextensionsv1 .CustomResourceDefinitionVersion ) bool {
243
243
for _ , v := range versions {
244
244
if len (v .AdditionalPrinterColumns ) > 0 {
245
245
return true
@@ -249,7 +249,7 @@ func HasPerVersionColumns(versions []apiextensions.CustomResourceDefinitionVersi
249
249
}
250
250
251
251
// HasVersionServed returns true if given CRD has given version served.
252
- func HasVersionServed (crd * apiextensions .CustomResourceDefinition , version string ) bool {
252
+ func HasVersionServed (crd * apiextensionsv1 .CustomResourceDefinition , version string ) bool {
253
253
for _ , v := range crd .Spec .Versions {
254
254
if ! v .Served || v .Name != version {
255
255
continue
0 commit comments