Skip to content

Commit a2dc962

Browse files
authored
remove deletion of console setting resources using label (codeready-toolchain#621)
1 parent 2833957 commit a2dc962

File tree

3 files changed

+3
-92
lines changed

3 files changed

+3
-92
lines changed

controllers/useraccount/console_usersettings.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const (
1616
)
1717

1818
// deleteResource deletes the specified resource associated with a user from console setting.
19-
// It first attempts to delete the resource by name, and if not found, it deletes all resources with matching labels.
19+
// It attempts to delete the resource by name, and does nothing if not found.
2020
//
2121
// userUID : The unique identifier of the user for whom the resource is being deleted.
2222
// Returns an error if the deletion operation fails. Returns nil if the operation is successful or there is nothing to delete.
@@ -32,10 +32,7 @@ func deleteResource(ctx context.Context, cl client.Client, userUID string, toDel
3232
toDelete.SetName(name)
3333
toDelete.SetNamespace(UserSettingNS)
3434
if err := cl.Delete(ctx, toDelete); err != nil {
35-
if errors.IsNotFound(err) {
36-
labels := map[string]string{ConsoleUserSettingsIdentifier: "true", ConsoleUserSettingsUID: userUID}
37-
return cl.DeleteAllOf(ctx, toDelete, client.MatchingLabels(labels), client.InNamespace(UserSettingNS))
38-
} else {
35+
if !errors.IsNotFound(err) {
3936
return err
4037
}
4138
}

controllers/useraccount/console_usersettings_test.go

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
. "github.com/codeready-toolchain/member-operator/test"
77
"github.com/codeready-toolchain/toolchain-common/pkg/test"
8-
"github.com/stretchr/testify/assert"
98
"github.com/stretchr/testify/require"
109
corev1 "k8s.io/api/core/v1"
1110
rbac "k8s.io/api/rbac/v1"
@@ -75,84 +74,6 @@ func TestDeleteConsoleSettingObjects(t *testing.T) {
7574
AssertObjectNotFound(t, cl, UserSettingNS, "user-settings-johnsmith-rolebinding", &rbac.RoleBinding{})
7675
})
7776

78-
t.Run("Object found by label and deletes successfully", func(t *testing.T) {
79-
// given
80-
cm := &corev1.ConfigMap{
81-
TypeMeta: metav1.TypeMeta{Kind: "ConfigMap"},
82-
ObjectMeta: metav1.ObjectMeta{
83-
Name: "user-settings-name-no-match",
84-
Namespace: UserSettingNS,
85-
Labels: map[string]string{
86-
ConsoleUserSettingsIdentifier: "true",
87-
ConsoleUserSettingsUID: "johnsmith",
88-
},
89-
},
90-
}
91-
// create a noise objects where the labels don't match
92-
noiseObject := &corev1.ConfigMap{
93-
TypeMeta: metav1.TypeMeta{
94-
Kind: "ConfigMap",
95-
APIVersion: "v1",
96-
},
97-
ObjectMeta: metav1.ObjectMeta{
98-
Name: "user-settings-name-no-match-noise",
99-
Namespace: UserSettingNS,
100-
Labels: map[string]string{
101-
ConsoleUserSettingsIdentifier: "true",
102-
},
103-
},
104-
}
105-
cl := test.NewFakeClient(t, cm, noiseObject)
106-
107-
// when
108-
err := deleteResource(context.TODO(), cl, "johnsmith", &corev1.ConfigMap{})
109-
110-
// then
111-
require.NoError(t, err)
112-
// check that the configmap doesn't exist anymore
113-
AssertObjectNotFound(t, cl, UserSettingNS, "johnsmith", &corev1.ConfigMap{})
114-
// check that the noise object still exists
115-
retrievedNoise := &corev1.ConfigMap{}
116-
AssertObject(t, cl, UserSettingNS, "user-settings-name-no-match-noise", retrievedNoise, func() {
117-
assert.Equal(t, noiseObject, retrievedNoise)
118-
})
119-
})
120-
t.Run("multiple objects found by label and deletes successfully", func(t *testing.T) {
121-
// given
122-
cm1 := &corev1.ConfigMap{
123-
TypeMeta: metav1.TypeMeta{Kind: "ConfigMap"},
124-
ObjectMeta: metav1.ObjectMeta{
125-
Name: "user-settings-name-no-match",
126-
Namespace: UserSettingNS,
127-
Labels: map[string]string{
128-
ConsoleUserSettingsIdentifier: "true",
129-
ConsoleUserSettingsUID: "johnsmith",
130-
},
131-
},
132-
}
133-
cm2 := &corev1.ConfigMap{
134-
TypeMeta: metav1.TypeMeta{Kind: "ConfigMap"},
135-
ObjectMeta: metav1.ObjectMeta{
136-
Name: "user-settings-name-no-match-second",
137-
Namespace: UserSettingNS,
138-
Labels: map[string]string{
139-
ConsoleUserSettingsIdentifier: "true",
140-
ConsoleUserSettingsUID: "johnsmith",
141-
},
142-
},
143-
}
144-
cl := test.NewFakeClient(t, cm1, cm2)
145-
146-
// when
147-
err := deleteResource(context.TODO(), cl, "johnsmith", &corev1.ConfigMap{})
148-
149-
// then
150-
require.NoError(t, err)
151-
// check that the configmaps don't exist anymore
152-
AssertObjectNotFound(t, cl, UserSettingNS, "user-settings-name-no-match", &corev1.ConfigMap{})
153-
AssertObjectNotFound(t, cl, UserSettingNS, "user-settings-name-no-match-second", &corev1.ConfigMap{})
154-
})
155-
15677
t.Run("Error is returned when error in deleting configmap", func(t *testing.T) {
15778
// given
15879
cl := test.NewFakeClient(t)

controllers/useraccount/useraccount_controller_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,8 @@ func TestReconcile(t *testing.T) {
427427
APIVersion: "rbac.authorization.k8s.io/v1",
428428
},
429429
ObjectMeta: metav1.ObjectMeta{
430-
Name: resourceName + "random",
430+
Name: resourceName + ConsoleUserSettingsRoleSuffix,
431431
Namespace: UserSettingNS,
432-
Labels: map[string]string{
433-
ConsoleUserSettingsIdentifier: "true",
434-
ConsoleUserSettingsUID: string(userUID),
435-
},
436432
},
437433
}
438434
rb := &rbac.RoleBinding{
@@ -464,9 +460,6 @@ func TestReconcile(t *testing.T) {
464460
ObjectMeta: metav1.ObjectMeta{
465461
Name: noiseResourceName,
466462
Namespace: UserSettingNS,
467-
Labels: map[string]string{
468-
ConsoleUserSettingsIdentifier: "true",
469-
},
470463
},
471464
}
472465
noiseRb := &rbac.RoleBinding{

0 commit comments

Comments
 (0)