Skip to content

Commit f7cbd18

Browse files
committed
crdchecker: update api according to EP
1 parent 25be0e6 commit f7cbd18

File tree

1 file changed

+159
-23
lines changed

1 file changed

+159
-23
lines changed

operator/v1alpha1/types_crdchecker.go

Lines changed: 159 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v1alpha1
22

33
import (
4+
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
45
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
56
)
67

@@ -25,7 +26,7 @@ type CRDCompatibilityRequirement struct {
2526
// metadata is the standard object's metadata.
2627
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
2728
// +optional
28-
metav1.ObjectMeta `json:"metadata"`
29+
metav1.ObjectMeta `json:"metadata,omitzero"`
2930

3031
// spec is the specification of the desired behavior of the CRD Compatibility Requirement.
3132
// +required
@@ -38,38 +39,96 @@ type CRDCompatibilityRequirement struct {
3839

3940
// CRDCompatibilityRequirementSpec is the specification of the desired behavior of the CRD Compatibility Requirement.
4041
type CRDCompatibilityRequirementSpec struct {
41-
// crdRef is the name of the target CRD. The target CRD is not required to
42-
// exist, as we may legitimately place requirements on it before it is
43-
// created. The observed CRD is given in status.observedCRD, which will be
44-
// empty if no CRD is observed.
42+
// compatibilitySchema defines the schema used by crdSchemaValidation and objectSchemaValidation.
4543
// This field is required.
46-
// +kubebuilder:validation:MinLength=1
47-
// +kubebuilder:validation:MaxLength:=253
48-
// +kubebuilder:validation:XValidation:rule="!format.dns1123Subdomain().validate(self).hasValue()",message="a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character."
4944
// +required
50-
CRDRef string `json:"crdRef,omitempty"`
45+
CompatibilitySchema CompatibilitySchema `json:"compatibilitySchema,omitempty,omitzero"`
46+
47+
// crdSchemaValidation ensures that updates to the installed CRD are compatible with this compatibility requirement.
48+
// This field is optional.
49+
// +optional
50+
CRDSchemaValidation CRDSchemaValidation `json:"crdSchemaValidation,omitempty,omitzero"`
51+
52+
// objectSchemaValidation ensures that matching objects conform to compatibilitySchema.
53+
// This field is optional.
54+
// +optional
55+
ObjectSchemaValidation ObjectSchemaValidation `json:"objectSchemaValidation,omitempty,omitzero"`
56+
}
5157

52-
// creatorDescription is a string describing the owner of this CRDCompatibilityRequirement. It will be printed in any error or
53-
// warning emitted by any of the CRDCompatibilityRequirement's webhooks. It should indicate to the recipient who they need to coordinate
54-
// with in order to safely update the target CRD. The message emitted will be: "This requirement was added by <creatorDescription>".
58+
// CompatibilitySchema defines the schema used by crdSchemaValidation and objectSchemaValidation.
59+
type CompatibilitySchema struct {
60+
// crdYAML contains the complete YAML document of the CRD from transport config map.
5561
// This field is required.
5662
// +kubebuilder:validation:MinLength=1
57-
// +kubebuilder:validation:MaxLength=253
63+
// +kubebuilder:validation:MaxLength=1572864
5864
// +required
59-
CreatorDescription string `json:"creatorDescription,omitempty"`
65+
CRDYAML string `json:"crdYAML,omitempty"`
6066

61-
// compatibilityCRD contains the CRD which is required by the creator of this CRDCompatibilityRequirement. CRD Compatibility Checker will
62-
// ensure that only a target CRD compatible with compatibilityCRD may be admitted.
67+
// requireVersions specifies which versions we will automatically extract from the yaml and require.
68+
// Valid options are:
69+
// StorageOnly - only storage version(s) required for compatibility. Users can create/update
70+
// objects using any served version. additionalVersions are applied on top of this.
71+
// All - all versions defined in the CRD are required for compatibility.
6372
// This field is required.
64-
// +kubebuilder:validation:MinLength=1
65-
// +kubebuilder:validation:MaxLength=1000000
6673
// +required
67-
CompatibilityCRD string `json:"compatibilityCRD,omitempty"`
74+
RequireVersions RequireVersions `json:"requireVersions,omitempty"`
6875

69-
// crdAdmitAction determines whether the CRD admission controller will Enforce or Warn if the CRD presented is not compatible.
76+
// additionalVersions is a set of versions to require in addition to those discovered by requireVersions.
77+
// Overlap with requireVersions is explicitly permitted.
78+
// +kubebuilder:validation:items:MinLength=1
79+
// +kubebuilder:validation:items:MaxLength=255
80+
// +kubebuilder:validation:MaxItems=255
81+
// +listType=set
82+
// +optional
83+
AdditionalVersions []string `json:"additionalVersions,omitempty"`
84+
85+
// excludeFields is a set of fields in the yaml which will not be validated by either
86+
// crdSchemaValidation or objectSchemaValidation.
87+
// FIXME(chrischdi): explain the format which is
88+
// +kubebuilder:validation:items:MinLength=1
89+
// +kubebuilder:validation:items:MaxLength=8192
90+
// +kubebuilder:validation:MaxItems=1024
91+
// +listType=set
92+
// +optional
93+
ExcludeFields []string `json:"excludeFields,omitempty"`
94+
}
95+
96+
// CRDSchemaValidation ensures that updates to the installed CRD are compatible with this compatibility requirement.
97+
type CRDSchemaValidation struct {
98+
// action determines whether violations are not admitted (Enforce) or admitted with an API warning (Warn).
99+
// Valid options are:
100+
// Enforce - incompatible CRDs will be rejected and not admitted to the cluster.
101+
// Warn - incompatible CRDs will be allowed but a warning will be generated in the API response.
70102
// This field is required.
71103
// +required
72-
CRDAdmitAction CRDAdmitAction `json:"crdAdmitAction,omitempty"`
104+
Action CRDAdmitAction `json:"action,omitempty"`
105+
}
106+
107+
// ObjectSchemaValidation ensures that matching objects conform to compatibilitySchema.
108+
type ObjectSchemaValidation struct {
109+
// action determines whether violations are not admitted (Enforce) or admitted with an API warning (Warn).
110+
// Valid options are:
111+
// Enforce - incompatible Objects will be rejected and not admitted to the cluster.
112+
// Warn - incompatible Objects will be allowed but a warning will be generated in the API response.
113+
// This field is required.
114+
// +required
115+
Action CRDAdmitAction `json:"action,omitempty"`
116+
117+
// namespaceSelector defines the namespaceSelector field of the resulting ValidatingWebhookConfiguration.
118+
// +optional
119+
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
120+
121+
// objectSelector defines the objectSelector field of the resulting ValidatingWebhookConfiguration.
122+
// +optional
123+
ObjectSelector *metav1.LabelSelector `json:"objectSelector,omitempty"`
124+
125+
// matchConditions defines the matchConditions field of the resulting ValidatingWebhookConfiguration.
126+
// +listType=map
127+
// +listMapKey=name
128+
// +kubebuilder:validation:MinItems=1
129+
// +kubebuilder:validation:MaxItems=64
130+
// +optional
131+
MatchConditions []admissionregistrationv1.MatchCondition `json:"matchConditions,omitempty"`
73132
}
74133

75134
// CRDAdmitAction determines the action taken when a CRD is not compatible.
@@ -84,29 +143,106 @@ const (
84143
CRDAdmitActionWarn CRDAdmitAction = "Warn"
85144
)
86145

146+
// RequireVersions specifies which versions we will automatically extract from the yaml and require.
147+
// +kubebuilder:validation:Enum=StorageOnly;All
148+
type RequireVersions string
149+
150+
const (
151+
// RequireVersionsStorageOnly means only storage versions will be required.
152+
RequireVersionsStorageOnly RequireVersions = "StorageOnly"
153+
154+
// RequireVersionsAll means all versions will be required.
155+
RequireVersionsAll RequireVersions = "All"
156+
)
157+
158+
// CRDCompatibilityRequirement's Progressing condition and corresponding reasons.
159+
const (
160+
// CRDCompatibilityRequirementProgressing is false if the spec has been completely reconciled.
161+
// True indicates that reconciliation is still in progress and the current status does not represent
162+
// a stable state. Progressing false with an error reason indicates that the object cannot be reconciled.
163+
CRDCompatibilityRequirementProgressing string = "Progressing"
164+
165+
// CRDCompatibilityRequirementConfigurationErrorReason surfaces when reconciliation cannot progress due to an invalid spec.
166+
CRDCompatibilityRequirementConfigurationErrorReason string = "ConfigurationError"
167+
168+
// CRDCompatibilityRequirementTransientErrorReason surfaces when reconciliation failed due to an error that can be retried.
169+
CRDCompatibilityRequirementTransientErrorReason string = "TransientError"
170+
171+
// CRDCompatibilityRequirementUpToDateReason surfaces when reconciliation completed successfully.
172+
CRDCompatibilityRequirementUpToDateReason string = "UpToDate"
173+
)
174+
175+
// CRDCompatibilityRequirement's Admitted condition and corresponding reasons.
176+
const (
177+
// CRDCompatibilityRequirementAdmitted is true if the requirement has been configured in the validating webhook,
178+
// otherwise false.
179+
CRDCompatibilityRequirementAdmitted string = "Admitted"
180+
181+
// CRDCompatibilityRequirementAdmittedReason surfaces when the requirement has been configured in the validating webhook.
182+
CRDCompatibilityRequirementAdmittedReason string = "Admitted"
183+
184+
// CRDCompatibilityRequirementNotAdmittedReason surfaces when the requirement has not been configured in the validating webhook.
185+
CRDCompatibilityRequirementNotAdmittedReason string = "NotAdmitted"
186+
)
187+
188+
// CRDCompatibilityRequirement's Compatible condition and corresponding reasons.
189+
const (
190+
// CRDCompatibilityRequirementCompatible is true if the observed CRD is compatible with the requirement,
191+
// otherwise false. Note that Compatible may be false when adding a new requirement which the existing
192+
// CRD does not meet.
193+
CRDCompatibilityRequirementCompatible string = "Compatible"
194+
195+
// CRDCompatibilityRequirementRequirementsNotMetReason surfaces when a CRD exists, and it is not compatible with this requirement.
196+
CRDCompatibilityRequirementRequirementsNotMetReason string = "RequirementsNotMet"
197+
198+
// CRDCompatibilityRequirementCRDDoesNotExistReason surfaces when the referenced CRD does not exist.
199+
CRDCompatibilityRequirementCRDDoesNotExistReason string = "CRDDoesNotExist"
200+
201+
// CRDCompatibilityRequirementCompatibleWithWarningsReason surfaces when the CRD exists and is compatible with this requirement, but Message contains one or more warning messages.
202+
CRDCompatibilityRequirementCompatibleWithWarningsReason string = "CompatibleWithWarnings"
203+
204+
// CRDCompatibilityRequirementCompatibleReason surfaces when the CRD exists and is compatible with this requirement.
205+
CRDCompatibilityRequirementCompatibleReason string = "Compatible"
206+
)
207+
87208
// CRDCompatibilityRequirementStatus defines the observed status of the CRD Compatibility Requirement.
88209
// +kubebuilder:validation:MinProperties=1
89210
type CRDCompatibilityRequirementStatus struct {
90211
// conditions is a list of conditions and their status.
212+
// Known condition types are Progressing, Admitted, Compatible.
91213
// +optional
92214
// +listType=map
93215
// +listMapKey=type
94216
// +kubebuilder:validation:MaxItems=16
217+
// +kubebuilder:validation:MinItems=1
95218
Conditions []metav1.Condition `json:"conditions,omitempty"`
96219

97220
// observedCRD documents the uid and generation of the CRD object when the current status was written.
98221
// This field will not be emitted if the target CRD does not exist or could not be retrieved.
99222
// +optional
100223
ObservedCRD ObservedCRD `json:"observedCRD,omitzero"`
224+
225+
// crdName is the name of the target CRD. The target CRD is not required to
226+
// exist, as we may legitimately place requirements on it before it is
227+
// created. The observed CRD is given in status.observedCRD, which will be
228+
// empty if no CRD is observed.
229+
// This field is optional.
230+
// crdRef must be at most 253 characters in length and must consist only of lower-case alphanumeric characters, periods (.) and hyphens (-). Each period separated label must start and end with an alphanumeric character and be at most 63 characters in length.
231+
// +kubebuilder:validation:MinLength=1
232+
// +kubebuilder:validation:MaxLength=253
233+
// +kubebuilder:validation:XValidation:rule="!format.dns1123Subdomain().validate(self).hasValue()",message="a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character."
234+
// +optional
235+
CRDName string `json:"crdName,omitempty"`
101236
}
102237

103238
// ObservedCRD contains information about the observed target CRD.
104239
// +kubebuilder:validation:MinProperties=1
105240
type ObservedCRD struct {
106241
// uid is the uid of the observed CRD.
107-
// +kubebuilder:validation:MaxLength=36
108242
// +kubebuilder:validation:MinLength=1
243+
// +kubebuilder:validation:MaxLength=36
109244
// +kubebuilder:validation:Format=uuid
245+
// +kubebuilder:validation:XValidation:rule="!format.uuid().validate(self).hasValue()",message="uid must be a valid UUID. It must consist only of lower-case hexadecimal digits, in 5 hyphenated blocks, where the blocks are of length 8-4-4-4-12 respectively."
110246
// +required
111247
UID string `json:"uid,omitempty"`
112248

@@ -128,7 +264,7 @@ type CRDCompatibilityRequirementList struct {
128264
// metadata is the standard list's metadata.
129265
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
130266
// +optional
131-
metav1.ListMeta `json:"metadata"`
267+
metav1.ListMeta `json:"metadata,omitzero"`
132268

133269
// items is a list of CRDCompatibilityRequirements.
134270
// +kubebuilder:validation:MaxItems=1000

0 commit comments

Comments
 (0)