Skip to content

Commit

Permalink
Add support running with OwnerReferencesPermissionEnforcement
Browse files Browse the repository at this point in the history
when OwnerReferencesPermissionEnforcement validating webhook is
enabled additional permissions are required to set/update owner ref
field. NFD worker sets/updates NodeFeature owner ref field to
the worker pod and owning daemonset.

owner reference can only be updated if the worker has delete permissions
for NodeFeatures.

if owner reference has blockOwnerDeletion (as the case for the daemonset
owner reference) then it requires update permissions to the finalizers
of the owner, to avoid this, we set blockOwnerDeleteion to false for all
owners referenced from NFD worker pod when setting/updating NodeFeature
owner ref.

Signed-off-by: adrianc <[email protected]>
  • Loading branch information
adrianchiris committed Jan 8, 2025
1 parent b81c078 commit 3f012c2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions deployment/base/rbac/worker-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rules:
- create
- get
- update
- delete
- apiGroups:
- ""
resources:
Expand Down
1 change: 1 addition & 0 deletions deployment/helm/node-feature-discovery/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rules:
- create
- get
- update
- delete
- apiGroups:
- ""
resources:
Expand Down
6 changes: 5 additions & 1 deletion pkg/nfd-worker/nfd-worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation"
k8sclient "k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
klogutils "sigs.k8s.io/node-feature-discovery/pkg/utils/klog"
"sigs.k8s.io/yaml"

Expand Down Expand Up @@ -280,7 +281,10 @@ func (w *nfdWorker) setOwnerReference() error {
klog.ErrorS(err, "failed to get self pod, cannot inherit ownerReference for NodeFeature")
return err
} else {
ownerReference = append(ownerReference, selfPod.OwnerReferences...)
for _, owner := range selfPod.OwnerReferences {
owner.BlockOwnerDeletion = ptr.To(false)
ownerReference = append(ownerReference, owner)
}
}

podUID := os.Getenv("POD_UID")
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/utils/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func createRoleWorker(ctx context.Context, cs clientset.Interface, ns string) (*
{
APIGroups: []string{"nfd.k8s-sigs.io"},
Resources: []string{"nodefeatures"},
Verbs: []string{"create", "get", "update"},
Verbs: []string{"create", "get", "update", "delete"},
},
{
APIGroups: []string{""},
Expand Down

0 comments on commit 3f012c2

Please sign in to comment.