Skip to content

Commit afaecc6

Browse files
committed
fix review findings
Signed-off-by: sivchari <shibuuuu5@gmail.com>
1 parent b54722f commit afaecc6

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

exp/topology/desiredstate/desired_state.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ func getOwnerReferenceFrom(obj, owner client.Object) *metav1.OwnerReference {
16351635
return nil
16361636
}
16371637

1638-
func cleanupCluster(cluster *clusterv1beta1.Cluster) *clusterv1beta1.Cluster {
1638+
func cleanupV1Beta1Cluster(cluster *clusterv1beta1.Cluster) *clusterv1beta1.Cluster {
16391639
// Optimize size of Cluster by not sending status, the managedFields and some specific annotations.
16401640
cluster.SetManagedFields(nil)
16411641

@@ -1650,3 +1650,19 @@ func cleanupCluster(cluster *clusterv1beta1.Cluster) *clusterv1beta1.Cluster {
16501650
cluster.Status = clusterv1beta1.ClusterStatus{}
16511651
return cluster
16521652
}
1653+
1654+
func cleanupCluster(cluster *clusterv1.Cluster) *clusterv1.Cluster {
1655+
// Optimize size of Cluster by not sending status, the managedFields and some specific annotations.
1656+
cluster.SetManagedFields(nil)
1657+
1658+
// The conversion that we run before calling cleanupCluster does not clone annotations
1659+
// So we have to do it here to not modify the original Cluster.
1660+
if cluster.Annotations != nil {
1661+
annotations := maps.Clone(cluster.Annotations)
1662+
delete(annotations, corev1.LastAppliedConfigAnnotation)
1663+
delete(annotations, conversion.DataAnnotation)
1664+
cluster.Annotations = annotations
1665+
}
1666+
cluster.Status = clusterv1.ClusterStatus{}
1667+
return cluster
1668+
}

exp/topology/desiredstate/lifecycle_hooks.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (g *generator) callBeforeClusterUpgradeHook(ctx context.Context, s *scope.S
7979
}
8080

8181
hookRequest := &runtimehooksv1.BeforeClusterUpgradeRequest{
82-
Cluster: *cleanupCluster(v1beta1Cluster),
82+
Cluster: *cleanupV1Beta1Cluster(v1beta1Cluster),
8383
FromKubernetesVersion: *currentVersion,
8484
ToKubernetesVersion: topologyVersion,
8585
ControlPlaneUpgrades: toUpgradeStep(s.UpgradeTracker.ControlPlane.UpgradePlan),
@@ -119,7 +119,7 @@ func (g *generator) callBeforeControlPlaneUpgradeHook(ctx context.Context, s *sc
119119
}
120120

121121
hookRequest := &runtimehooksv1.BeforeControlPlaneUpgradeRequest{
122-
Cluster: *cleanupCluster(v1beta1Cluster),
122+
Cluster: *cleanupV1Beta1Cluster(v1beta1Cluster),
123123
FromKubernetesVersion: *currentVersion,
124124
ToKubernetesVersion: nextVersion,
125125
ControlPlaneUpgrades: toUpgradeStep(s.UpgradeTracker.ControlPlane.UpgradePlan),
@@ -161,7 +161,7 @@ func (g *generator) callAfterControlPlaneUpgradeHook(ctx context.Context, s *sco
161161

162162
// Call all the registered extension for the hook.
163163
hookRequest := &runtimehooksv1.AfterControlPlaneUpgradeRequest{
164-
Cluster: *cleanupCluster(v1beta1Cluster),
164+
Cluster: *cleanupV1Beta1Cluster(v1beta1Cluster),
165165
KubernetesVersion: *currentVersion,
166166
ControlPlaneUpgrades: toUpgradeStep(s.UpgradeTracker.ControlPlane.UpgradePlan),
167167
WorkersUpgrades: toUpgradeStep(s.UpgradeTracker.MachineDeployments.UpgradePlan, s.UpgradeTracker.MachinePools.UpgradePlan),
@@ -204,7 +204,7 @@ func (g *generator) callBeforeWorkersUpgradeHook(ctx context.Context, s *scope.S
204204
}
205205

206206
hookRequest := &runtimehooksv1.BeforeWorkersUpgradeRequest{
207-
Cluster: *cleanupCluster(v1beta1Cluster),
207+
Cluster: *cleanupV1Beta1Cluster(v1beta1Cluster),
208208
FromKubernetesVersion: *currentVersion,
209209
ToKubernetesVersion: nextVersion,
210210
ControlPlaneUpgrades: toUpgradeStep(s.UpgradeTracker.ControlPlane.UpgradePlan),
@@ -251,7 +251,7 @@ func (g *generator) callAfterWorkersUpgradeHook(ctx context.Context, s *scope.Sc
251251

252252
// Call all the registered extension for the hook.
253253
hookRequest := &runtimehooksv1.AfterWorkersUpgradeRequest{
254-
Cluster: *cleanupCluster(v1beta1Cluster),
254+
Cluster: *cleanupV1Beta1Cluster(v1beta1Cluster),
255255
KubernetesVersion: *currentVersion,
256256
ControlPlaneUpgrades: toUpgradeStep(s.UpgradeTracker.ControlPlane.UpgradePlan),
257257
WorkersUpgrades: toUpgradeStep(s.UpgradeTracker.MachineDeployments.UpgradePlan, s.UpgradeTracker.MachinePools.UpgradePlan),

exp/topology/desiredstate/upgrade_plan.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func GetUpgradePlanFromExtension(runtimeClient runtimeclient.Client, cluster *cl
419419

420420
// Prepare the request.
421421
req := &runtimehooksv1.GenerateUpgradePlanRequest{
422-
Cluster: *cluster,
422+
Cluster: *cleanupCluster(cluster.DeepCopy()),
423423
FromControlPlaneKubernetesVersion: currentControlPlaneVersion,
424424
FromWorkersKubernetesVersion: currentMinWorkersVersion,
425425
ToKubernetesVersion: desiredVersion,
@@ -428,11 +428,7 @@ func GetUpgradePlanFromExtension(runtimeClient runtimeclient.Client, cluster *cl
428428
// Call the extension.
429429
resp := &runtimehooksv1.GenerateUpgradePlanResponse{}
430430
if err := runtimeClient.CallExtension(ctx, runtimehooksv1.GenerateUpgradePlan, cluster, extensionName, req, resp); err != nil {
431-
return nil, nil, errors.Wrapf(err, "failed to call GenerateUpgradePlan extension %q", extensionName)
432-
}
433-
434-
if resp.GetStatus() != runtimehooksv1.ResponseStatusSuccess {
435-
return nil, nil, errors.Errorf("GenerateUpgradePlan extension %q returned failure: %s", extensionName, resp.GetMessage())
431+
return nil, nil, errors.Wrap(err, "failed to get upgrade plan from extension")
436432
}
437433

438434
// Convert UpgradeStep to string slice.

exp/topology/desiredstate/upgrade_plan_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ func TestGetUpgradePlanFromExtension_Errors(t *testing.T) {
12061206
currentControlPlaneVersion: "v1.31.0",
12071207
currentMinWorkersVersion: "v1.31.0",
12081208
extensionError: errors.New("extension call error"),
1209-
wantErrMessage: "failed to call GenerateUpgradePlan extension \"test-extension\": extension call error",
1209+
wantErrMessage: "failed to get upgrade plan from extension: extension call error",
12101210
},
12111211
}
12121212

0 commit comments

Comments
 (0)