From 4c5002bb74439e71a9ffbaf076b92f85f6c419f5 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Mon, 24 Mar 2025 16:35:22 -0400 Subject: [PATCH 1/2] Add field validation to existing field Add kubebuilder validation markers [1] to ClusterOrder type definitions. [1]: https://book.kubebuilder.io/reference/markers/crd-validation.html --- api/v1alpha1/clusterorder_types.go | 6 ++++++ .../bases/cloudkit.openshift.io_clusterorders.yaml | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/api/v1alpha1/clusterorder_types.go b/api/v1alpha1/clusterorder_types.go index 2124b921..6b7f2ac0 100644 --- a/api/v1alpha1/clusterorder_types.go +++ b/api/v1alpha1/clusterorder_types.go @@ -27,6 +27,9 @@ import ( // ClusterOrderSpec defines the desired state of ClusterOrder type ClusterOrderSpec struct { // TemplateID is the unique identigier of the cluster template to use when creating this cluster + // +kubebuilder:validation:Required + // +kubebuilder:validation:Type=string + // +kubebuilder:validation:Pattern=`^[a-z][-a-z0-9]*[a-z0-9]$` TemplateID string `json:"templateID,omitempty"` } @@ -73,6 +76,9 @@ const ( // ClusterOrderStatus defines the observed state of ClusterOrder type ClusterOrderStatus struct { // Phase provides a single-value overview of the state of the ClusterOrder + // +kubebuilder:validation:Required + // +kubebuilder:validation:Type=string + // +kubebuilder:validation:Enum=Unknown;Accepted;Progressing;Failed;Ready Phase ClusterOrderPhaseType `json:"phase,omitempty"` // Conditions holds an array of metav1.Condition that describe the state of the ClusterOrder diff --git a/config/crd/bases/cloudkit.openshift.io_clusterorders.yaml b/config/crd/bases/cloudkit.openshift.io_clusterorders.yaml index 060f50c4..ae973441 100644 --- a/config/crd/bases/cloudkit.openshift.io_clusterorders.yaml +++ b/config/crd/bases/cloudkit.openshift.io_clusterorders.yaml @@ -42,7 +42,10 @@ spec: templateID: description: TemplateID is the unique identigier of the cluster template to use when creating this cluster + pattern: ^[a-z][-a-z0-9]*[a-z0-9]$ type: string + required: + - templateID type: object status: description: ClusterOrderStatus defines the observed state of ClusterOrder @@ -108,7 +111,15 @@ spec: phase: description: Phase provides a single-value overview of the state of the ClusterOrder + enum: + - Unknown + - Accepted + - Progressing + - Failed + - Ready type: string + required: + - phase type: object type: object served: true From 727d1e7505db01d0ce82d9a9fbc108b88ddd26f7 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Tue, 25 Mar 2025 13:41:38 -0400 Subject: [PATCH 2/2] Add cluster reference to ClusterOrder.status Add a `clusterReference` field to ClusterOrder.status that records the namespace, cluster name, and service account name created by the controller in response to a ClusterOrder. --- api/v1alpha1/clusterorder_types.go | 18 +++++++++++++---- api/v1alpha1/zz_generated.deepcopy.go | 20 +++++++++++++++++++ .../cloudkit.openshift.io_clusterorders.yaml | 18 +++++++++++++++-- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/api/v1alpha1/clusterorder_types.go b/api/v1alpha1/clusterorder_types.go index 6b7f2ac0..2f10a376 100644 --- a/api/v1alpha1/clusterorder_types.go +++ b/api/v1alpha1/clusterorder_types.go @@ -66,23 +66,33 @@ const ( // ClusterOrderConditionControlPlaneAvailable means the cluster control plane is ready ClusterOrderConditionControlPlaneAvailable ClusterOrderConditionType = "ControlPlaneAvailable" - // ClusterOrderConditionNodePoolAvailable means the node pool has the correct number of nodes - ClusterOrderConditionNodePoolAvailable ClusterOrderConditionType = "NodePoolAvailable" - // ClusterOrderConditionAvailable means the cluster is available ClusterOrderConditionAvailable ClusterOrderConditionType = "Available" ) +// ClusterOrderClusterReferenceType contains a reference to the namespace created by this ClusterOrder +type ClusterOrderClusterReferenceType struct { + // Namespace that contains the HostedCluster resource + Namespace string `json:"namespace"` + HostedClusterName string `json:"hostedClusterName"` + ServiceAccountName string `json:"serviceAccountName"` +} + // ClusterOrderStatus defines the observed state of ClusterOrder type ClusterOrderStatus struct { // Phase provides a single-value overview of the state of the ClusterOrder - // +kubebuilder:validation:Required + // +kubebuilder:validation:Optional // +kubebuilder:validation:Type=string // +kubebuilder:validation:Enum=Unknown;Accepted;Progressing;Failed;Ready Phase ClusterOrderPhaseType `json:"phase,omitempty"` // Conditions holds an array of metav1.Condition that describe the state of the ClusterOrder + // +kubebuilder:validation:Optional Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` + + // Reference to the namespace that contains the HostedCluster resource + // +kubebuilder:validation:Optional + ClusterReference *ClusterOrderClusterReferenceType `json:"clusterReference,omitempty"` } // +kubebuilder:object:root=true diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 3af426dc..e64f81f9 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -52,6 +52,21 @@ func (in *ClusterOrder) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterOrderClusterReferenceType) DeepCopyInto(out *ClusterOrderClusterReferenceType) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterOrderClusterReferenceType. +func (in *ClusterOrderClusterReferenceType) DeepCopy() *ClusterOrderClusterReferenceType { + if in == nil { + return nil + } + out := new(ClusterOrderClusterReferenceType) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterOrderList) DeepCopyInto(out *ClusterOrderList) { *out = *in @@ -109,6 +124,11 @@ func (in *ClusterOrderStatus) DeepCopyInto(out *ClusterOrderStatus) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.ClusterReference != nil { + in, out := &in.ClusterReference, &out.ClusterReference + *out = new(ClusterOrderClusterReferenceType) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterOrderStatus. diff --git a/config/crd/bases/cloudkit.openshift.io_clusterorders.yaml b/config/crd/bases/cloudkit.openshift.io_clusterorders.yaml index ae973441..9b168c89 100644 --- a/config/crd/bases/cloudkit.openshift.io_clusterorders.yaml +++ b/config/crd/bases/cloudkit.openshift.io_clusterorders.yaml @@ -50,6 +50,22 @@ spec: status: description: ClusterOrderStatus defines the observed state of ClusterOrder properties: + clusterReference: + description: Reference to the namespace that contains the HostedCluster + resource + properties: + hostedClusterName: + type: string + namespace: + description: Namespace that contains the HostedCluster resource + type: string + serviceAccountName: + type: string + required: + - hostedClusterName + - namespace + - serviceAccountName + type: object conditions: description: Conditions holds an array of metav1.Condition that describe the state of the ClusterOrder @@ -118,8 +134,6 @@ spec: - Failed - Ready type: string - required: - - phase type: object type: object served: true