From e8490d5e80b1bdfd1de713a8977eb849d16685dd Mon Sep 17 00:00:00 2001 From: William Tam Date: Tue, 25 Feb 2020 12:08:49 -0500 Subject: [PATCH] Fix dockerconfigjson secret namespace and name swap issue. Move sources to func in main driver. (#17) --- pkg/pipelines/bootstrap.go | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/pkg/pipelines/bootstrap.go b/pkg/pipelines/bootstrap.go index 876e8a53efc..e8eafbc729d 100644 --- a/pkg/pipelines/bootstrap.go +++ b/pkg/pipelines/bootstrap.go @@ -98,10 +98,7 @@ func Bootstrap(o *BootstrapOptions) error { } // Create Pipelines - outputs = append(outputs, createDevCIPipeline(meta.NamespacedName(namespaces["cicd"], "dev-ci-pipeline"))) - outputs = append(outputs, createStageCIPipeline(meta.NamespacedName(namespaces["cicd"], "stage-ci-pipeline"), namespaces["stage"])) - outputs = append(outputs, createDevCDPipeline(meta.NamespacedName(namespaces["cicd"], "dev-cd-pipeline"), o.DeploymentPath, namespaces["dev"])) - outputs = append(outputs, createStageCDPipeline(meta.NamespacedName(namespaces["cicd"], "stage-cd-pipeline"), namespaces["stage"])) + outputs = append(outputs, createPipelines(namespaces, o.DeploymentPath)) // Create Event Listener eventListener := eventlisteners.Generate(o.GitRepo, namespaces["cicd"]) @@ -112,16 +109,32 @@ func Bootstrap(o *BootstrapOptions) error { outputs = append(outputs, route) // Create Service Account, Role, Role Bindings, and ClusterRole Bindings - sa := createServiceAccount(meta.NamespacedName(namespaces["cicd"], saName), dockerSecretName) - outputs = append(outputs, sa) - role := createRole(meta.NamespacedName(namespaces["cicd"], roleName), rules) - outputs = append(outputs, role) - outputs = append(outputs, createRoleBinding(meta.NamespacedName(roleBindingName, namespaces["cicd"]), sa, role.Kind, role.Name)) - outputs = append(outputs, createRoleBinding(meta.NamespacedName("edit-clusterrole-binding", ""), sa, "ClusterRole", "edit")) + outputs = append(outputs, createRoleBindings(namespaces)) return marshalOutputs(os.Stdout, outputs) } +func createRoleBindings(ns map[string]string) []interface{} { + out := make([]interface{}, 0) + sa := createServiceAccount(meta.NamespacedName(ns["cicd"], saName), dockerSecretName) + out = append(out, sa) + role := createRole(meta.NamespacedName(ns["cicd"], roleName), rules) + out = append(out, role) + out = append(out, createRoleBinding(meta.NamespacedName(roleBindingName, ns["cicd"]), sa, role.Kind, role.Name)) + out = append(out, createRoleBinding(meta.NamespacedName("edit-clusterrole-binding", ""), sa, "ClusterRole", "edit")) + return out +} + +func createPipelines(ns map[string]string, deploymentPath string) []interface{} { + out := make([]interface{}, 0) + out = append(out, createDevCIPipeline(meta.NamespacedName(ns["cicd"], "dev-ci-pipeline"))) + out = append(out, createStageCIPipeline(meta.NamespacedName(ns["cicd"], "stage-ci-pipeline"), ns["stage"])) + out = append(out, createDevCDPipeline(meta.NamespacedName(ns["cicd"], "dev-cd-pipeline"), deploymentPath, ns["dev"])) + out = append(out, createStageCDPipeline(meta.NamespacedName(ns["cicd"], "stage-cd-pipeline"), ns["stage"])) + return out + +} + // createDockerSecret creates Docker secret func createDockerSecret(quayIOAuthFilename, ns string) (*corev1.Secret, error) { @@ -136,7 +149,7 @@ func createDockerSecret(quayIOAuthFilename, ns string) (*corev1.Secret, error) { } defer f.Close() - dockerSecret, err := createDockerConfigSecret(meta.NamespacedName(dockerSecretName, ns), f) + dockerSecret, err := createDockerConfigSecret(meta.NamespacedName(ns, dockerSecretName), f) if err != nil { return nil, err }