@@ -3,6 +3,7 @@ package template
33import (
44 "fmt"
55 "reflect"
6+ "strings"
67 "testing"
78 "time"
89
@@ -439,3 +440,127 @@ func getKey(config *mcfgv1.ControllerConfig, t *testing.T) string {
439440 }
440441 return key
441442}
443+
444+ func TestKubeletAutoNodeSizingEnabled (t * testing.T ) {
445+ cc := newControllerConfig ("test-cluster" )
446+ ps := []byte (`{"dummy": "dummy"}` )
447+
448+ mcs , err := getMachineConfigsForControllerConfig (templateDir , cc , ps , nil )
449+ if err != nil {
450+ t .Fatal (err )
451+ }
452+
453+ // Find machine configs that should contain the auto-node-sizing file
454+ // The file should be in all role-based machine configs (master, worker)
455+ autoSizingFileFound := false
456+ for _ , mc := range mcs {
457+ ignCfg , err := ctrlcommon .ParseAndConvertConfig (mc .Spec .Config .Raw )
458+ if err != nil {
459+ t .Fatalf ("Failed to parse ignition config for %s: %v" , mc .Name , err )
460+ }
461+
462+ // Look for the auto-node-sizing file
463+ for _ , file := range ignCfg .Storage .Files {
464+ if file .Path == ctrlcommon .NodeSizingEnabledEnvPath {
465+ autoSizingFileFound = true
466+
467+ // Decode the file contents
468+ contents , err := ctrlcommon .DecodeIgnitionFileContents (file .Contents .Source , file .Contents .Compression )
469+ if err != nil {
470+ t .Fatalf ("Failed to decode auto-node-sizing file contents: %v" , err )
471+ }
472+
473+ contentsStr := string (contents )
474+
475+ // Verify NODE_SIZING_ENABLED based on node role
476+ // Master nodes should have NODE_SIZING_ENABLED=false
477+ // Other nodes (worker, etc.) should have NODE_SIZING_ENABLED=true
478+ isMasterNode := strings .Contains (mc .Name , "master" )
479+ if isMasterNode {
480+ if ! strings .Contains (contentsStr , "NODE_SIZING_ENABLED=false" ) {
481+ t .Errorf ("Expected NODE_SIZING_ENABLED=false in %s, got: %s" , mc .Name , contentsStr )
482+ }
483+ } else {
484+ if ! strings .Contains (contentsStr , "NODE_SIZING_ENABLED=true" ) {
485+ t .Errorf ("Expected NODE_SIZING_ENABLED=true in %s, got: %s" , mc .Name , contentsStr )
486+ }
487+ }
488+
489+ // Verify other expected values
490+ if ! strings .Contains (contentsStr , "SYSTEM_RESERVED_MEMORY=1Gi" ) {
491+ t .Errorf ("Expected SYSTEM_RESERVED_MEMORY=1Gi in %s, got: %s" , mc .Name , contentsStr )
492+ }
493+
494+ if ! strings .Contains (contentsStr , "SYSTEM_RESERVED_CPU=500m" ) {
495+ t .Errorf ("Expected SYSTEM_RESERVED_CPU=500m in %s, got: %s" , mc .Name , contentsStr )
496+ }
497+
498+ if ! strings .Contains (contentsStr , "SYSTEM_RESERVED_ES=1Gi" ) {
499+ t .Errorf ("Expected SYSTEM_RESERVED_ES=1Gi in %s, got: %s" , mc .Name , contentsStr )
500+ }
501+ }
502+ }
503+ }
504+
505+ if ! autoSizingFileFound {
506+ t .Errorf ("Expected to find %s file in at least one machine config" , ctrlcommon .NodeSizingEnabledEnvPath )
507+ }
508+ }
509+
510+ func TestKubeletAutoNodeSizingDisabledForHypershift (t * testing.T ) {
511+ cc := newControllerConfig ("test-cluster" )
512+ // Set ControlPlaneTopology to External to simulate Hypershift
513+ cc .Spec .Infra .Status .ControlPlaneTopology = configv1 .ExternalTopologyMode
514+ ps := []byte (`{"dummy": "dummy"}` )
515+
516+ mcs , err := getMachineConfigsForControllerConfig (templateDir , cc , ps , nil )
517+ if err != nil {
518+ t .Fatal (err )
519+ }
520+
521+ // Find machine configs that should contain the auto-node-sizing file
522+ autoSizingFileFound := false
523+ for _ , mc := range mcs {
524+ ignCfg , err := ctrlcommon .ParseAndConvertConfig (mc .Spec .Config .Raw )
525+ if err != nil {
526+ t .Fatalf ("Failed to parse ignition config for %s: %v" , mc .Name , err )
527+ }
528+
529+ // Look for the auto-node-sizing file
530+ for _ , file := range ignCfg .Storage .Files {
531+ if file .Path == ctrlcommon .NodeSizingEnabledEnvPath {
532+ autoSizingFileFound = true
533+
534+ // Decode the file contents
535+ contents , err := ctrlcommon .DecodeIgnitionFileContents (file .Contents .Source , file .Contents .Compression )
536+ if err != nil {
537+ t .Fatalf ("Failed to decode auto-node-sizing file contents: %v" , err )
538+ }
539+
540+ contentsStr := string (contents )
541+
542+ // Verify NODE_SIZING_ENABLED=false is present for Hypershift
543+ if ! strings .Contains (contentsStr , "NODE_SIZING_ENABLED=false" ) {
544+ t .Errorf ("Expected NODE_SIZING_ENABLED=false for Hypershift in %s, got: %s" , mc .Name , contentsStr )
545+ }
546+
547+ // Verify other expected values are still present
548+ if ! strings .Contains (contentsStr , "SYSTEM_RESERVED_MEMORY=1Gi" ) {
549+ t .Errorf ("Expected SYSTEM_RESERVED_MEMORY=1Gi in %s, got: %s" , mc .Name , contentsStr )
550+ }
551+
552+ if ! strings .Contains (contentsStr , "SYSTEM_RESERVED_CPU=500m" ) {
553+ t .Errorf ("Expected SYSTEM_RESERVED_CPU=500m in %s, got: %s" , mc .Name , contentsStr )
554+ }
555+
556+ if ! strings .Contains (contentsStr , "SYSTEM_RESERVED_ES=1Gi" ) {
557+ t .Errorf ("Expected SYSTEM_RESERVED_ES=1Gi in %s, got: %s" , mc .Name , contentsStr )
558+ }
559+ }
560+ }
561+ }
562+
563+ if ! autoSizingFileFound {
564+ t .Errorf ("Expected to find %s file in at least one machine config" , ctrlcommon .NodeSizingEnabledEnvPath )
565+ }
566+ }
0 commit comments