Skip to content

Commit b794526

Browse files
Fix prtb migration (#13)
* Add project member Signed-off-by: galal-hussein <[email protected]> * Fix compare in prtb migration Signed-off-by: galal-hussein <[email protected]> --------- Signed-off-by: galal-hussein <[email protected]>
1 parent 38a4aca commit b794526

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

pkg/cluster/cluster.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (c *Cluster) Compare(ctx context.Context, tc *Cluster) error {
205205
for _, tPrtb := range tProject.PRTBs {
206206
if sPrtb.Name == tPrtb.Name {
207207
sPrtb.Migrated = true
208-
if !reflect.DeepEqual(sPrtb.Obj, tPrtb.Obj) {
208+
if !sPrtb.Compare(tPrtb) {
209209
sPrtb.Diff = true
210210
}
211211
}
@@ -347,7 +347,6 @@ func (c *Cluster) Migrate(ctx context.Context, client *client.Clients, tc *Clust
347347
return errors.New("user " + userID + " does not exists, please migrate user first")
348348
}
349349
}
350-
351350
prtb.Mutate(tc.Obj.Name, prtb.ProjectName)
352351
if err := client.ProjectRoleTemplateBindings.Create(ctx, prtb.ProjectName, prtb.Obj, nil, v1.CreateOptions{}); err != nil {
353352
return err

pkg/cluster/projectroletemplatebinding.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func (p *ProjectRoleTemplateBinding) normalize() {
3636
// removing objectMeta and projectName since prtb has no spec
3737
p.Obj.ObjectMeta = v1.ObjectMeta{}
3838
p.Obj.ProjectName = ""
39+
if p.Obj.GroupPrincipalName != "" || p.Obj.GroupName != "" {
40+
p.Obj.UserName = ""
41+
p.Obj.UserPrincipalName = ""
42+
}
3943
}
4044

4145
func (p *ProjectRoleTemplateBinding) Mutate(clusterName, projectName string) {
@@ -52,6 +56,22 @@ func (p *ProjectRoleTemplateBinding) Mutate(clusterName, projectName string) {
5256
}
5357
}
5458

59+
func (p *ProjectRoleTemplateBinding) Compare(target *ProjectRoleTemplateBinding) bool {
60+
// if group principal name exists in the target cluster we should just return true
61+
// this is due to the original creator of the source cluster might be different than
62+
// the target cluster creator
63+
if target.Obj.GroupPrincipalName != "" || target.Obj.GroupName != "" {
64+
return true
65+
}
66+
if p.Obj.UserName == target.Obj.UserName &&
67+
p.Obj.UserPrincipalName == target.Obj.UserPrincipalName &&
68+
p.Obj.ServiceAccount == target.Obj.ServiceAccount &&
69+
p.Obj.RoleTemplateName == target.Obj.RoleTemplateName {
70+
return true
71+
}
72+
return false
73+
}
74+
5575
func (p *ProjectRoleTemplateBinding) SetDescription(ctx context.Context, client *client.Clients) error {
5676
if p.Obj.UserName == "" && p.Obj.UserPrincipalName == "" {
5777
groupName := p.Obj.GroupName

0 commit comments

Comments
 (0)