|
| 1 | +/* |
| 2 | +Copyright 2024. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" |
| 22 | + "k8s.io/apimachinery/pkg/types" |
| 23 | +) |
| 24 | + |
| 25 | +const ( |
| 26 | + ClusterExtensionRevisionKind = "ClusterExtensionRevision" |
| 27 | + |
| 28 | + // Condition Types |
| 29 | + ClusterExtensionRevisionTypeAvailable = "Available" |
| 30 | + ClusterExtensionRevisionTypeSucceeded = "Succeeded" |
| 31 | + |
| 32 | + // Condition Reasons |
| 33 | + ClusterExtensionRevisionReasonAvailable = "Available" |
| 34 | + ClusterExtensionRevisionReasonReconcileFailure = "ReconcileFailure" |
| 35 | + ClusterExtensionRevisionReasonRevisionValidationFailure = "RevisionValidationFailure" |
| 36 | + ClusterExtensionRevisionReasonPhaseValidationError = "PhaseValidationError" |
| 37 | + ClusterExtensionRevisionReasonObjectCollisions = "ObjectCollisions" |
| 38 | + ClusterExtensionRevisionReasonRolloutSuccess = "RolloutSuccess" |
| 39 | + ClusterExtensionRevisionReasonProbeFailure = "ProbeFailure" |
| 40 | + ClusterExtensionRevisionReasonIncomplete = "Incomplete" |
| 41 | + ClusterExtensionRevisionReasonProgressing = "Progressing" |
| 42 | +) |
| 43 | + |
| 44 | +// ClusterExtensionRevisionSpec defines the desired state of ClusterExtensionRevision. |
| 45 | +type ClusterExtensionRevisionSpec struct { |
| 46 | + // Specifies the lifecycle state of the ClusterExtensionRevision. |
| 47 | + // |
| 48 | + // +kubebuilder:default="Active" |
| 49 | + // +kubebuilder:validation:Enum=Active;Paused;Archived |
| 50 | + // +kubebuilder:validation:XValidation:rule="oldSelf == 'Active' || oldSelf == 'Paused' || oldSelf == 'Archived' && oldSelf == self", message="can not un-archive" |
| 51 | + LifecycleState ClusterExtensionRevisionLifecycleState `json:"lifecycleState,omitempty"` |
| 52 | + // Revision number orders changes over time, must always be previous revision +1. |
| 53 | + // |
| 54 | + // +kubebuilder:validation:Required |
| 55 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf", message="revision is immutable" |
| 56 | + Revision int64 `json:"revision"` |
| 57 | + // Phases are groups of objects that will be applied at the same time. |
| 58 | + // All objects in the a phase will have to pass their probes in order to progress to the next phase. |
| 59 | + // |
| 60 | + // +kubebuilder:validation:Required |
| 61 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf || oldSelf.size() == 0", message="phases is immutable" |
| 62 | + // +patchMergeKey=name |
| 63 | + // +patchStrategy=merge |
| 64 | + // +listType=map |
| 65 | + // +listMapKey=name |
| 66 | + Phases []ClusterExtensionRevisionPhase `json:"phases"` |
| 67 | + // Previous references previous revisions that objects can be adopted from. |
| 68 | + // |
| 69 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf", message="previous is immutable" |
| 70 | + Previous []ClusterExtensionRevisionPrevious `json:"previous,omitempty"` |
| 71 | +} |
| 72 | + |
| 73 | +// ClusterExtensionRevisionLifecycleState specifies the lifecycle state of the ClusterExtensionRevision. |
| 74 | +type ClusterExtensionRevisionLifecycleState string |
| 75 | + |
| 76 | +const ( |
| 77 | + // ClusterExtensionRevisionLifecycleStateActive / "Active" is the default lifecycle state. |
| 78 | + ClusterExtensionRevisionLifecycleStateActive ClusterExtensionRevisionLifecycleState = "Active" |
| 79 | + // ClusterExtensionRevisionLifecycleStatePaused / "Paused" disables reconciliation of the ClusterExtensionRevision. |
| 80 | + // Only Status updates will still propagated, but object changes will not be reconciled. |
| 81 | + ClusterExtensionRevisionLifecycleStatePaused ClusterExtensionRevisionLifecycleState = "Paused" |
| 82 | + // ClusterExtensionRevisionLifecycleStateArchived / "Archived" disables reconciliation while also "scaling to zero", |
| 83 | + // which deletes all objects that are not excluded via the pausedFor property and |
| 84 | + // removes itself from the owner list of all other objects previously under management. |
| 85 | + ClusterExtensionRevisionLifecycleStateArchived ClusterExtensionRevisionLifecycleState = "Archived" |
| 86 | +) |
| 87 | + |
| 88 | +// ClusterExtensionRevisionPhase are groups of objects that will be applied at the same time. |
| 89 | +// All objects in the a phase will have to pass their probes in order to progress to the next phase. |
| 90 | +type ClusterExtensionRevisionPhase struct { |
| 91 | + // Name identifies this phase. |
| 92 | + // |
| 93 | + // +kubebuilder:validation:MaxLength=63 |
| 94 | + // +kubebuilder:validation:Pattern=`^[a-z]([-a-z0-9]*[a-z0-9])?$` |
| 95 | + Name string `json:"name"` |
| 96 | + // Objects are a list of all the objects within this phase. |
| 97 | + Objects []ClusterExtensionRevisionObject `json:"objects"` |
| 98 | +} |
| 99 | + |
| 100 | +// ClusterExtensionRevisionObject contains an object and settings for it. |
| 101 | +type ClusterExtensionRevisionObject struct { |
| 102 | + // +kubebuilder:validation:EmbeddedResource |
| 103 | + // +kubebuilder:pruning:PreserveUnknownFields |
| 104 | + Object unstructured.Unstructured `json:"object"` |
| 105 | + // CollisionProtection controls whether OLM can adopt and modify objects |
| 106 | + // already existing on the cluster or even owned by another controller. |
| 107 | + // |
| 108 | + // +kubebuilder:default="Prevent" |
| 109 | + CollisionProtection CollisionProtection `json:"collisionProtection,omitempty"` |
| 110 | +} |
| 111 | + |
| 112 | +// CollisionProtection specifies if and how ownership collisions are prevented. |
| 113 | +type CollisionProtection string |
| 114 | + |
| 115 | +const ( |
| 116 | + // CollisionProtectionPrevent prevents owner collisions entirely |
| 117 | + // by only allowing to work with objects itself has created. |
| 118 | + CollisionProtectionPrevent CollisionProtection = "Prevent" |
| 119 | + // CollisionProtectionIfNoController allows to patch and override |
| 120 | + // objects already present if they are not owned by another controller. |
| 121 | + CollisionProtectionIfNoController CollisionProtection = "IfNoController" |
| 122 | + // CollisionProtectionNone allows to patch and override objects |
| 123 | + // already present and owned by other controllers. |
| 124 | + // Be careful! This setting may cause multiple controllers to fight over a resource, |
| 125 | + // causing load on the API server and etcd. |
| 126 | + CollisionProtectionNone CollisionProtection = "None" |
| 127 | +) |
| 128 | + |
| 129 | +type ClusterExtensionRevisionPrevious struct { |
| 130 | + // +kubebuilder:validation:Required |
| 131 | + Name string `json:"name"` |
| 132 | + // +kubebuilder:validation:Required |
| 133 | + UID types.UID `json:"uid"` |
| 134 | +} |
| 135 | + |
| 136 | +// ClusterExtensionRevisionStatus defines the observed state of a ClusterExtensionRevision. |
| 137 | +type ClusterExtensionRevisionStatus struct { |
| 138 | + // +patchMergeKey=type |
| 139 | + // +patchStrategy=merge |
| 140 | + // +listType=map |
| 141 | + // +listMapKey=type |
| 142 | + // +optional |
| 143 | + Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` |
| 144 | +} |
| 145 | + |
| 146 | +// +kubebuilder:object:root=true |
| 147 | +// +kubebuilder:resource:scope=Cluster |
| 148 | +// +kubebuilder:subresource:status |
| 149 | + |
| 150 | +// ClusterExtensionRevision is the Schema for the clusterextensionrevisions API |
| 151 | +type ClusterExtensionRevision struct { |
| 152 | + metav1.TypeMeta `json:",inline"` |
| 153 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 154 | + |
| 155 | + // spec is an optional field that defines the desired state of the ClusterExtension. |
| 156 | + // +optional |
| 157 | + Spec ClusterExtensionRevisionSpec `json:"spec,omitempty"` |
| 158 | + |
| 159 | + // status is an optional field that defines the observed state of the ClusterExtension. |
| 160 | + // +optional |
| 161 | + Status ClusterExtensionRevisionStatus `json:"status,omitempty"` |
| 162 | +} |
| 163 | + |
| 164 | +// +kubebuilder:object:root=true |
| 165 | + |
| 166 | +// ClusterExtensionRevisionList contains a list of ClusterExtensionRevision |
| 167 | +type ClusterExtensionRevisionList struct { |
| 168 | + metav1.TypeMeta `json:",inline"` |
| 169 | + |
| 170 | + // +optional |
| 171 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 172 | + |
| 173 | + // items is a required list of ClusterExtensionRevision objects. |
| 174 | + // |
| 175 | + // +kubebuilder:validation:Required |
| 176 | + Items []ClusterExtensionRevision `json:"items"` |
| 177 | +} |
| 178 | + |
| 179 | +func init() { |
| 180 | + SchemeBuilder.Register(&ClusterExtensionRevision{}, &ClusterExtensionRevisionList{}) |
| 181 | +} |
0 commit comments