How to categorize this issue?
/area quality
/kind enhancement
What would you like to be added:
The Project API has an owner field, in practice the owner subject could be also a project member with additional roles assigned. There is some code canonicalizing the resource, but it is placed in the version <-> internal conversion methods
|
if owner := out.Owner; owner != nil { |
|
outer: |
|
for i, member := range out.Members { |
|
if member.Name == owner.Name && member.APIGroup == owner.APIGroup && member.Kind == owner.Kind { |
|
// add owner role to the current project's owner if not present |
|
for _, role := range member.Roles { |
|
if role == core.ProjectMemberOwner { |
|
continue outer |
|
} |
|
} |
|
|
|
out.Members[i].Roles = append(out.Members[i].Roles, core.ProjectMemberOwner) |
|
} else { |
|
// delete owner role from all other members |
|
out.Members[i].Roles = removeRoleFromRoles(member.Roles, ProjectMemberOwner) |
|
} |
|
} |
|
} |
|
if owner := out.Owner; owner != nil { |
|
outer: |
|
for i, member := range out.Members { |
|
if member.Name == owner.Name && member.APIGroup == owner.APIGroup && member.Kind == owner.Kind { |
|
// add owner role to the current project's owner if not present |
|
if member.Role == core.ProjectMemberOwner { |
|
// remove it from owners list if present |
|
out.Members[i].Roles = removeRoleFromRoles(member.Roles, ProjectMemberOwner) |
|
continue outer |
|
} |
|
for _, role := range member.Roles { |
|
if role == ProjectMemberOwner { |
|
continue outer |
|
} |
|
} |
|
|
|
if out.Members[i].Role == "" { |
|
out.Members[i].Role = core.ProjectMemberOwner |
|
} else { |
|
out.Members[i].Roles = append(out.Members[i].Roles, core.ProjectMemberOwner) |
|
} |
|
} else { |
|
// delete owner role from all other members |
|
out.Members[i].Roles = removeRoleFromRoles(member.Roles, ProjectMemberOwner) |
|
|
|
if member.Role == ProjectMemberOwner { |
|
if len(out.Members[i].Roles) == 0 { |
|
out.Members[i].Role = "" |
|
} else { |
|
out.Members[i].Role = out.Members[i].Roles[0] |
|
if len(out.Members[i].Roles) > 1 { |
|
out.Members[i].Roles = out.Members[i].Roles[1:] |
|
} else { |
|
out.Members[i].Roles = nil |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
A better place for such code is the REST strategy, i.e. in the Canonicalize method
|
func (projectStrategy) Canonicalize(_ runtime.Object) { |
Why is this needed:
Improve code quality and readability.
How to categorize this issue?
/area quality
/kind enhancement
What would you like to be added:
The
ProjectAPI has anownerfield, in practice the owner subject could be also a project member with additional roles assigned. There is some code canonicalizing the resource, but it is placed in theversion <-> internalconversion methodsgardener/pkg/apis/core/v1beta1/conversions.go
Lines 132 to 149 in a3cbecf
gardener/pkg/apis/core/v1beta1/conversions.go
Lines 159 to 198 in a3cbecf
A better place for such code is the REST strategy, i.e. in the
Canonicalizemethodgardener/pkg/apiserver/registry/core/project/strategy.go
Line 60 in fb264cf
Why is this needed:
Improve code quality and readability.