Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ subjects:
name: {{ include "mccp.serviceAccountName" . }}
namespace: {{ .Release.Namespace | quote }}
---
{{- if .Values.config.capi.clusters.namespace }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
Expand All @@ -26,6 +27,20 @@ subjects:
- kind: ServiceAccount
name: {{ include "mccp.serviceAccountName" . }}
namespace: {{ .Release.Namespace | quote }}
{{- else }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: clusters-service-secrets-role
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: clusters-service-secrets-role
subjects:
- kind: ServiceAccount
name: {{ include "mccp.serviceAccountName" . }}
namespace: {{ .Release.Namespace | quote }}
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
Expand Down
11 changes: 6 additions & 5 deletions cmd/clusters-service/pkg/server/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (s *server) CreatePullRequest(ctx context.Context, msg *capiv1_proto.Create
}

if viper.GetString("add-bases-kustomization") == "enabled" {
commonKustomization, err := getCommonKustomization(clusterName)
commonKustomization, err := getCommonKustomization(cluster)
if err != nil {
return nil, fmt.Errorf("failed to get common kustomization for %s: %s", clusterName, err)
}
Expand Down Expand Up @@ -399,9 +399,9 @@ func getToken(ctx context.Context) (string, string, error) {
return providerToken.AccessToken, "oauth2", nil
}

func getCommonKustomization(clusterName string) (*gitprovider.CommitFile, error) {
func getCommonKustomization(cluster types.NamespacedName) (*gitprovider.CommitFile, error) {

commonKustomizationPath := getCommonKustomizationPath(clusterName)
commonKustomizationPath := getCommonKustomizationPath(cluster)
commonKustomization := &kustomizev1.Kustomization{
TypeMeta: metav1.TypeMeta{
Kind: kustomizev1.KustomizationKind,
Expand Down Expand Up @@ -623,10 +623,11 @@ func getClusterManifestPath(cluster types.NamespacedName) string {
)
}

func getCommonKustomizationPath(clusterName string) string {
func getCommonKustomizationPath(cluster types.NamespacedName) string {
return filepath.Join(
viper.GetString("capi-repository-clusters-path"),
clusterName,
cluster.Namespace,
cluster.Name,
"clusters-bases-kustomization.yaml",
)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusters-service/pkg/server/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ metadata:
`,
},
{
Path: "clusters/dev/clusters-bases-kustomization.yaml",
Path: "clusters/default/dev/clusters-bases-kustomization.yaml",
Content: `apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
Expand Down Expand Up @@ -479,7 +479,7 @@ metadata:
`,
},
{
Path: "clusters/dev/clusters-bases-kustomization.yaml",
Path: "clusters/default/dev/clusters-bases-kustomization.yaml",
Content: `apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
Expand Down