Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nfs backup failure with latest changes for anyuid support #405

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions pkg/drivers/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,24 @@ func SetupRoleBindingForSCC(name, namespace, pvcName string) error {
return fmt.Errorf("failed to check if cluster is OCP: %v", err)
}

provisionerName, err := GetProvisionerNameFromPvc(pvcName, namespace)
if err != nil {
return fmt.Errorf("failed to get provisioner name from pvc: %v", err)
}

provisionersListToUseAnyUid, err := GetArrayConfigValue(KdmpConfigmapName, KdmpConfigmapNamespace, provisionersToUseAnyUid)
if err != nil {
logrus.Errorf("failed to extract provisioners list from configmap: %v", err)
return err
}

if len(provisionersListToUseAnyUid) > 0 {
if isOCP && contains(provisionersListToUseAnyUid, provisionerName) {
failed, err := addRoleBindingForScc(name, namespace, AnyUidClusterRoleName)
if failed {
return err
// In case of nfs backup, nfs restore job pods when they are invoked for resources backup, we don't send any pvcName
if pvcName != "" {
provisionerName, err := GetProvisionerNameFromPvc(pvcName, namespace)
if err != nil {
return fmt.Errorf("failed to get provisioner name from pvc: %v", err)
}
if isOCP && contains(provisionersListToUseAnyUid, provisionerName) {
failed, err := addRoleBindingForScc(name, namespace, AnyUidClusterRoleName)
if failed {
return err
}
}
}
}
Expand Down
37 changes: 20 additions & 17 deletions pkg/drivers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,32 +1054,35 @@ func AddSecurityContextToJob(job *batchv1.Job, podUserId, podGroupId, pvcName, p
return nil, err
}

// If PROVISIONERS_TO_USE_ANYUID is set in kdmp-config, then add rolebinding for anyuid SCC
// If PROVISIONERS_TO_USE_ANYUID is set in kdmp-config, then add anyuid SCC to the job pod
provisionersListToUseAnyUid, err := GetArrayConfigValue(KdmpConfigmapName, KdmpConfigmapNamespace, provisionersToUseAnyUid)
if err != nil {
errMsg := fmt.Sprintf("failed to extract provisioners list from configmap: %v", err)
logrus.Errorf(errMsg)
return nil, fmt.Errorf(errMsg)
}

// Get provisioner name from the pvcName, pvcNamespace
provisionerName, err := GetProvisionerNameFromPvc(pvcName, pvcNamespace)
if err != nil {
errMsg := fmt.Sprintf("failed to get provisionerName name for pvc [%s/%s]: %v", pvcNamespace, pvcName, err)
logrus.Errorf(errMsg)
return nil, fmt.Errorf(errMsg)
}

if len(provisionersListToUseAnyUid) > 0 {
if isOcp && contains(provisionersListToUseAnyUid, provisionerName) {
logrus.Infof("PROVISIONERS_TO_USE_ANYUID is set to use, running the job %v with anyuid SCC", job.Name)
// Add the annotation to force the pod to adopt anyuid scc in OCP
// It may not work if the pod's SA doesn't have permission to use anyuid SCC
if job.Spec.Template.Annotations == nil {
job.Spec.Template.Annotations = make(map[string]string)
// In case of nfs backup, nfs restore job pods when they are invoked for resources backup, we don't send any pvcName
if pvcName != "" {
// Get provisioner name from the pvcName, pvcNamespace
provisionerName, err := GetProvisionerNameFromPvc(pvcName, pvcNamespace)
if err != nil {
errMsg := fmt.Sprintf("failed to get provisionerName name for pvc [%s/%s]: %v", pvcNamespace, pvcName, err)
logrus.Errorf(errMsg)
return nil, fmt.Errorf(errMsg)
}

if isOcp && contains(provisionersListToUseAnyUid, provisionerName) {
logrus.Infof("PROVISIONERS_TO_USE_ANYUID is set to use, running the job %v with anyuid SCC", job.Name)
// Add the annotation to force the pod to adopt anyuid scc in OCP
// It may not work if the pod's SA doesn't have permission to use anyuid SCC
if job.Spec.Template.Annotations == nil {
job.Spec.Template.Annotations = make(map[string]string)
}
job.Spec.Template.Annotations["openshift.io/required-scc"] = "anyuid"
return job, nil
}
job.Spec.Template.Annotations["openshift.io/required-scc"] = "anyuid"
return job, nil
}
}

Expand Down
Loading