Skip to content

Commit

Permalink
Merge pull request #19 from snapp-incubator/enabling-cluster-scoped-t…
Browse files Browse the repository at this point in the history
…eams

adding ability to have teams with cluster access
  • Loading branch information
sinamna authored Jul 29, 2024
2 parents db56e42 + 81f5044 commit 7cecaea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ spec:
envFrom:
- configMapRef:
name: public-repos
- configMapRef:
name: cluster-admin-teams
serviceAccountName: controller-manager
terminationGracePeriodSeconds: 10
32 changes: 25 additions & 7 deletions controllers/namespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,17 @@ func (r *NamespaceReconciler) createAppProj(team string) (*argov1alpha1.AppProje
repo_env := os.Getenv("PUBLIC_REPOS")
repo_list := strings.Split(repo_env, ",")

// Get cluster scoped teams
team_env := os.Getenv("CLUSTER_ADMIN_TEAMS")
team_list := strings.Split(team_env, ",")

includeAllGroupKind := []metav1.GroupKind{
{
Group: "*",
Kind: "*",
},
}

appProj := &argov1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
Name: team,
Expand All @@ -300,12 +311,6 @@ func (r *NamespaceReconciler) createAppProj(team string) (*argov1alpha1.AppProje
Spec: argov1alpha1.AppProjectSpec{
SourceRepos: repo_list,
Destinations: destList,
ClusterResourceBlacklist: []metav1.GroupKind{
{
Group: "*",
Kind: "*",
},
},
NamespaceResourceBlacklist: []metav1.GroupKind{
{
Group: "",
Expand All @@ -330,7 +335,11 @@ func (r *NamespaceReconciler) createAppProj(team string) (*argov1alpha1.AppProje
},
},
}

if isTeamClusterAdmin(team, team_list) {
appProj.Spec.ClusterResourceWhitelist = includeAllGroupKind
} else {
appProj.Spec.ClusterResourceBlacklist = includeAllGroupKind
}
return appProj, nil

}
Expand Down Expand Up @@ -371,3 +380,12 @@ func convertLabelToAppProjectNameset(l string) AppProjectNameset {
}
return result
}

func isTeamClusterAdmin(team string, clusterAdminList []string) bool {
for _, tm := range clusterAdminList {
if team == tm {
return true
}
}
return false
}

0 comments on commit 7cecaea

Please sign in to comment.