Skip to content

Commit 3b85bed

Browse files
committed
feat: adds labels for better discovery
Signed-off-by: Bartosz Majsak <bartosz.majsak@gmail.com>
1 parent e315444 commit 3b85bed

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

maas-api/internal/tier/mapper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func TestMapper_GetTierForGroups(t *testing.T) {
155155
func TestMapper_GetTierForGroups_MissingConfigMap(t *testing.T) {
156156
ctx := t.Context()
157157

158-
clientset := fake.NewSimpleClientset()
158+
clientset := fake.NewClientset()
159159
mapper := tier.NewMapper(clientset, testTenant, testNamespace)
160160

161161
// Should default to free mappedTier when ConfigMap is missing
@@ -194,7 +194,7 @@ func TestMapper_GetTierForGroups_SameLevels(t *testing.T) {
194194
},
195195
}
196196

197-
clientset := fake.NewSimpleClientset([]runtime.Object{configMap}...)
197+
clientset := fake.NewClientset([]runtime.Object{configMap}...)
198198
mapper := tier.NewMapper(clientset, testTenant, testNamespace)
199199

200200
// When levels are equal, first tier found should win

maas-api/internal/token/labels.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package token
2+
3+
func namespaceLabels(instance, tier string) map[string]string {
4+
return map[string]string{
5+
"app.kubernetes.io/component": "token-issuer",
6+
"app.kubernetes.io/part-of": "maas-api",
7+
"maas.opendatahub.io/instance": instance,
8+
"maas.opendatahub.io/tier": tier,
9+
"maas.opendatahub.io/tier-namespace": "true",
10+
}
11+
}
12+
13+
func serviceAccountLabels(instance, tier, username string) map[string]string {
14+
return map[string]string{
15+
"app.kubernetes.io/component": "token-issuer",
16+
"app.kubernetes.io/part-of": "maas-api",
17+
"maas.opendatahub.io/instance": instance,
18+
"maas.opendatahub.io/tier": tier,
19+
"maas.opendatahub.io/username": username,
20+
}
21+
}

maas-api/internal/token/manager.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (m *Manager) ensureTierNamespace(ctx context.Context, tier string) (string,
134134
ns := &corev1.Namespace{
135135
ObjectMeta: metav1.ObjectMeta{
136136
Name: namespace,
137-
Labels: commonLabels(m.tenantName, tier),
137+
Labels: namespaceLabels(m.tenantName, tier),
138138
},
139139
}
140140

@@ -171,7 +171,7 @@ func (m *Manager) ensureServiceAccount(ctx context.Context, namespace, username,
171171
ObjectMeta: metav1.ObjectMeta{
172172
Name: saName,
173173
Namespace: namespace,
174-
Labels: commonLabels(m.tenantName, userTier),
174+
Labels: serviceAccountLabels(m.tenantName, userTier, username),
175175
},
176176
}
177177

@@ -255,12 +255,3 @@ func (m *Manager) sanitizeServiceAccountName(username string) (string, error) {
255255

256256
return name + "-" + suffix, nil
257257
}
258-
259-
func commonLabels(name string, t string) map[string]string {
260-
return map[string]string{
261-
"app.kubernetes.io/component": "token-issuer",
262-
"app.kubernetes.io/part-of": "maas-api",
263-
"maas.opendatahub.io/instance": name,
264-
"maas.opendatahub.io/tier": t,
265-
}
266-
}

maas-api/internal/token/reviewer_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package token_test
22

33
import (
4-
"context"
54
"errors"
65
"slices"
76
"testing"
@@ -90,7 +89,7 @@ func TestResolver_ExtractUserInfo(t *testing.T) {
9089

9190
for _, tt := range tests {
9291
t.Run(tt.name, func(t *testing.T) {
93-
fakeClient := fake.NewSimpleClientset()
92+
fakeClient := fake.NewClientset()
9493

9594
if tt.tokenReviewResponse != nil || tt.tokenReviewError != nil {
9695
fakeClient.PrependReactor("create", "tokenreviews", func(action ktesting.Action) (bool, runtime.Object, error) {
@@ -102,7 +101,7 @@ func TestResolver_ExtractUserInfo(t *testing.T) {
102101
}
103102

104103
resolver := token.NewReviewer(fakeClient)
105-
ctx := context.Background()
104+
ctx := t.Context()
106105

107106
result, err := resolver.ExtractUserInfo(ctx, tt.token)
108107

0 commit comments

Comments
 (0)