Skip to content

Commit 7c62cf2

Browse files
ccojocark8s-ci-robot
authored andcommitted
Remove the namespace from security profiles path
Change-Id: I34c8a88d0af12a567b03c968fa1cdfe68ae68fc4 Signed-off-by: Cosmin Cojocar <[email protected]>
1 parent d57522a commit 7c62cf2

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

internal/pkg/manager/workloadannotator/workloadannotator.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const (
4343
linkedPodsKey = ".metadata.activeWorkloads"
4444
StatusToProfLabel = "spo.x-k8s.io/profile-id"
4545
reconcileTimeout = 1 * time.Minute
46-
pathParts = 3
46+
pathParts = 2
4747
)
4848

4949
// NewController returns a new empty controller instance.
@@ -129,8 +129,8 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
129129
continue
130130
}
131131

132-
profileNamespace := profileElements[1]
133-
profileName := strings.TrimSuffix(profileElements[2], ".json")
132+
profileNamespace := "" // It is a cluster wide profile.
133+
profileName := strings.TrimSuffix(profileElements[1], ".json")
134134
seccompProfile := &seccompprofileapi.SeccompProfile{}
135135

136136
if err := r.client.Get(ctx, util.NamespacedName(profileName, profileNamespace), seccompProfile); err != nil {
@@ -152,7 +152,7 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
152152
profileName := strings.TrimSuffix(profileIndex, profileSuffix)
153153

154154
selinuxProfile := &selinuxprofileapi.SelinuxProfile{}
155-
if err := r.client.Get(ctx, util.NamespacedName(profileName, pod.GetNamespace()), selinuxProfile); err != nil {
155+
if err := r.client.Get(ctx, util.NamespacedName(profileName, ""), selinuxProfile); err != nil {
156156
logger.Error(err, "could not get selinux profile for pod")
157157

158158
return reconcile.Result{}, fmt.Errorf("looking up SelinuxProfile for new or updated pod: %w", err)
@@ -317,7 +317,7 @@ func getSelinuxProfilesFromPod(ctx context.Context, r *PodReconciler, pod *corev
317317
// try to get profile from pod securityContext
318318
sc := pod.Spec.SecurityContext
319319
if sc != nil {
320-
if isOperatorSelinuxType(ctx, r, sc.SELinuxOptions, pod.GetNamespace()) {
320+
if isOperatorSelinuxType(ctx, r, sc.SELinuxOptions, "") {
321321
profiles = append(profiles, sc.SELinuxOptions.Type)
322322
}
323323
}
@@ -328,7 +328,7 @@ func getSelinuxProfilesFromPod(ctx context.Context, r *PodReconciler, pod *corev
328328
for i := range containers {
329329
sc := containers[i].SecurityContext
330330
if sc != nil {
331-
if isOperatorSelinuxType(ctx, r, sc.SELinuxOptions, pod.GetNamespace()) {
331+
if isOperatorSelinuxType(ctx, r, sc.SELinuxOptions, "") {
332332
profileString := containers[i].SecurityContext.SELinuxOptions.Type
333333
if !util.Contains(profiles, profileString) {
334334
profiles = append(profiles, profileString)

internal/pkg/manager/workloadannotator/workloadannotator_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727
func TestGetSeccompProfilesFromPod(t *testing.T) {
2828
t.Parallel()
2929

30-
profilePath := "operator/default/test.json"
31-
profilePath2 := "operator/default/test2.json"
30+
profilePath := "operator/test.json"
31+
profilePath2 := "operator/test2.json"
3232
cases := []struct {
3333
name string
3434
pod corev1.Pod
@@ -211,11 +211,11 @@ func TestGetSeccompProfilesFromPod(t *testing.T) {
211211
}{
212212
{
213213
name: "NoSuffix",
214-
profile: "operator/default/test",
214+
profile: "operator/test",
215215
},
216216
{
217217
name: "BadSuffix",
218-
profile: "operator/default/test.js",
218+
profile: "operator/test.js",
219219
},
220220
{
221221
name: "WrongPath",

0 commit comments

Comments
 (0)