Skip to content

Commit

Permalink
clusterctl: Add public function to create new CRD migrator
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandr Demicev <alexandr.demicev@suse.com>
  • Loading branch information
alexander-demicev committed Feb 6, 2024
1 parent 6bbcfda commit 85c9fec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (cm *certManagerClient) migrateCRDs(ctx context.Context) error {
return err
}

return newCRDMigrator(c).Run(ctx, objs)
return NewCRDMigrator(c).Run(ctx, objs)
}

func (cm *certManagerClient) deleteObjs(ctx context.Context, objs []unstructured.Unstructured) error {
Expand Down
9 changes: 7 additions & 2 deletions cmd/clusterctl/client/cluster/crd_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ import (
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
)

// CRDMigrator interface defines methods for migrating CRs to the storage version of new CRDs.
type CRDMigrator interface {
Run(ctx context.Context, objs []unstructured.Unstructured) error
}

// crdMigrator migrates CRs to the storage version of new CRDs.
// This is necessary when the new CRD drops a version which
// was previously used as a storage version.
type crdMigrator struct {
Client client.Client
}

// newCRDMigrator creates a new CRD migrator.
func newCRDMigrator(client client.Client) *crdMigrator {
// NewCRDMigrator creates a new CRD migrator.
func NewCRDMigrator(client client.Client) CRDMigrator {
return &crdMigrator{
Client: client,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func (u *providerUpgrader) doUpgrade(ctx context.Context, upgradePlan *UpgradePl
return err
}

if err := newCRDMigrator(c).Run(ctx, components.Objs()); err != nil {
if err := NewCRDMigrator(c).Run(ctx, components.Objs()); err != nil {
return err
}
}
Expand Down

0 comments on commit 85c9fec

Please sign in to comment.