Skip to content

Commit 7013b82

Browse files
charlesgongclaude
andcommitted
Extract shared machinepool dance logic into pkg/infra
Move reusable infra machinepool functions (GetInfraMachinePool, CloneMachinePool, RunMachinePoolDance) into pkg/infra/ so both resize and change-ebs-volume-type commands reference the shared package instead of duplicating logic. Remove OptionsDefaults test per reviewer feedback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d8be074 commit 7013b82

File tree

6 files changed

+726
-824
lines changed

6 files changed

+726
-824
lines changed

cmd/cluster/changevolumetype.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
machinev1 "github.com/openshift/api/machine/v1"
1414
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
1515
hivev1 "github.com/openshift/hive/apis/hive/v1"
16-
"github.com/openshift/osdctl/cmd/cluster/resize"
1716
"github.com/openshift/osdctl/cmd/servicelog"
17+
infraPkg "github.com/openshift/osdctl/pkg/infra"
1818
"github.com/openshift/osdctl/pkg/k8s"
1919
"github.com/openshift/osdctl/pkg/printer"
2020
"github.com/openshift/osdctl/pkg/utils"
@@ -399,17 +399,20 @@ const (
399399
volumeTypeChangedServiceLogTemplate = "https://raw.githubusercontent.com/openshift/managed-notifications/master/osd/infranode_volume_type_changed.json"
400400
)
401401

402-
// changeInfraVolumeType uses the Hive MachinePool dance from the resize package
402+
// changeInfraVolumeType uses the Hive MachinePool dance from pkg/infra
403403
// to replace infra nodes with new ones using the target volume type.
404404
func (o *changeVolumeTypeOptions) changeInfraVolumeType(ctx context.Context) error {
405405
printer.PrintlnGreen("\n=== Changing infra node volume type ===")
406406

407407
targetType := o.targetType
408408
previousType := ""
409409

410-
infraReplacer := resize.NewInfraFromClients(o.cluster, o.client, o.hiveClient, o.hiveAdminClient, o.reason)
411-
infraReplacer.SkipServiceLog = true
412-
infraReplacer.MachinePoolModifier = func(mp *hivev1.MachinePool) error {
410+
originalMp, err := infraPkg.GetInfraMachinePool(ctx, o.hiveClient, o.clusterID)
411+
if err != nil {
412+
return err
413+
}
414+
415+
newMp, err := infraPkg.CloneMachinePool(originalMp, func(mp *hivev1.MachinePool) error {
413416
if mp.Spec.Platform.AWS == nil {
414417
return fmt.Errorf("infra MachinePool has no AWS platform configuration")
415418
}
@@ -422,9 +425,18 @@ func (o *changeVolumeTypeOptions) changeInfraVolumeType(ctx context.Context) err
422425
mp.Spec.Platform.AWS.Type = targetType
423426
mp.Spec.Platform.AWS.IOPS = 0
424427
return nil
428+
})
429+
if err != nil {
430+
return err
431+
}
432+
433+
clients := infraPkg.DanceClients{
434+
ClusterClient: o.client,
435+
HiveClient: o.hiveClient,
436+
HiveAdmin: o.hiveAdminClient,
425437
}
426438

427-
if err := infraReplacer.RunMachinePoolDance(ctx); err != nil {
439+
if err := infraPkg.RunMachinePoolDance(ctx, clients, originalMp, newMp, nil); err != nil {
428440
return err
429441
}
430442

cmd/cluster/changevolumetype_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,3 @@ func TestChangeVolumeType_CountReadyNodes(t *testing.T) {
118118
nodes := &corev1.NodeList{}
119119
assert.Equal(t, 0, countReadyNodes(nodes))
120120
}
121-
122-
func TestChangeVolumeType_OptionsDefaults(t *testing.T) {
123-
ops := &changeVolumeTypeOptions{}
124-
125-
assert.Empty(t, ops.clusterID)
126-
assert.Empty(t, ops.targetType)
127-
assert.Empty(t, ops.role)
128-
assert.Empty(t, ops.reason)
129-
assert.Nil(t, ops.client)
130-
assert.Nil(t, ops.clientAdmin)
131-
assert.Nil(t, ops.hiveClient)
132-
assert.Nil(t, ops.hiveAdminClient)
133-
assert.Nil(t, ops.cluster)
134-
}

0 commit comments

Comments
 (0)