Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

Commit

Permalink
Fix dockerconfigjson secret namespace and name swap issue. Move sourc…
Browse files Browse the repository at this point in the history
…es to func in main driver. (#17)
  • Loading branch information
wtam2018 authored and bigkevmcd committed May 15, 2020
1 parent b3578c3 commit 579c856
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions pkg/pipelines/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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) {

Expand All @@ -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
}
Expand Down

0 comments on commit 579c856

Please sign in to comment.