From c46573b78248df75573e18cf5a19358eea654fa6 Mon Sep 17 00:00:00 2001 From: Shyam Radhakrishnan Date: Tue, 17 Oct 2023 08:28:36 +0530 Subject: [PATCH] Add node pool status in machine pool status (#338) * Add node pool state in machine pool status --- ...tructure.cluster.x-k8s.io_ociclusters.yaml | 20 ++++++++++++---- ....cluster.x-k8s.io_ociclustertemplates.yaml | 23 +++++++++++++++---- ...e.cluster.x-k8s.io_ocimanagedclusters.yaml | 20 ++++++++++++---- ...r.x-k8s.io_ocimanagedclustertemplates.yaml | 23 +++++++++++++++---- ...uster.x-k8s.io_ocimanagedmachinepools.yaml | 4 ++++ ...uster.x-k8s.io_ocivirtualmachinepools.yaml | 4 ++++ .../v1beta1/ocimanagedmachinepool_types.go | 3 +++ .../v1beta1/ocivirtualmachinepool_types.go | 3 +++ exp/api/v1beta1/zz_generated.conversion.go | 4 ++++ .../v1beta2/ocimanagedmachinepool_types.go | 3 +++ .../v1beta2/ocivirtualmachinepool_types.go | 3 +++ .../ocimanaged_machinepool_controller.go | 2 ++ .../ocimanaged_machinepool_controller_test.go | 2 ++ .../ocivirtual_machinepool_controller.go | 3 +++ .../ocivirtual_machinepool_controller_test.go | 2 ++ 15 files changed, 103 insertions(+), 16 deletions(-) diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml index 657dde91..d724c9ff 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml @@ -1373,7 +1373,10 @@ spec: If the rule''s `destination` is the `cidrBlock` value for a Service (the rule is for traffic destined for a particular - `Service` through a service gateway).' + `Service` through a service gateway). + * `NETWORK_SECURITY_GROUP`: If the rule''s + `destination` is the OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string icmpOptions: description: 'IcmpOptions Optional and @@ -1605,7 +1608,10 @@ spec: If the rule''s `source` is the `cidrBlock` value for a Service (the rule is for traffic coming from a particular `Service` - through a service gateway).' + through a service gateway). * `NETWORK_SECURITY_GROUP`: + If the rule''s `destination` is the + OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string tcpOptions: description: TcpOptions Optional and valid @@ -1806,7 +1812,10 @@ spec: * `SERVICE_CIDR_BLOCK`: If the rule''s `destination` is the `cidrBlock` value for a Service (the rule is for traffic destined for a particular - `Service` through a service gateway).' + `Service` through a service gateway). * + `NETWORK_SECURITY_GROUP`: If the rule''s + `destination` is the OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string icmpOptions: description: 'IcmpOptions Optional and valid @@ -2018,7 +2027,10 @@ spec: If the rule''s `source` is the `cidrBlock` value for a Service (the rule is for traffic coming from a particular `Service` through - a service gateway).' + a service gateway). * `NETWORK_SECURITY_GROUP`: + If the rule''s `destination` is the OCID + (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string tcpOptions: description: TcpOptions Optional and valid diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml index 01a086cc..53742447 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml @@ -1439,7 +1439,11 @@ spec: is the `cidrBlock` value for a Service (the rule is for traffic destined for a particular `Service` - through a service gateway).' + through a service gateway). + * `NETWORK_SECURITY_GROUP`: + If the rule''s `destination` + is the OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string icmpOptions: description: 'IcmpOptions Optional @@ -1708,7 +1712,11 @@ spec: `cidrBlock` value for a Service (the rule is for traffic coming from a particular `Service` - through a service gateway).' + through a service gateway). + * `NETWORK_SECURITY_GROUP`: + If the rule''s `destination` + is the OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string tcpOptions: description: TcpOptions Optional @@ -1931,7 +1939,11 @@ spec: `destination` is the `cidrBlock` value for a Service (the rule is for traffic destined for a particular - `Service` through a service gateway).' + `Service` through a service gateway). + * `NETWORK_SECURITY_GROUP`: If the + rule''s `destination` is the OCID + (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string icmpOptions: description: 'IcmpOptions Optional @@ -2177,7 +2189,10 @@ spec: `source` is the `cidrBlock` value for a Service (the rule is for traffic coming from a particular `Service` - through a service gateway).' + through a service gateway). * `NETWORK_SECURITY_GROUP`: + If the rule''s `destination` is + the OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string tcpOptions: description: TcpOptions Optional and diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml index 462bc038..7dadbe65 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml @@ -1379,7 +1379,10 @@ spec: If the rule''s `destination` is the `cidrBlock` value for a Service (the rule is for traffic destined for a particular - `Service` through a service gateway).' + `Service` through a service gateway). + * `NETWORK_SECURITY_GROUP`: If the rule''s + `destination` is the OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string icmpOptions: description: 'IcmpOptions Optional and @@ -1611,7 +1614,10 @@ spec: If the rule''s `source` is the `cidrBlock` value for a Service (the rule is for traffic coming from a particular `Service` - through a service gateway).' + through a service gateway). * `NETWORK_SECURITY_GROUP`: + If the rule''s `destination` is the + OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string tcpOptions: description: TcpOptions Optional and valid @@ -1812,7 +1818,10 @@ spec: * `SERVICE_CIDR_BLOCK`: If the rule''s `destination` is the `cidrBlock` value for a Service (the rule is for traffic destined for a particular - `Service` through a service gateway).' + `Service` through a service gateway). * + `NETWORK_SECURITY_GROUP`: If the rule''s + `destination` is the OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string icmpOptions: description: 'IcmpOptions Optional and valid @@ -2024,7 +2033,10 @@ spec: If the rule''s `source` is the `cidrBlock` value for a Service (the rule is for traffic coming from a particular `Service` through - a service gateway).' + a service gateway). * `NETWORK_SECURITY_GROUP`: + If the rule''s `destination` is the OCID + (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string tcpOptions: description: TcpOptions Optional and valid diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml index 986436bd..c77e3b3b 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml @@ -1449,7 +1449,11 @@ spec: is the `cidrBlock` value for a Service (the rule is for traffic destined for a particular `Service` - through a service gateway).' + through a service gateway). + * `NETWORK_SECURITY_GROUP`: + If the rule''s `destination` + is the OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string icmpOptions: description: 'IcmpOptions Optional @@ -1718,7 +1722,11 @@ spec: `cidrBlock` value for a Service (the rule is for traffic coming from a particular `Service` - through a service gateway).' + through a service gateway). + * `NETWORK_SECURITY_GROUP`: + If the rule''s `destination` + is the OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string tcpOptions: description: TcpOptions Optional @@ -1941,7 +1949,11 @@ spec: `destination` is the `cidrBlock` value for a Service (the rule is for traffic destined for a particular - `Service` through a service gateway).' + `Service` through a service gateway). + * `NETWORK_SECURITY_GROUP`: If the + rule''s `destination` is the OCID + (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string icmpOptions: description: 'IcmpOptions Optional @@ -2187,7 +2199,10 @@ spec: `source` is the `cidrBlock` value for a Service (the rule is for traffic coming from a particular `Service` - through a service gateway).' + through a service gateway). * `NETWORK_SECURITY_GROUP`: + If the rule''s `destination` is + the OCID (https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) + of a NetworkSecurityGroup.' type: string tcpOptions: description: TcpOptions Optional and diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedmachinepools.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedmachinepools.yaml index 3d0960b8..19a84998 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedmachinepools.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedmachinepools.yaml @@ -268,6 +268,8 @@ spec: description: InfrastructureMachineKind is the kind of the infrastructure resources behind MachinePool Machines. type: string + nodepoolLifecycleState: + type: string ready: type: boolean replicas: @@ -556,6 +558,8 @@ spec: description: InfrastructureMachineKind is the kind of the infrastructure resources behind MachinePool Machines. type: string + nodepoolLifecycleState: + type: string ready: type: boolean replicas: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocivirtualmachinepools.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocivirtualmachinepools.yaml index 41f01a4f..d272ff29 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocivirtualmachinepools.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocivirtualmachinepools.yaml @@ -192,6 +192,8 @@ spec: description: InfrastructureMachineKind is the kind of the infrastructure resources behind MachinePool Machines. type: string + nodepoolLifecycleState: + type: string ready: type: boolean replicas: @@ -382,6 +384,8 @@ spec: description: InfrastructureMachineKind is the kind of the infrastructure resources behind MachinePool Machines. type: string + nodepoolLifecycleState: + type: string ready: type: boolean replicas: diff --git a/exp/api/v1beta1/ocimanagedmachinepool_types.go b/exp/api/v1beta1/ocimanagedmachinepool_types.go index 124675ef..820a0f36 100644 --- a/exp/api/v1beta1/ocimanagedmachinepool_types.go +++ b/exp/api/v1beta1/ocimanagedmachinepool_types.go @@ -193,6 +193,9 @@ type OCIManagedMachinePoolStatus struct { // +optional Conditions clusterv1.Conditions `json:"conditions,omitempty"` + // +optional + NodepoolLifecycleState string `json:"nodepoolLifecycleState,omitempty"` + // Replicas is the most recently observed number of replicas // +optional Replicas int32 `json:"replicas"` diff --git a/exp/api/v1beta1/ocivirtualmachinepool_types.go b/exp/api/v1beta1/ocivirtualmachinepool_types.go index f9417761..f245a5e6 100644 --- a/exp/api/v1beta1/ocivirtualmachinepool_types.go +++ b/exp/api/v1beta1/ocivirtualmachinepool_types.go @@ -106,6 +106,9 @@ type OCIVirtualMachinePoolStatus struct { // +optional Replicas int32 `json:"replicas"` + // +optional + NodepoolLifecycleState string `json:"nodepoolLifecycleState,omitempty"` + // FailureReason will contains the CAPI MachinePoolStatusFailure if the virtual machine pool has hit an error condition. // +optional FailureReason *errors.MachinePoolStatusFailure `json:"failureReason,omitempty"` diff --git a/exp/api/v1beta1/zz_generated.conversion.go b/exp/api/v1beta1/zz_generated.conversion.go index bdd646a2..a90381a7 100644 --- a/exp/api/v1beta1/zz_generated.conversion.go +++ b/exp/api/v1beta1/zz_generated.conversion.go @@ -1069,6 +1069,7 @@ func autoConvert_v1beta2_OCIManagedMachinePoolSpec_To_v1beta1_OCIManagedMachineP func autoConvert_v1beta1_OCIManagedMachinePoolStatus_To_v1beta2_OCIManagedMachinePoolStatus(in *OCIManagedMachinePoolStatus, out *v1beta2.OCIManagedMachinePoolStatus, s conversion.Scope) error { out.Ready = in.Ready out.Conditions = *(*clusterapiapiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) + out.NodepoolLifecycleState = in.NodepoolLifecycleState out.Replicas = in.Replicas out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessages = *(*[]string)(unsafe.Pointer(&in.FailureMessages)) @@ -1084,6 +1085,7 @@ func Convert_v1beta1_OCIManagedMachinePoolStatus_To_v1beta2_OCIManagedMachinePoo func autoConvert_v1beta2_OCIManagedMachinePoolStatus_To_v1beta1_OCIManagedMachinePoolStatus(in *v1beta2.OCIManagedMachinePoolStatus, out *OCIManagedMachinePoolStatus, s conversion.Scope) error { out.Ready = in.Ready out.Conditions = *(*clusterapiapiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) + out.NodepoolLifecycleState = in.NodepoolLifecycleState out.Replicas = in.Replicas out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessages = *(*[]string)(unsafe.Pointer(&in.FailureMessages)) @@ -1308,6 +1310,7 @@ func autoConvert_v1beta1_OCIVirtualMachinePoolStatus_To_v1beta2_OCIVirtualMachin out.Ready = in.Ready out.Conditions = *(*clusterapiapiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) out.Replicas = in.Replicas + out.NodepoolLifecycleState = in.NodepoolLifecycleState out.FailureReason = (*errors.MachinePoolStatusFailure)(unsafe.Pointer(in.FailureReason)) out.FailureMessages = *(*[]string)(unsafe.Pointer(&in.FailureMessages)) out.InfrastructureMachineKind = in.InfrastructureMachineKind @@ -1323,6 +1326,7 @@ func autoConvert_v1beta2_OCIVirtualMachinePoolStatus_To_v1beta1_OCIVirtualMachin out.Ready = in.Ready out.Conditions = *(*clusterapiapiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) out.Replicas = in.Replicas + out.NodepoolLifecycleState = in.NodepoolLifecycleState out.FailureReason = (*errors.MachinePoolStatusFailure)(unsafe.Pointer(in.FailureReason)) out.FailureMessages = *(*[]string)(unsafe.Pointer(&in.FailureMessages)) out.InfrastructureMachineKind = in.InfrastructureMachineKind diff --git a/exp/api/v1beta2/ocimanagedmachinepool_types.go b/exp/api/v1beta2/ocimanagedmachinepool_types.go index 5c57bd0f..033251c8 100644 --- a/exp/api/v1beta2/ocimanagedmachinepool_types.go +++ b/exp/api/v1beta2/ocimanagedmachinepool_types.go @@ -216,6 +216,9 @@ type OCIManagedMachinePoolStatus struct { // +optional Conditions clusterv1.Conditions `json:"conditions,omitempty"` + // +optional + NodepoolLifecycleState string `json:"nodepoolLifecycleState,omitempty"` + // Replicas is the most recently observed number of replicas // +optional Replicas int32 `json:"replicas"` diff --git a/exp/api/v1beta2/ocivirtualmachinepool_types.go b/exp/api/v1beta2/ocivirtualmachinepool_types.go index b5c25c32..747b0fa0 100644 --- a/exp/api/v1beta2/ocivirtualmachinepool_types.go +++ b/exp/api/v1beta2/ocivirtualmachinepool_types.go @@ -106,6 +106,9 @@ type OCIVirtualMachinePoolStatus struct { // +optional Replicas int32 `json:"replicas"` + // +optional + NodepoolLifecycleState string `json:"nodepoolLifecycleState,omitempty"` + // FailureReason will contains the CAPI MachinePoolStatusFailure if the virtual machine pool has hit an error condition. // +optional FailureReason *errors.MachinePoolStatusFailure `json:"failureReason,omitempty"` diff --git a/exp/controllers/ocimanaged_machinepool_controller.go b/exp/controllers/ocimanaged_machinepool_controller.go index bf37a947..8a97018a 100644 --- a/exp/controllers/ocimanaged_machinepool_controller.go +++ b/exp/controllers/ocimanaged_machinepool_controller.go @@ -300,6 +300,7 @@ func (r *OCIManagedMachinePoolReconciler) reconcileNormal(ctx context.Context, l machinePoolScope.OCIManagedMachinePool.Status.FailureMessages = failureMessages } + machinePoolScope.OCIManagedMachinePool.Status.NodepoolLifecycleState = fmt.Sprintf("%s", nodePool.LifecycleState) switch nodePool.LifecycleState { case oke.NodePoolLifecycleStateCreating: machinePoolScope.Info("Node Pool is creating") @@ -430,6 +431,7 @@ func (r *OCIManagedMachinePoolReconciler) reconcileDelete(ctx context.Context, m } machinePoolScope.Info(fmt.Sprintf("Node Pool lifecycle state is %v", nodePool.LifecycleState)) + machinePoolScope.OCIManagedMachinePool.Status.NodepoolLifecycleState = fmt.Sprintf("%s", nodePool.LifecycleState) switch nodePool.LifecycleState { case oke.NodePoolLifecycleStateDeleting: // Node Pool is already deleting diff --git a/exp/controllers/ocimanaged_machinepool_controller_test.go b/exp/controllers/ocimanaged_machinepool_controller_test.go index 85de3534..58d0995b 100644 --- a/exp/controllers/ocimanaged_machinepool_controller_test.go +++ b/exp/controllers/ocimanaged_machinepool_controller_test.go @@ -318,6 +318,8 @@ func TestNormalReconciliationFunction(t *testing.T) { g.Expect(*createMachine.Spec.ProviderID).To(Equal("id-1")) g.Expect(*createMachine.Spec.OCID).To(Equal("id-1")) + g.Expect(ms.OCIManagedMachinePool.Status.NodepoolLifecycleState).To(Equal("CREATING")) + g.Expect(len(t.deletePoolMachines)).To(Equal(1)) deleteMachine := t.deletePoolMachines[0] g.Expect(deleteMachine.Name).To(Equal("test")) diff --git a/exp/controllers/ocivirtual_machinepool_controller.go b/exp/controllers/ocivirtual_machinepool_controller.go index cf0c61a2..ac04a260 100644 --- a/exp/controllers/ocivirtual_machinepool_controller.go +++ b/exp/controllers/ocivirtual_machinepool_controller.go @@ -289,6 +289,8 @@ func (r *OCIVirtualMachinePoolReconciler) reconcileNormal(ctx context.Context, l machinePoolScope.OCIVirtualMachinePool.Spec.ProviderID = common.String(fmt.Sprintf("oci://%s", *nodePool.Id)) machinePoolScope.OCIVirtualMachinePool.Spec.ID = nodePool.Id + machinePoolScope.OCIVirtualMachinePool.Status.NodepoolLifecycleState = fmt.Sprintf("%s", nodePool.LifecycleState) + switch nodePool.LifecycleState { case oke.VirtualNodePoolLifecycleStateCreating: machinePoolScope.Info("Node Pool is creating") @@ -366,6 +368,7 @@ func (r *OCIVirtualMachinePoolReconciler) reconcileDelete(ctx context.Context, m return reconcile.Result{}, nil } + machinePoolScope.OCIVirtualMachinePool.Status.NodepoolLifecycleState = fmt.Sprintf("%s", nodePool.LifecycleState) machinePoolScope.Info(fmt.Sprintf("Node Pool lifecycle state is %v", nodePool.LifecycleState)) switch nodePool.LifecycleState { case oke.VirtualNodePoolLifecycleStateDeleting: diff --git a/exp/controllers/ocivirtual_machinepool_controller_test.go b/exp/controllers/ocivirtual_machinepool_controller_test.go index 943fc608..03bbd6aa 100644 --- a/exp/controllers/ocivirtual_machinepool_controller_test.go +++ b/exp/controllers/ocivirtual_machinepool_controller_test.go @@ -319,6 +319,8 @@ func TestNormalReconciliationFunctionForVirtualMP(t *testing.T) { g.Expect(*machine.Spec.InstanceName).To(Equal("name-1")) g.Expect(*machine.Spec.ProviderID).To(Equal("id-1")) g.Expect(*machine.Spec.OCID).To(Equal("id-1")) + + g.Expect(ms.OCIVirtualMachinePool.Status.NodepoolLifecycleState).To(Equal("ACTIVE")) }, }, {