diff --git a/cmd/kops/integration_test.go b/cmd/kops/integration_test.go index cd3cb152eeed5..a410cf723f426 100644 --- a/cmd/kops/integration_test.go +++ b/cmd/kops/integration_test.go @@ -22,6 +22,7 @@ import ( "crypto/rand" "crypto/rsa" "crypto/x509" + "encoding/json" "encoding/pem" "fmt" "os" @@ -1203,10 +1204,19 @@ func (i *integrationTest) runTest(t *testing.T, ctx context.Context, h *testutil options.ClusterName = i.clusterName options.LifecycleOverrides = i.lifecycleOverrides - _, err := RunUpdateCluster(ctx, factory, &stdout, options) + updateClusterResults, err := RunUpdateCluster(ctx, factory, &stdout, options) if err != nil { t.Fatalf("error running update cluster %q: %v", i.clusterName, err) } + + // Verify that we can print all the tasks + // Catches bugs like https://github.com/kubernetes/kops/issues/17316 + for key, task := range updateClusterResults.TaskMap { + if _, err := json.Marshal(task); err != nil { + t.Errorf("unable to marshal task %q of type %T to json: %v", key, task, err) + } + } + } // Compare main files diff --git a/pkg/model/awsmodel/autoscalinggroup.go b/pkg/model/awsmodel/autoscalinggroup.go index 4b0f123ae1159..154343c38a8b7 100644 --- a/pkg/model/awsmodel/autoscalinggroup.go +++ b/pkg/model/awsmodel/autoscalinggroup.go @@ -82,12 +82,12 @@ func (b *AutoscalingGroupModelBuilder) Build(c *fi.CloudupModelBuilderContext) e // @step: now lets build the autoscaling group task if ig.Spec.Manager != "Karpenter" { - tsk, err := b.buildAutoScalingGroupTask(c, name, ig) + asg, err := b.buildAutoScalingGroupTask(c, name, ig) if err != nil { return err } - tsk.LaunchTemplate = task - c.AddTask(tsk) + asg.LaunchTemplate = task + c.AddTask(asg) warmPool := b.Cluster.Spec.CloudProvider.AWS.WarmPool.ResolveDefaults(ig) @@ -103,9 +103,9 @@ func (b *AutoscalingGroupModelBuilder) Build(c *fi.CloudupModelBuilderContext) e if warmPool.MaxSize != nil { warmPoolTask.MaxSize = fi.PtrTo(int32(aws.ToInt64(warmPool.MaxSize))) } - tsk.WarmPool = warmPoolTask + asg.WarmPool = warmPoolTask } else { - tsk.WarmPool = nil + asg.WarmPool = nil } c.AddTask(warmPoolTask) diff --git a/upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go b/upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go index 6e3855c66e69a..31daa6e2dc503 100644 --- a/upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go +++ b/upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go @@ -100,8 +100,10 @@ type AutoscalingGroup struct { TargetGroups []*TargetGroup // CapacityRebalance makes ASG proactively replace spot instances when ASG receives a rebalance recommendation CapacityRebalance *bool - // WarmPool is the WarmPool config for the ASG - WarmPool *WarmPool + + // WarmPool is the WarmPool config for the ASG. + // It is marked to be ignored in JSON marshalling to avoid a circular dependency. + WarmPool *WarmPool `json:"-"` deletions []fi.CloudupDeletion } diff --git a/upup/pkg/fi/cloudup/awstasks/warmpool.go b/upup/pkg/fi/cloudup/awstasks/warmpool.go index 91f462f3d9a3c..234392722c5fb 100644 --- a/upup/pkg/fi/cloudup/awstasks/warmpool.go +++ b/upup/pkg/fi/cloudup/awstasks/warmpool.go @@ -41,6 +41,7 @@ type WarmPool struct { // MinSize is the smallest number of nodes in the warm pool. MinSize int32 + // AutoscalingGroup is the AutoscalingGroup on which we configure this warmpool. AutoscalingGroup *AutoscalingGroup }