Skip to content

Commit

Permalink
Merge pull request #1096 from ErikJiang/add_rls_label
Browse files Browse the repository at this point in the history
migrate old version localArtifactSet
  • Loading branch information
ErikJiang authored Jan 29, 2024
2 parents b5e248c + 3a27e0d commit 202bfcb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 13 additions & 0 deletions pkg/controllers/offlineversion/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ func (c *Controller) Reconcile(ctx context.Context, req controllerruntime.Reques
sprayRelease, ok := localartifactset.ObjectMeta.Labels[constants.KeySprayRelease]
if !ok {
klog.Warningf("No label %s found in %s", constants.KeySprayRelease, localartifactset.Name)

// Migrate old versions of LocalArtifactSet without a release version label.
sprayRelease = "master"
if localartifactset.ObjectMeta.Labels != nil {
localartifactset.ObjectMeta.Labels[constants.KeySprayRelease] = sprayRelease
} else {
localartifactset.ObjectMeta.Labels = map[string]string{constants.KeySprayRelease: sprayRelease}
}
_, err := c.LocalArtifactSetClientSet.KubeanV1alpha1().LocalArtifactSets().Update(context.Background(), localartifactset, metav1.UpdateOptions{})
if err != nil {
klog.Error(err)
return controllerruntime.Result{RequeueAfter: Loop}, nil
}
return controllerruntime.Result{}, nil
}

Expand Down
13 changes: 11 additions & 2 deletions pkg/controllers/offlineversion/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func TestReconcile(t *testing.T) {
want: true,
},
{
name: "ComponentsversionGlobal not exist",
name: "localArtifact missing release label",
args: func() bool {
controller := &Controller{
Client: newFakeClient(),
Expand All @@ -511,11 +511,20 @@ func TestReconcile(t *testing.T) {
},
}

manifest := &manifestv1alpha1.Manifest{
ObjectMeta: metav1.ObjectMeta{
Name: "manifest-master",
},
}
infomanifest.GetVersionedManifest().Op("add", manifest, nil)
controller.InfoManifestClientSet.KubeanV1alpha1().Manifests().Create(context.Background(), manifest, metav1.CreateOptions{})
controller.Client.Create(context.Background(), &offlineVersionData)
controller.LocalArtifactSetClientSet.KubeanV1alpha1().LocalArtifactSets().Create(context.Background(), &offlineVersionData, metav1.CreateOptions{})

result, _ := controller.Reconcile(context.Background(), controllerruntime.Request{NamespacedName: types.NamespacedName{Name: offlineVersionData.Name}})
return result.RequeueAfter == 0 && result.Requeue == false
localartifactset, _ := controller.LocalArtifactSetClientSet.KubeanV1alpha1().LocalArtifactSets().Get(context.Background(), offlineVersionData.Name, metav1.GetOptions{})
release, ok := localartifactset.ObjectMeta.Labels[constants.KeySprayRelease]
return ok == true && release == "master" && result.Requeue == false && result.RequeueAfter == 0
},
want: true,
},
Expand Down

0 comments on commit 202bfcb

Please sign in to comment.