Skip to content

Commit

Permalink
feat: retrieve MaxPods configuration from Kops config
Browse files Browse the repository at this point in the history
  • Loading branch information
rafatio committed Sep 30, 2024
1 parent cf514d7 commit 9c4c31e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions controllers/controlplane/kopscontrolplane_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,7 @@ func TestPrepareCustomCloudResources(t *testing.T) {
description: "Should generate files based on template with one NodePool v1",
kopsClusterFunction: func(kopsCluster *kopsapi.Cluster) *kopsapi.Cluster {
kopsCluster.Spec.Kubelet = &kopsapi.KubeletConfigSpec{
MaxPods: helpers.Int32Ptr(60),
KubeReserved: map[string]string{
"cpu": "150m",
"memory": "150Mi",
Expand Down Expand Up @@ -2172,6 +2173,7 @@ func TestPrepareCustomCloudResources(t *testing.T) {
description: "Should generate files based on template with one NodePool V1 and one Provisioner",
kopsClusterFunction: func(kopsCluster *kopsapi.Cluster) *kopsapi.Cluster {
kopsCluster.Spec.Kubelet = &kopsapi.KubeletConfigSpec{
MaxPods: helpers.Int32Ptr(60),
KubeReserved: map[string]string{
"cpu": "150m",
"memory": "150Mi",
Expand Down
1 change: 1 addition & 0 deletions utils/karpenter_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func GetKubeletConfiguration(kubeletSpec *kopsapi.KubeletConfigSpec) *karpenterv
}

return &karpenterv1.KubeletConfiguration{
MaxPods: kubeletSpec.MaxPods,
SystemReserved: kubeletSpec.SystemReserved,
KubeReserved: kubeletSpec.KubeReserved,
}
Expand Down
28 changes: 27 additions & 1 deletion utils/karpenter_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ func TestCreateEC2NodeClassV1FromKopsLaunchTemplateInfo(t *testing.T) {
},
},
Spec: karpenterv1.EC2NodeClassSpec{
Kubelet: &karpenterv1.KubeletConfiguration{
MaxPods: helpers.Int32Ptr(60),
KubeReserved: map[string]string{
"cpu": "150m",
"memory": "150Mi",
"ephemeral-storage": "1Gi",
},
SystemReserved: map[string]string{
"cpu": "150m",
"memory": "200Mi",
"ephemeral-storage": "1Gi",
},
},
AMIFamily: &karpenterv1.AMIFamilyCustom,
AMISelectorTerms: []karpenterv1.AMISelectorTerm{
{
Expand Down Expand Up @@ -156,7 +169,6 @@ func TestCreateEC2NodeClassV1FromKopsLaunchTemplateInfo(t *testing.T) {
"kops.k8s.io/instancegroup": "test-machine-pool",
"KubernetesCluster": "test-cluster.test.k8s.cluster",
},
Kubelet: &karpenterv1.KubeletConfiguration{},
UserData: helpers.StringPtr("dummy content"),
},
},
Expand Down Expand Up @@ -185,6 +197,20 @@ func TestCreateEC2NodeClassV1FromKopsLaunchTemplateInfo(t *testing.T) {

kopsCluster := helpers.NewKopsCluster("test-cluster")

kopsCluster.Spec.Kubelet = &kopsapi.KubeletConfigSpec{
MaxPods: helpers.Int32Ptr(60),
KubeReserved: map[string]string{
"cpu": "150m",
"memory": "150Mi",
"ephemeral-storage": "1Gi",
},
SystemReserved: map[string]string{
"cpu": "150m",
"memory": "200Mi",
"ephemeral-storage": "1Gi",
},
}

kmp := helpers.NewKopsMachinePool("test-machine-pool", "default", "test-cluster")

terraformOutputDir := filepath.Join(os.TempDir(), kopsCluster.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ spec:
cpu: 150m
ephemeral-storage: 1Gi
memory: 150Mi
maxPods: 60
systemReserved:
cpu: 150m
ephemeral-storage: 1Gi
Expand Down

0 comments on commit 9c4c31e

Please sign in to comment.