pb-2157: retaining the rolebinding subjects if the namespace is not set during restore.
@@ -41,10 +41,23 @@ func (r *ResourceCollector) prepareRoleBindingForApply(
if err != nil {
return err
}
+ subjectWithNs := make([]rbacv1.Subject, 0)
+ subjectWithoutNs := make([]rbacv1.Subject, 0)
+ // Create list of rolebinding subjects that has namspace and pass it to updateSubject to
+ // update destination namespace based on the namespace mapping.
+ for _, subject := range rb.Subjects {
+ if len(subject.Namespace) != 0 {
+ subjectWithNs = append(subjectWithNs, subject)
+ } else {
+ subjectWithoutNs = append(subjectWithoutNs, subject)
+ }
+ }
+ rb.Subjects = subjectWithNs
rb.Subjects, err = r.updateSubjects(rb.Subjects, namespaceMappings)
if err != nil {
return err
}
+ rb.Subjects = append(rb.Subjects, subjectWithoutNs...)
o, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&rb)
if err != nil {
return err
