1 package v1 2 3 import ( 4 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 5 ) 6 7 // +genclient 8 // +genclient:nonNamespaced 9 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 10 // +kubebuilder:object:root=true 11 // +kubebuilder:subresource:status 12 // +openshift:compatibility-gen:level=1 13 14 // StableConfigType is a stable config type that may include TechPreviewNoUpgrade fields. 15 // 16 // Compatibility level 1: Stable within a major release for a minimum of 12 months or 3 minor releases (whichever is longer). 17 // +openshift:compatibility-gen:level=1 18 type StableConfigType struct { 19 metav1.TypeMeta `json:",inline"` 20 21 // metadata is the standard object's metadata. 22 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 23 metav1.ObjectMeta `json:"metadata,omitempty"` 24 25 // spec is the specification of the desired behavior of the StableConfigType. 26 Spec StableConfigTypeSpec `json:"spec,omitempty"` 27 // status is the most recently observed status of the StableConfigType. 28 Status StableConfigTypeStatus `json:"status,omitempty"` 29 } 30 31 // StableConfigTypeSpec is the desired state 32 type StableConfigTypeSpec struct { 33 // coolNewField is a field that is for tech preview only. On normal clusters this shouldn't be present 34 // 35 // +kubebuilder:validation:Optional 36 // +openshift:enable:FeatureSets=TechPreviewNoUpgrade 37 // +optional 38 CoolNewField string `json:"coolNewField"` 39 40 // stableField is a field that is present on default clusters and on tech preview clusters 41 // 42 // If empty, the platform will choose a good default, which may change over time without notice. 43 // 44 // +optional 45 StableField string `json:"stableField"` 46 47 // immutableField is a field that is immutable once the object has been created. 48 // It is required at all times. 49 // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="immutableField is immutable" 50 // +kubebuilder:validation:Required 51 ImmutableField string `json:"immutableField"` 52 53 // optionalImmutableField is a field that is immutable once set. 54 // It is optional but may not be changed once set. 55 // +kubebuilder:validation:XValidation:rule="oldSelf == '' || self == oldSelf",message="optionalImmutableField is immutable once set" 56 // +optional 57 OptionalImmutableField string `json:"optionalImmutableField"` 58 59 // evolvingUnion demonstrates how to phase in new values into discriminated union 60 // +optional 61 EvolvingUnion EvolvingUnion `json:"evolvingUnion"` 62 63 // celUnion demonstrates how to validate a discrminated union using CEL 64 // +optional 65 CELUnion CELUnion `json:"celUnion,omitempty"` 66 } 67 68 type EvolvingUnion struct { 69 // type is the discriminator. It has different values for Default and for TechPreviewNoUpgrade 70 // +kubebuilder:validation:Required 71 Type EvolvingDiscriminator `json:"type,omitempty"` 72 } 73 74 // EvolvingDiscriminator defines the audit policy profile type. 75 // +openshift:validation:FeatureSetAwareEnum:featureSet=Default,enum="";StableValue 76 // +openshift:validation:FeatureSetAwareEnum:featureSet=TechPreviewNoUpgrade,enum="";StableValue;TechPreviewOnlyValue 77 type EvolvingDiscriminator string 78 79 const ( 80 // "StableValue" is always present. 81 StableValue EvolvingDiscriminator = "StableValue" 82 83 // "TechPreviewOnlyValue" should only be allowed when TechPreviewNoUpgrade is set in the cluster 84 TechPreviewOnlyValue EvolvingDiscriminator = "TechPreviewOnlyValue" 85 ) 86 87 // CELUnion demonstrates how to use a discriminated union and how to validate it using CEL. 88 // +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'RequiredMember' ? has(self.requiredMember) : !has(self.requiredMember)",message="requiredMember is required when type is RequiredMember, and forbidden otherwise" 89 // +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'OptionalMember' ? true : !has(self.optionalMember)",message="optionalMember is forbidden when type is not OptionalMember" 90 // +union 91 type CELUnion struct { 92 // type determines which of the union members should be populated. 93 // +kubebuilder:validation:Required 94 // +unionDiscriminator 95 Type CELUnionDiscriminator `json:"type,omitempty"` 96 97 // requiredMember is a union member that is required. 98 // +unionMember 99 RequiredMember *string `json:"requiredMember,omitempty"` 100 101 // optionalMember is a union member that is optional. 102 // +unionMember,optional 103 OptionalMember *string `json:"optionalMember,omitempty"` 104 } 105 106 // CELUnionDiscriminator is a union discriminator for the CEL union. 107 // +kubebuilder:validation:Enum:="RequiredMember";"OptionalMember";"EmptyMember" 108 type CELUnionDiscriminator string 109 110 const ( 111 // RequiredMember represents a required union member. 112 RequiredMember CELUnionDiscriminator = "RequiredMember" 113 114 // OptionalMember represents an optional union member. 115 OptionalMember CELUnionDiscriminator = "OptionalMember" 116 117 // EmptyMember represents an empty union member. 118 EmptyMember CELUnionDiscriminator = "EmptyMember" 119 ) 120 121 // StableConfigTypeStatus defines the observed status of the StableConfigType. 122 type StableConfigTypeStatus struct { 123 // Represents the observations of a foo's current state. 124 // Known .status.conditions.type are: "Available", "Progressing", and "Degraded" 125 // +patchMergeKey=type 126 // +patchStrategy=merge 127 // +listType=map 128 // +listMapKey=type 129 Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` 130 131 // immutableField is a field that is immutable once the object has been created. 132 // It is required at all times. 133 // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="immutableField is immutable" 134 // +optional 135 ImmutableField string `json:"immutableField,omitempty"` 136 } 137 138 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 139 // +kubebuilder:object:root=true 140 // +openshift:compatibility-gen:level=1 141 142 // StableConfigTypeList contains a list of StableConfigTypes. 143 // 144 // Compatibility level 1: Stable within a major release for a minimum of 12 months or 3 minor releases (whichever is longer). 145 // +openshift:compatibility-gen:level=1 146 type StableConfigTypeList struct { 147 metav1.TypeMeta `json:",inline"` 148 149 // metadata is the standard list's metadata. 150 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 151 metav1.ListMeta `json:"metadata,omitempty"` 152 153 Items []StableConfigType `json:"items"` 154 } 155