Skip to content

Commit

Permalink
clusterctl: don't run crd migration if storedVersions is equal to sto…
Browse files Browse the repository at this point in the history
…rageVersion
  • Loading branch information
chrischdi committed Apr 25, 2024
1 parent 3e4c196 commit baa5b6d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/crd_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (m *crdMigrator) run(ctx context.Context, newCRD *apiextensionsv1.CustomRes
currentStatusStoredVersions := sets.Set[string]{}.Insert(currentCRD.Status.StoredVersions...)
// If the new CRD still contains all current stored versions, nothing to do
// as no previous storage version will be dropped.
if servedVersions.HasAll(currentStatusStoredVersions.UnsortedList()...) {
if servedVersions.HasAll(currentStatusStoredVersions.UnsortedList()...) || (currentStatusStoredVersions.Len() == 1 && currentStatusStoredVersions.Has(currentStorageVersion)) {
log.V(2).Info("CRD migration check passed", "name", newCRD.Name)
return false, nil
}
Expand Down
22 changes: 22 additions & 0 deletions cmd/clusterctl/client/cluster/crd_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,28 @@ func Test_CRDMigrator(t *testing.T) {
},
wantIsMigrated: false,
},
{
name: "No-op if new CRD adds a new versions and unserves the old",
currentCRD: &apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
{Name: "v1alpha1", Storage: true, Served: true},
},
},
Status: apiextensionsv1.CustomResourceDefinitionStatus{StoredVersions: []string{"v1alpha1"}},
},
newCRD: &apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
{Name: "v1beta1", Storage: true, Served: true}, // v1beta1 is being added
{Name: "v1alpha1", Served: false}, // v1alpha1 still exists but is not served anymore
},
},
},
wantIsMigrated: false,
},
{
name: "Fails if new CRD drops current storage version",
currentCRD: &apiextensionsv1.CustomResourceDefinition{
Expand Down

0 comments on commit baa5b6d

Please sign in to comment.