Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make notification component optional #123

Merged
merged 1 commit into from
Jul 22, 2020
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
25 changes: 24 additions & 1 deletion cmd/tk/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
} else if installExport {
fmt.Println("---")
fmt.Println("# GitOps Toolkit revision", installVersion, time.Now().Format(time.RFC3339))
fmt.Println("# Components:", strings.Join(installComponents, ","))
fmt.Print(yaml)
fmt.Println("---")
return nil
Expand Down Expand Up @@ -183,7 +184,7 @@ fieldSpecs:
`

var kustomizationTmpl = `---
{{- $version := .Version }}
{{- $eventsAddr := .EventsAddr }}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: {{.Namespace}}
Expand All @@ -196,6 +197,21 @@ resources:
{{- range .Components }}
- {{.}}.yaml
{{- end }}

patchesJson6902:
{{- range $i, $v := .Components }}
{{- if ne $v "notification-controller" }}
- target:
group: apps
version: v1
kind: Deployment
name: {{$v}}
patch: |-
- op: replace
path: /spec/template/spec/containers/0/args/0
value: --events-addr={{$eventsAddr}}
{{- end }}
{{- end }}
`

var kustomizationRolesTmpl = `---
Expand Down Expand Up @@ -241,14 +257,21 @@ func downloadManifests(version string, tmpDir string) error {
}

func genInstallManifests(version string, namespace string, components []string, tmpDir string) error {
eventsAddr := ""
if utils.containsItemString(components, defaultNotification) {
eventsAddr = fmt.Sprintf("http://%s/", defaultNotification)
}

model := struct {
Version string
Namespace string
Components []string
EventsAddr string
}{
Version: version,
Namespace: namespace,
Components: components,
EventsAddr: eventsAddr,
}

if err := downloadManifests(version, tmpDir); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/tk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ var (
)

var (
defaultComponents = []string{"source-controller", "kustomize-controller", "helm-controller", "notification-controller"}
defaultVersion = "latest"
defaultNamespace = "gitops-system"
defaultComponents = []string{"source-controller", "kustomize-controller", "helm-controller", "notification-controller"}
defaultVersion = "latest"
defaultNamespace = "gitops-system"
defaultNotification = "notification-controller"
)

func init() {
Expand Down
9 changes: 9 additions & 0 deletions cmd/tk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,12 @@ func (*Utils) copyFile(src, dst string) error {
}
return out.Close()
}

func (*Utils) containsItemString(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}