@@ -14,7 +14,6 @@ import (
14
14
"github.com/go-logr/logr"
15
15
v1 "k8s.io/api/core/v1"
16
16
k8serrors "k8s.io/apimachinery/pkg/api/errors"
17
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18
17
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
19
18
"k8s.io/apimachinery/pkg/runtime/schema"
20
19
capa "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
@@ -588,40 +587,13 @@ func (r *KarpenterMachinePoolReconciler) createOrUpdateNodePool(ctx context.Cont
588
587
}
589
588
}
590
589
591
- requirements := []v1alpha1.NodeSelectorRequirementWithMinValues {}
592
- taints := []v1.Taint {}
593
- expireAfter := v1alpha1 .MustParseNillableDuration ("720h" )
594
- budgets := []v1alpha1.Budget {}
595
- consolidateAfter := v1alpha1 .MustParseNillableDuration ("0s" )
596
- consolidationPolicy := "WhenEmptyOrUnderutilized"
597
-
598
- if karpenterMachinePool .Spec .NodePool != nil {
599
- requirements = karpenterMachinePool .Spec .NodePool .Template .Spec .Requirements
600
- taints = karpenterMachinePool .Spec .NodePool .Template .Spec .Taints
601
- expireAfter = karpenterMachinePool .Spec .NodePool .Template .Spec .ExpireAfter
602
- budgets = karpenterMachinePool .Spec .NodePool .Disruption .Budgets
603
- consolidateAfter = karpenterMachinePool .Spec .NodePool .Disruption .ConsolidateAfter
604
- consolidationPolicy = string (karpenterMachinePool .Spec .NodePool .Disruption .ConsolidationPolicy )
605
- }
606
-
607
- terminationGracePeriod := metav1.Duration {}
608
- if karpenterMachinePool .Spec .NodePool != nil && karpenterMachinePool .Spec .NodePool .Template .Spec .TerminationGracePeriod != nil {
609
- terminationGracePeriod = * karpenterMachinePool .Spec .NodePool .Template .Spec .TerminationGracePeriod
610
- }
611
-
612
- weight := int32 (1 )
613
- if karpenterMachinePool .Spec .NodePool != nil && karpenterMachinePool .Spec .NodePool .Weight != nil {
614
- weight = * karpenterMachinePool .Spec .NodePool .Weight
615
- }
616
-
617
590
operation , err := controllerutil .CreateOrUpdate (ctx , workloadClusterClient , nodePool , func () error {
618
591
spec := map [string ]interface {}{
619
592
"template" : map [string ]interface {}{
620
593
"metadata" : map [string ]interface {}{
621
594
"labels" : labels ,
622
595
},
623
596
"spec" : map [string ]interface {}{
624
- "taints" : taints ,
625
597
"startupTaints" : []interface {}{
626
598
map [string ]interface {}{
627
599
"effect" : "NoExecute" ,
@@ -634,23 +606,39 @@ func (r *KarpenterMachinePoolReconciler) createOrUpdateNodePool(ctx context.Cont
634
606
"value" : "true" ,
635
607
},
636
608
},
637
- "requirements" : requirements ,
638
609
"nodeClassRef" : map [string ]interface {}{
639
610
"group" : "karpenter.k8s.aws" ,
640
611
"kind" : "EC2NodeClass" ,
641
612
"name" : karpenterMachinePool .Name ,
642
613
},
643
- "terminationGracePeriodSeconds" : terminationGracePeriod ,
644
- "expireAfter" : expireAfter ,
645
614
},
646
615
},
647
- "disruption" : map [string ]interface {}{
648
- "budgets" : budgets ,
649
- "consolidateAfter" : consolidateAfter ,
650
- "consolidationPolicy" : consolidationPolicy ,
651
- },
652
- "limits" : karpenterMachinePool .Spec .NodePool .Limits ,
653
- "weight" : weight ,
616
+ "disruption" : map [string ]interface {}{},
617
+ }
618
+
619
+ if karpenterMachinePool .Spec .NodePool != nil {
620
+ dis := spec ["disruption" ].(map [string ]interface {})
621
+ dis ["budgets" ] = karpenterMachinePool .Spec .NodePool .Disruption .Budgets
622
+ dis ["consolidateAfter" ] = karpenterMachinePool .Spec .NodePool .Disruption .ConsolidateAfter
623
+ dis ["consolidationPolicy" ] = karpenterMachinePool .Spec .NodePool .Disruption .ConsolidationPolicy
624
+
625
+ if karpenterMachinePool .Spec .NodePool .Limits != nil {
626
+ spec ["limits" ] = karpenterMachinePool .Spec .NodePool .Limits
627
+ }
628
+
629
+ if karpenterMachinePool .Spec .NodePool .Weight != nil {
630
+ spec ["weight" ] = * karpenterMachinePool .Spec .NodePool .Weight
631
+ }
632
+
633
+ tpl := spec ["template" ].(map [string ]interface {})["spec" ].(map [string ]interface {})
634
+
635
+ tpl ["taints" ] = karpenterMachinePool .Spec .NodePool .Template .Spec .Taints
636
+ tpl ["requirements" ] = karpenterMachinePool .Spec .NodePool .Template .Spec .Requirements
637
+ tpl ["expireAfter" ] = karpenterMachinePool .Spec .NodePool .Template .Spec .ExpireAfter
638
+
639
+ if karpenterMachinePool .Spec .NodePool .Template .Spec .TerminationGracePeriod != nil {
640
+ tpl ["terminationGracePeriodSeconds" ] = karpenterMachinePool .Spec .NodePool .Template .Spec .TerminationGracePeriod
641
+ }
654
642
}
655
643
656
644
nodePool .Object ["spec" ] = spec
0 commit comments