Skip to content

Commit

Permalink
Merge pull request #61 from cybozu-go/delegated-namespaces
Browse files Browse the repository at this point in the history
Add delegated namespaces to destinations in AppProject
  • Loading branch information
zoetrope authored Oct 7, 2024
2 parents 83f1da0 + 67ff7b4 commit 86ad924
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions controllers/tenant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ func (r *TenantReconciler) reconcileArgoCD(ctx context.Context, tenant *cattagev
for i, ns := range nss.Items {
namespaces[i] = ns.Name
}
delegatedNamespaces, err := r.getDelegatedNamespaces(ctx, tenant.Spec.Delegates)
if err != nil {
return err
}
namespaces = append(namespaces, delegatedNamespaces...)

tpl, err := template.New("AppProject Template").Parse(r.config.ArgoCD.AppProjectTemplate)
if err != nil {
Expand Down Expand Up @@ -552,6 +557,21 @@ func (r *TenantReconciler) reconcileArgoCD(ctx context.Context, tenant *cattagev
return nil
}

func (r *TenantReconciler) getDelegatedNamespaces(ctx context.Context, delegates []cattagev1beta1.DelegateSpec) ([]string, error) {
result := make([]string, 0)

for _, d := range delegates {
nss := &corev1.NamespaceList{}
if err := r.client.List(ctx, nss, client.MatchingFields{constants.TenantNamespaceIndex: d.Name}); err != nil {
return nil, err
}
for _, ns := range nss.Items {
result = append(result, ns.Name)
}
}
return result, nil
}

func (r *TenantReconciler) reconcileConfigMapForApplicationController(ctx context.Context, tenant *cattagev1beta1.Tenant) error {
cmList := &corev1.ConfigMapList{}
err := r.client.List(ctx, cmList, client.MatchingLabels{constants.ManagedByLabel: "cattage"})
Expand Down
4 changes: 4 additions & 0 deletions controllers/tenant_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ var _ = Describe("Tenant controller", Ordered, func() {
"namespace": Equal("extra-namespace-y"),
"server": Equal("*"),
}),
MatchAllKeys(Keys{
"namespace": Equal("app-c"),
"server": Equal("*"),
}),
),
"namespaceResourceBlacklist": ConsistOf(
MatchAllKeys(Keys{
Expand Down

0 comments on commit 86ad924

Please sign in to comment.