Skip to content

Commit

Permalink
update Namespace instead of NSTemplateSet
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek committed Aug 4, 2023
1 parent 701b39c commit 7015649
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
9 changes: 6 additions & 3 deletions test/e2e/parallel/serviceaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ func TestDoNotOverrideServiceAccount(t *testing.T) {
})
require.NoError(t, err)

// drop the SpaceRoles annotation from the namespace to trigger the reconciliation
_, err = member.UpdateNSTemplateSet(t, mur.Name, func(nsTmplSet *v1alpha1.NSTemplateSet) {
delete(nsTmplSet.Annotations, v1alpha1.LastAppliedSpaceRolesAnnotationKey)
// Update the namespace annotations & labels to trigger the reconciliation
_, err = member.UpdateNamespace(t, mur.Name, func(ns *corev1.Namespace) {
// drop the last-applied-space-roles annotation, so we are sure that the content of the roles are re-applied
delete(ns.Annotations, v1alpha1.LastAppliedSpaceRolesAnnotationKey)
// change the tier name, so we are sure that the content of the tier template is re-applied
ns.Labels[v1alpha1.TierLabelKey] = "appstudio"
})
require.NoError(t, err)

Expand Down
22 changes: 11 additions & 11 deletions testsupport/wait/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -1252,25 +1252,25 @@ func (a *MemberAwaitility) UpdateIdlerSpec(t *testing.T, idler *toolchainv1alpha
return result, err
}

// UpdateNSTemplateSet tries to update the Spec of the given NSTemplateSet
// UpdateNamespace tries to update the Spec of the given Namespace
// If it fails with an error (for example if the object has been modified) then it retrieves the latest version and tries again
// Returns the updated NSTemplateSet
func (a *MemberAwaitility) UpdateNSTemplateSet(t *testing.T, spaceName string, modifyNSTemplateSet func(nsTmplSet *toolchainv1alpha1.NSTemplateSet)) (*toolchainv1alpha1.NSTemplateSet, error) {
var nsTmplSet *toolchainv1alpha1.NSTemplateSet
// Returns the updated Namespace
func (a *MemberAwaitility) UpdateNamespace(t *testing.T, nsName string, modifyNamespace func(ns *corev1.Namespace)) (*corev1.Namespace, error) {
var ns *corev1.Namespace
err := wait.Poll(a.RetryInterval, a.Timeout, func() (done bool, err error) {
freshNSTmplSet := &toolchainv1alpha1.NSTemplateSet{}
if err := a.Client.Get(context.TODO(), types.NamespacedName{Namespace: a.Namespace, Name: spaceName}, freshNSTmplSet); err != nil {
freshNs := &corev1.Namespace{}
if err := a.Client.Get(context.TODO(), types.NamespacedName{Namespace: a.Namespace, Name: nsName}, freshNs); err != nil {
return true, err
}
modifyNSTemplateSet(freshNSTmplSet)
if err := a.Client.Update(context.TODO(), freshNSTmplSet); err != nil {
t.Logf("error updating NSTemplateSet '%s': %s. Will retry again...", spaceName, err.Error())
modifyNamespace(freshNs)
if err := a.Client.Update(context.TODO(), freshNs); err != nil {
t.Logf("error updating Namespace '%s': %s. Will retry again...", nsName, err.Error())
return false, nil
}
nsTmplSet = freshNSTmplSet
ns = freshNs
return true, nil
})
return nsTmplSet, err
return ns, err
}

// UpdateServiceAccount tries to update the given ServiceAccount
Expand Down

0 comments on commit 7015649

Please sign in to comment.