@@ -14,7 +14,6 @@ import (
1414 "github.com/go-logr/logr"
1515 v1 "k8s.io/api/core/v1"
1616 k8serrors "k8s.io/apimachinery/pkg/api/errors"
17- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1817 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1918 "k8s.io/apimachinery/pkg/runtime/schema"
2019 capa "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
@@ -541,40 +540,13 @@ func (r *KarpenterMachinePoolReconciler) createOrUpdateNodePool(ctx context.Cont
541540 }
542541 }
543542
544- requirements := []v1alpha1.NodeSelectorRequirementWithMinValues {}
545- taints := []v1.Taint {}
546- expireAfter := v1alpha1 .MustParseNillableDuration ("720h" )
547- budgets := []v1alpha1.Budget {}
548- consolidateAfter := v1alpha1 .MustParseNillableDuration ("0s" )
549- consolidationPolicy := "WhenEmptyOrUnderutilized"
550-
551- if karpenterMachinePool .Spec .NodePool != nil {
552- requirements = karpenterMachinePool .Spec .NodePool .Template .Spec .Requirements
553- taints = karpenterMachinePool .Spec .NodePool .Template .Spec .Taints
554- expireAfter = karpenterMachinePool .Spec .NodePool .Template .Spec .ExpireAfter
555- budgets = karpenterMachinePool .Spec .NodePool .Disruption .Budgets
556- consolidateAfter = karpenterMachinePool .Spec .NodePool .Disruption .ConsolidateAfter
557- consolidationPolicy = string (karpenterMachinePool .Spec .NodePool .Disruption .ConsolidationPolicy )
558- }
559-
560- terminationGracePeriod := metav1.Duration {}
561- if karpenterMachinePool .Spec .NodePool != nil && karpenterMachinePool .Spec .NodePool .Template .Spec .TerminationGracePeriod != nil {
562- terminationGracePeriod = * karpenterMachinePool .Spec .NodePool .Template .Spec .TerminationGracePeriod
563- }
564-
565- weight := int32 (1 )
566- if karpenterMachinePool .Spec .NodePool != nil && karpenterMachinePool .Spec .NodePool .Weight != nil {
567- weight = * karpenterMachinePool .Spec .NodePool .Weight
568- }
569-
570543 operation , err := controllerutil .CreateOrUpdate (ctx , workloadClusterClient , nodePool , func () error {
571544 spec := map [string ]interface {}{
572545 "template" : map [string ]interface {}{
573546 "metadata" : map [string ]interface {}{
574547 "labels" : labels ,
575548 },
576549 "spec" : map [string ]interface {}{
577- "taints" : taints ,
578550 "startupTaints" : []interface {}{
579551 map [string ]interface {}{
580552 "effect" : "NoExecute" ,
@@ -587,23 +559,39 @@ func (r *KarpenterMachinePoolReconciler) createOrUpdateNodePool(ctx context.Cont
587559 "value" : "true" ,
588560 },
589561 },
590- "requirements" : requirements ,
591562 "nodeClassRef" : map [string ]interface {}{
592563 "group" : "karpenter.k8s.aws" ,
593564 "kind" : "EC2NodeClass" ,
594565 "name" : karpenterMachinePool .Name ,
595566 },
596- "terminationGracePeriodSeconds" : terminationGracePeriod ,
597- "expireAfter" : expireAfter ,
598567 },
599568 },
600- "disruption" : map [string ]interface {}{
601- "budgets" : budgets ,
602- "consolidateAfter" : consolidateAfter ,
603- "consolidationPolicy" : consolidationPolicy ,
604- },
605- "limits" : karpenterMachinePool .Spec .NodePool .Limits ,
606- "weight" : weight ,
569+ "disruption" : map [string ]interface {}{},
570+ }
571+
572+ if karpenterMachinePool .Spec .NodePool != nil {
573+ dis := spec ["disruption" ].(map [string ]interface {})
574+ dis ["budgets" ] = karpenterMachinePool .Spec .NodePool .Disruption .Budgets
575+ dis ["consolidateAfter" ] = karpenterMachinePool .Spec .NodePool .Disruption .ConsolidateAfter
576+ dis ["consolidationPolicy" ] = karpenterMachinePool .Spec .NodePool .Disruption .ConsolidationPolicy
577+
578+ if karpenterMachinePool .Spec .NodePool .Limits != nil {
579+ spec ["limits" ] = karpenterMachinePool .Spec .NodePool .Limits
580+ }
581+
582+ if karpenterMachinePool .Spec .NodePool .Weight != nil {
583+ spec ["weight" ] = * karpenterMachinePool .Spec .NodePool .Weight
584+ }
585+
586+ tpl := spec ["template" ].(map [string ]interface {})["spec" ].(map [string ]interface {})
587+
588+ tpl ["taints" ] = karpenterMachinePool .Spec .NodePool .Template .Spec .Taints
589+ tpl ["requirements" ] = karpenterMachinePool .Spec .NodePool .Template .Spec .Requirements
590+ tpl ["expireAfter" ] = karpenterMachinePool .Spec .NodePool .Template .Spec .ExpireAfter
591+
592+ if karpenterMachinePool .Spec .NodePool .Template .Spec .TerminationGracePeriod != nil {
593+ tpl ["terminationGracePeriodSeconds" ] = karpenterMachinePool .Spec .NodePool .Template .Spec .TerminationGracePeriod
594+ }
607595 }
608596
609597 nodePool .Object ["spec" ] = spec
0 commit comments