Skip to content

Commit

Permalink
feat: persist NodeCount property of k8s Node Pool on AtProvider Status (
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadzhiyski authored Nov 11, 2024
1 parent df413b0 commit 72d581c
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 8 deletions.
1 change: 1 addition & 0 deletions apis/k8s/v1alpha1/nodepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ type NodePoolObservation struct {
PublicIPs []string `json:"publicIps,omitempty"`
AvailableUpgradeVersions []string `json:"availableUpgradeVersions,omitempty"`
CPUFamily string `json:"cpuFamily,omitempty"`
NodeCount *int32 `json:"nodeCount,omitempty"`
}

// A NodePoolSpec defines the desired state of a NodePool.
Expand Down
5 changes: 5 additions & 0 deletions apis/k8s/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion internal/clients/k8s/k8snodepool/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func LateInitializer(in *v1alpha1.NodePoolParameters, sg *sdkgo.KubernetesNodePo

// LateStatusInitializer fills the empty fields in *v1alpha1.ClusterObservation with
// the values seen in sdkgo.KubernetesCluster.
func LateStatusInitializer(in *v1alpha1.NodePoolObservation, sg *sdkgo.KubernetesNodePool) {
func LateStatusInitializer(in *v1alpha1.NodePoolObservation, sg *sdkgo.KubernetesNodePool) { // nolint:gocyclo
if sg == nil {
return
}
Expand All @@ -259,6 +259,10 @@ func LateStatusInitializer(in *v1alpha1.NodePoolObservation, sg *sdkgo.Kubernete
if cpuFamilyOk, ok := propertiesOk.GetCpuFamilyOk(); ok && cpuFamilyOk != nil {
in.CPUFamily = *cpuFamilyOk
}

if nodeCountOK, ok := propertiesOk.GetNodeCountOk(); ok {
in.NodeCount = nodeCountOK
}
}

}
Expand Down
67 changes: 67 additions & 0 deletions internal/clients/k8s/k8snodepool/nodepool_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package k8snodepool

import (
"slices"
"testing"

ionoscloud "github.com/ionos-cloud/sdk-go/v6"
Expand Down Expand Up @@ -200,3 +201,69 @@ func TestIsNodePoolUpToDate(t *testing.T) {
})
}
}

func TestLateStatusInitializer(t *testing.T) {
cr := &v1alpha1.NodePool{
Spec: v1alpha1.NodePoolSpec{
ForProvider: v1alpha1.NodePoolParameters{
Name: "not empty",
K8sVersion: "v1.22.33",
NodeCount: 4,
CPUFamily: "super fast",
CoresCount: 5,
RAMSize: 6,
AvailabilityZone: "AUTO",
StorageType: "SSD",
StorageSize: 7,
MaintenanceWindow: v1alpha1.MaintenanceWindow{
Time: "15:24:30Z",
DayOfTheWeek: "Mon",
},
},
},
Status: v1alpha1.NodePoolStatus{
AtProvider: v1alpha1.NodePoolObservation{},
},
}

nodePool := ionoscloud.KubernetesNodePool{Properties: &ionoscloud.KubernetesNodePoolProperties{
Name: ionoscloud.PtrString("not empty"),
DatacenterId: ionoscloud.PtrString("my-dc"),
NodeCount: ionoscloud.PtrInt32(4),
CpuFamily: ionoscloud.PtrString("super fast"),
CoresCount: ionoscloud.PtrInt32(5),
RamSize: ionoscloud.PtrInt32(6),
AvailabilityZone: ionoscloud.PtrString("AUTO"),
StorageType: ionoscloud.PtrString("SSD"),
StorageSize: ionoscloud.PtrInt32(7),
K8sVersion: ionoscloud.PtrString("v1.22.33"),
MaintenanceWindow: &ionoscloud.KubernetesMaintenanceWindow{
DayOfTheWeek: ionoscloud.PtrString("Fri"),
Time: ionoscloud.PtrString("03:24:30Z"),
},
AutoScaling: nil,
Lans: nil,
Labels: nil,
Annotations: nil,
PublicIps: &[]string{"172.10.1.1"},
AvailableUpgradeVersions: &[]string{"v1.22.33", "v1.22.34"},
}}

LateStatusInitializer(&cr.Status.AtProvider, &nodePool)

if *cr.Status.AtProvider.NodeCount != *nodePool.Properties.NodeCount {
t.Errorf("NodeCount not equal")
}

if cr.Status.AtProvider.CPUFamily != *nodePool.Properties.CpuFamily {
t.Errorf("CPU Family not equal")
}

if !slices.Equal(cr.Status.AtProvider.AvailableUpgradeVersions, *nodePool.Properties.AvailableUpgradeVersions) {
t.Errorf("AvailableUpgradeVersions not equal")
}

if !slices.Equal(cr.Status.AtProvider.PublicIPs, *nodePool.Properties.PublicIps) {
t.Errorf("PublicIPs not equal")
}
}
9 changes: 5 additions & 4 deletions package/crds/compute.ionoscloud.crossplane.io_s3keys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ spec:
UserID
properties:
active:
description: Whether the IONOS Object Storage is active / enabled or not. Can only
be updated to false, by default the key will be created as active.
Default value is true.
description: Whether the IONOS Object Storage is active / enabled
or not. Can only be updated to false, by default the key will
be created as active. Default value is true.
type: boolean
userID:
description: The UUID of the user owning the IONOS Object Storage Key.
description: The UUID of the user owning the IONOS Object Storage
Key.
type: string
required:
- userID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ spec:
Synchronization Mode.
properties:
backupLocation:
description: The IONOS Object Storage location where the backups will be stored.
description: The IONOS Object Storage location where the backups
will be stored.
enum:
- de
- eu-south-2
Expand Down
4 changes: 2 additions & 2 deletions package/crds/k8s.ionoscloud.crossplane.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ spec:
type: string
s3Buckets:
description: |-
List of IONOS Object Storage bucket configured for K8s usage.
List of IONOS Object Storage buckets configured for K8s usage.
For now, it contains only an IONOS Object Storage bucket used to store K8s API audit logs.
items:
description: IONOS Object Storage bucket configured for K8s usage.
description: S3Bucket configured for K8s usage.
properties:
name:
type: string
Expand Down
3 changes: 3 additions & 0 deletions package/crds/k8s.ionoscloud.crossplane.io_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,9 @@ spec:
type: array
cpuFamily:
type: string
nodeCount:
format: int32
type: integer
nodePoolId:
type: string
publicIps:
Expand Down

0 comments on commit 72d581c

Please sign in to comment.