Skip to content

Commit

Permalink
retain project scope repos
Browse files Browse the repository at this point in the history
  • Loading branch information
nima-rx committed Sep 18, 2022
1 parent 14c9b4b commit 799e4ae
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions controllers/namespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,18 @@ func (r *NamespaceReconciler) createAppProj(ctx context.Context, team string) (*

}

// Get public repos
repo_env := os.Getenv("PUBLIC_REPOS")
repo_list := strings.Split(repo_env, ",")

// Compare source repos and public repos
foundproj := &argov1alpha1.AppProject{}
err = r.Get(ctx, types.NamespacedName{Name: team, Namespace: baseNs}, foundproj)
proj_repos := foundproj.Spec.SourceRepos
if !reflect.DeepEqual(repo_list, proj_repos) {
repo_list = appendRepos(repo_list, proj_repos)
}

appProj := &argov1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
Name: team,
Expand All @@ -238,14 +247,14 @@ func (r *NamespaceReconciler) createAppProj(ctx context.Context, team string) (*
},
Roles: []argov1alpha1.ProjectRole{
{
Groups: []string{team + "-admin"},
Groups: []string{team + "-admin", team + "-admin" + "-ci"},
Name: team + "-admin",
Policies: []string{
"p, proj:" + team + ":" + team + "-admin, applications, *, " + team + "/*, allow",
},
},
{
Groups: []string{team + "-view"},
Groups: []string{team + "-view", team + "-view" + "-ci"},
Name: team + "-view",
Policies: []string{
"p, proj:" + team + ":" + team + "-view, applications, *, " + team + "/get, allow",
Expand All @@ -265,3 +274,19 @@ func (r *NamespaceReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&corev1.Namespace{}).
Complete(r)
}

func appendRepos(repo_list []string, proj_repos []string) []string {

check := make(map[string]int)
mixrepos := append(repo_list, proj_repos...)
res := make([]string, 0)
for _, val := range mixrepos {
check[val] = 1
}

for letter, _ := range check {
res = append(res, letter)
}

return res
}

0 comments on commit 799e4ae

Please sign in to comment.