@@ -589,7 +589,7 @@ var _ = Describe("LaunchTemplates", func() {
589
589
Expect (string (userData )).To (ContainSubstring ("--max-pods=10" ))
590
590
})
591
591
It ("should specify --system-reserved when overriding system reserved values" , func () {
592
- newProvisioner : = test .Provisioner (test.ProvisionerOptions {
592
+ provisioner = test .Provisioner (test.ProvisionerOptions {
593
593
Kubelet : & v1alpha5.KubeletConfiguration {
594
594
SystemReserved : v1.ResourceList {
595
595
v1 .ResourceCPU : resource .MustParse ("500m" ),
@@ -598,7 +598,7 @@ var _ = Describe("LaunchTemplates", func() {
598
598
},
599
599
},
600
600
})
601
- ExpectApplied (ctx , env .Client , newProvisioner )
601
+ ExpectApplied (ctx , env .Client , provisioner )
602
602
pod := ExpectProvisioned (ctx , env .Client , controller , test .UnschedulablePod ())[0 ]
603
603
ExpectScheduled (ctx , env .Client , pod )
604
604
Expect (fakeEC2API .CalledWithCreateLaunchTemplateInput .Len ()).To (Equal (1 ))
@@ -610,10 +610,92 @@ var _ = Describe("LaunchTemplates", func() {
610
610
i := strings .Index (string (userData ), arg )
611
611
rem := string (userData )[(i + len (arg )):]
612
612
i = strings .Index (rem , "'" )
613
- for k , v := range newProvisioner .Spec .KubeletConfiguration .SystemReserved {
613
+ for k , v := range provisioner .Spec .KubeletConfiguration .SystemReserved {
614
+ Expect (rem [:i ]).To (ContainSubstring (fmt .Sprintf ("%v=%v" , k .String (), v .String ())))
615
+ }
616
+ })
617
+ It ("should specify --kube-reserved when overriding system reserved values" , func () {
618
+ provisioner = test .Provisioner (test.ProvisionerOptions {
619
+ Kubelet : & v1alpha5.KubeletConfiguration {
620
+ KubeReserved : v1.ResourceList {
621
+ v1 .ResourceCPU : resource .MustParse ("500m" ),
622
+ v1 .ResourceMemory : resource .MustParse ("1Gi" ),
623
+ v1 .ResourceEphemeralStorage : resource .MustParse ("2Gi" ),
624
+ },
625
+ },
626
+ })
627
+ ExpectApplied (ctx , env .Client , provisioner )
628
+ pod := ExpectProvisioned (ctx , env .Client , controller , test .UnschedulablePod ())[0 ]
629
+ ExpectScheduled (ctx , env .Client , pod )
630
+ Expect (fakeEC2API .CalledWithCreateLaunchTemplateInput .Len ()).To (Equal (1 ))
631
+ input := fakeEC2API .CalledWithCreateLaunchTemplateInput .Pop ()
632
+ userData , _ := base64 .StdEncoding .DecodeString (* input .LaunchTemplateData .UserData )
633
+
634
+ // Check whether the arguments are there for --kube-reserved
635
+ arg := "--kube-reserved="
636
+ i := strings .Index (string (userData ), arg )
637
+ rem := string (userData )[(i + len (arg )):]
638
+ i = strings .Index (rem , "'" )
639
+ for k , v := range provisioner .Spec .KubeletConfiguration .KubeReserved {
614
640
Expect (rem [:i ]).To (ContainSubstring (fmt .Sprintf ("%v=%v" , k .String (), v .String ())))
615
641
}
616
642
})
643
+ It ("should pass eviction threshold hard values when specified" , func () {
644
+ provisioner = test .Provisioner (test.ProvisionerOptions {
645
+ Kubelet : & v1alpha5.KubeletConfiguration {
646
+ EvictionHard : map [string ]string {
647
+ "memory.available" : "10%" ,
648
+ "nodefs.available" : "15%" ,
649
+ "nodefs.inodesFree" : "5%" ,
650
+ },
651
+ },
652
+ })
653
+ ExpectApplied (ctx , env .Client , provisioner )
654
+ pod := ExpectProvisioned (ctx , env .Client , controller , test .UnschedulablePod ())[0 ]
655
+ ExpectScheduled (ctx , env .Client , pod )
656
+ Expect (fakeEC2API .CalledWithCreateLaunchTemplateInput .Len ()).To (Equal (1 ))
657
+ input := fakeEC2API .CalledWithCreateLaunchTemplateInput .Pop ()
658
+ userData , _ := base64 .StdEncoding .DecodeString (* input .LaunchTemplateData .UserData )
659
+
660
+ // Check whether the arguments are there for --kube-reserved
661
+ arg := "--eviction-hard="
662
+ i := strings .Index (string (userData ), arg )
663
+ rem := string (userData )[(i + len (arg )):]
664
+ i = strings .Index (rem , "'" )
665
+ for k , v := range provisioner .Spec .KubeletConfiguration .EvictionHard {
666
+ Expect (rem [:i ]).To (ContainSubstring (fmt .Sprintf ("%v<%v" , k , v )))
667
+ }
668
+ })
669
+ It ("should specify --pods-per-core" , func () {
670
+ provisioner = test .Provisioner (test.ProvisionerOptions {
671
+ Kubelet : & v1alpha5.KubeletConfiguration {
672
+ PodsPerCore : ptr .Int32 (2 ),
673
+ },
674
+ })
675
+ ExpectApplied (ctx , env .Client , provisioner )
676
+ pod := ExpectProvisioned (ctx , env .Client , controller , test .UnschedulablePod ())[0 ]
677
+ ExpectScheduled (ctx , env .Client , pod )
678
+ Expect (fakeEC2API .CalledWithCreateLaunchTemplateInput .Len ()).To (Equal (1 ))
679
+ input := fakeEC2API .CalledWithCreateLaunchTemplateInput .Pop ()
680
+ userData , _ := base64 .StdEncoding .DecodeString (* input .LaunchTemplateData .UserData )
681
+ Expect (string (userData )).To (ContainSubstring (fmt .Sprintf ("--pods-per-core=%d" , 2 )))
682
+ })
683
+ It ("should specify --pods-per-core with --max-pods enabled" , func () {
684
+ provisioner = test .Provisioner (test.ProvisionerOptions {
685
+ Kubelet : & v1alpha5.KubeletConfiguration {
686
+ PodsPerCore : ptr .Int32 (2 ),
687
+ MaxPods : ptr .Int32 (100 ),
688
+ },
689
+ })
690
+ ExpectApplied (ctx , env .Client , provisioner )
691
+ pod := ExpectProvisioned (ctx , env .Client , controller , test .UnschedulablePod ())[0 ]
692
+ ExpectScheduled (ctx , env .Client , pod )
693
+ Expect (fakeEC2API .CalledWithCreateLaunchTemplateInput .Len ()).To (Equal (1 ))
694
+ input := fakeEC2API .CalledWithCreateLaunchTemplateInput .Pop ()
695
+ userData , _ := base64 .StdEncoding .DecodeString (* input .LaunchTemplateData .UserData )
696
+ Expect (string (userData )).To (ContainSubstring (fmt .Sprintf ("--pods-per-core=%d" , 2 )))
697
+ Expect (string (userData )).To (ContainSubstring (fmt .Sprintf ("--max-pods=%d" , 100 )))
698
+ })
617
699
It ("should specify --container-runtime containerd by default" , func () {
618
700
ExpectApplied (ctx , env .Client , test .Provisioner (test.ProvisionerOptions {Provider : provider }))
619
701
pod := ExpectProvisioned (ctx , env .Client , controller , test .UnschedulablePod ())[0 ]
@@ -770,7 +852,7 @@ var _ = Describe("LaunchTemplates", func() {
770
852
AWS : * provider ,
771
853
})
772
854
ExpectApplied (ctx , env .Client , nodeTemplate )
773
- newProvisioner : = test .Provisioner (test.ProvisionerOptions {
855
+ provisioner = test .Provisioner (test.ProvisionerOptions {
774
856
ProviderRef : & v1alpha5.ProviderRef {
775
857
Name : nodeTemplate .Name ,
776
858
},
@@ -782,7 +864,7 @@ var _ = Describe("LaunchTemplates", func() {
782
864
},
783
865
},
784
866
})
785
- ExpectApplied (ctx , env .Client , newProvisioner )
867
+ ExpectApplied (ctx , env .Client , provisioner )
786
868
pod := ExpectProvisioned (ctx , env .Client , controller , test .UnschedulablePod ())[0 ]
787
869
ExpectScheduled (ctx , env .Client , pod )
788
870
Expect (fakeEC2API .CalledWithCreateLaunchTemplateInput .Len ()).To (Equal (1 ))
@@ -795,6 +877,70 @@ var _ = Describe("LaunchTemplates", func() {
795
877
Expect (config .Settings .Kubernetes .SystemReserved [v1 .ResourceMemory .String ()]).To (Equal ("3Gi" ))
796
878
Expect (config .Settings .Kubernetes .SystemReserved [v1 .ResourceEphemeralStorage .String ()]).To (Equal ("10Gi" ))
797
879
})
880
+ It ("should override kube reserved values in user data" , func () {
881
+ provider .AMIFamily = & awsv1alpha1 .AMIFamilyBottlerocket
882
+ nodeTemplate := test .AWSNodeTemplate (v1alpha1.AWSNodeTemplateSpec {
883
+ UserData : nil ,
884
+ AWS : * provider ,
885
+ })
886
+ ExpectApplied (ctx , env .Client , nodeTemplate )
887
+ provisioner = test .Provisioner (test.ProvisionerOptions {
888
+ ProviderRef : & v1alpha5.ProviderRef {
889
+ Name : nodeTemplate .Name ,
890
+ },
891
+ Kubelet : & v1alpha5.KubeletConfiguration {
892
+ KubeReserved : v1.ResourceList {
893
+ v1 .ResourceCPU : resource .MustParse ("2" ),
894
+ v1 .ResourceMemory : resource .MustParse ("3Gi" ),
895
+ v1 .ResourceEphemeralStorage : resource .MustParse ("10Gi" ),
896
+ },
897
+ },
898
+ })
899
+ ExpectApplied (ctx , env .Client , provisioner )
900
+ pod := ExpectProvisioned (ctx , env .Client , controller , test .UnschedulablePod ())[0 ]
901
+ ExpectScheduled (ctx , env .Client , pod )
902
+ Expect (fakeEC2API .CalledWithCreateLaunchTemplateInput .Len ()).To (Equal (1 ))
903
+ input := fakeEC2API .CalledWithCreateLaunchTemplateInput .Pop ()
904
+ userData , _ := base64 .StdEncoding .DecodeString (* input .LaunchTemplateData .UserData )
905
+ config := & bootstrap.BottlerocketConfig {}
906
+ Expect (config .UnmarshalTOML (userData )).To (Succeed ())
907
+ Expect (len (config .Settings .Kubernetes .KubeReserved )).To (Equal (3 ))
908
+ Expect (config .Settings .Kubernetes .KubeReserved [v1 .ResourceCPU .String ()]).To (Equal ("2" ))
909
+ Expect (config .Settings .Kubernetes .KubeReserved [v1 .ResourceMemory .String ()]).To (Equal ("3Gi" ))
910
+ Expect (config .Settings .Kubernetes .KubeReserved [v1 .ResourceEphemeralStorage .String ()]).To (Equal ("10Gi" ))
911
+ })
912
+ It ("should override kube reserved values in user data" , func () {
913
+ provider .AMIFamily = & awsv1alpha1 .AMIFamilyBottlerocket
914
+ nodeTemplate := test .AWSNodeTemplate (v1alpha1.AWSNodeTemplateSpec {
915
+ UserData : nil ,
916
+ AWS : * provider ,
917
+ })
918
+ ExpectApplied (ctx , env .Client , nodeTemplate )
919
+ provisioner = test .Provisioner (test.ProvisionerOptions {
920
+ ProviderRef : & v1alpha5.ProviderRef {
921
+ Name : nodeTemplate .Name ,
922
+ },
923
+ Kubelet : & v1alpha5.KubeletConfiguration {
924
+ EvictionHard : map [string ]string {
925
+ "memory.available" : "10%" ,
926
+ "nodefs.available" : "15%" ,
927
+ "nodefs.inodesFree" : "5%" ,
928
+ },
929
+ },
930
+ })
931
+ ExpectApplied (ctx , env .Client , provisioner )
932
+ pod := ExpectProvisioned (ctx , env .Client , controller , test .UnschedulablePod ())[0 ]
933
+ ExpectScheduled (ctx , env .Client , pod )
934
+ Expect (fakeEC2API .CalledWithCreateLaunchTemplateInput .Len ()).To (Equal (1 ))
935
+ input := fakeEC2API .CalledWithCreateLaunchTemplateInput .Pop ()
936
+ userData , _ := base64 .StdEncoding .DecodeString (* input .LaunchTemplateData .UserData )
937
+ config := & bootstrap.BottlerocketConfig {}
938
+ Expect (config .UnmarshalTOML (userData )).To (Succeed ())
939
+ Expect (len (config .Settings .Kubernetes .EvictionHard )).To (Equal (3 ))
940
+ Expect (config .Settings .Kubernetes .EvictionHard ["memory.available" ]).To (Equal ("10%" ))
941
+ Expect (config .Settings .Kubernetes .EvictionHard ["nodefs.available" ]).To (Equal ("15%" ))
942
+ Expect (config .Settings .Kubernetes .EvictionHard ["nodefs.inodesFree" ]).To (Equal ("5%" ))
943
+ })
798
944
It ("should specify max pods value when passing maxPods in configuration" , func () {
799
945
bottlerocketProvider := provider .DeepCopy ()
800
946
bottlerocketProvider .AMIFamily = & awsv1alpha1 .AMIFamilyBottlerocket
0 commit comments