Add watch all namespaces flag

pull/227/head
stefanprodan 4 years ago
parent 3f98affd5a
commit d5e78b9f80

@ -51,6 +51,7 @@ var (
bootstrapImagePullSecret string bootstrapImagePullSecret string
bootstrapArch string bootstrapArch string
bootstrapBranch string bootstrapBranch string
bootstrapWatchAllNamespaces bool
) )
const ( const (
@ -74,6 +75,8 @@ func init() {
bootstrapCmd.PersistentFlags().StringVar(&bootstrapBranch, "branch", bootstrapDefaultBranch, bootstrapCmd.PersistentFlags().StringVar(&bootstrapBranch, "branch", bootstrapDefaultBranch,
"default branch (for GitHub this must match the default branch setting for the organization)") "default branch (for GitHub this must match the default branch setting for the organization)")
rootCmd.AddCommand(bootstrapCmd) rootCmd.AddCommand(bootstrapCmd)
bootstrapCmd.PersistentFlags().BoolVar(&bootstrapWatchAllNamespaces, "watch-all-namespaces", true,
"watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed")
} }
func generateInstallManifests(targetPath, namespace, tmpDir string) (string, error) { func generateInstallManifests(targetPath, namespace, tmpDir string) (string, error) {
@ -84,7 +87,8 @@ func generateInstallManifests(targetPath, namespace, tmpDir string) (string, err
return "", fmt.Errorf("generating manifests failed: %w", err) return "", fmt.Errorf("generating manifests failed: %w", err)
} }
if err := genInstallManifests(bootstrapVersion, namespace, bootstrapComponents, bootstrapRegistry, bootstrapImagePullSecret, bootstrapArch, gotkDir); err != nil { if err := genInstallManifests(bootstrapVersion, namespace, bootstrapComponents,
bootstrapWatchAllNamespaces, bootstrapRegistry, bootstrapImagePullSecret, bootstrapArch, gotkDir); err != nil {
return "", fmt.Errorf("generating manifests failed: %w", err) return "", fmt.Errorf("generating manifests failed: %w", err)
} }

@ -63,6 +63,7 @@ var (
installRegistry string installRegistry string
installImagePullSecret string installImagePullSecret string
installArch string installArch string
installWatchAllNamespaces bool
) )
func init() { func init() {
@ -82,6 +83,8 @@ func init() {
"Kubernetes secret name used for pulling the toolkit images from a private registry") "Kubernetes secret name used for pulling the toolkit images from a private registry")
installCmd.Flags().StringVar(&installArch, "arch", "amd64", installCmd.Flags().StringVar(&installArch, "arch", "amd64",
"arch can be amd64 or arm64") "arch can be amd64 or arm64")
installCmd.Flags().BoolVar(&installWatchAllNamespaces, "watch-all-namespaces", true,
"watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed")
rootCmd.AddCommand(installCmd) rootCmd.AddCommand(installCmd)
} }
@ -111,7 +114,8 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
logger.Generatef("generating manifests") logger.Generatef("generating manifests")
} }
if kustomizePath == "" { if kustomizePath == "" {
err = genInstallManifests(installVersion, namespace, installComponents, installRegistry, installImagePullSecret, installArch, tmpDir) err = genInstallManifests(installVersion, namespace, installComponents,
installWatchAllNamespaces, installRegistry, installImagePullSecret, installArch, tmpDir)
if err != nil { if err != nil {
return fmt.Errorf("install failed: %w", err) return fmt.Errorf("install failed: %w", err)
} }
@ -199,6 +203,7 @@ fieldSpecs:
var kustomizationTmpl = `--- var kustomizationTmpl = `---
{{- $eventsAddr := .EventsAddr }} {{- $eventsAddr := .EventsAddr }}
{{- $watchAllNamespaces := .WatchAllNamespaces }}
{{- $registry := .Registry }} {{- $registry := .Registry }}
{{- $arch := .Arch }} {{- $arch := .Arch }}
apiVersion: kustomize.config.k8s.io/v1beta1 apiVersion: kustomize.config.k8s.io/v1beta1
@ -223,7 +228,17 @@ patches:
patchesJson6902: patchesJson6902:
{{- range $i, $component := .Components }} {{- range $i, $component := .Components }}
{{- if ne $component "notification-controller" }} {{- if eq $component "notification-controller" }}
- target:
group: apps
version: v1
kind: Deployment
name: {{$component}}
patch: |-
- op: replace
path: /spec/template/spec/containers/0/args/0
value: --watch-all-namespaces={{$watchAllNamespaces}}
{{- else }}
- target: - target:
group: apps group: apps
version: v1 version: v1
@ -233,6 +248,9 @@ patchesJson6902:
- op: replace - op: replace
path: /spec/template/spec/containers/0/args/0 path: /spec/template/spec/containers/0/args/0
value: --events-addr={{$eventsAddr}} value: --events-addr={{$eventsAddr}}
- op: replace
path: /spec/template/spec/containers/0/args/1
value: --watch-all-namespaces={{$watchAllNamespaces}}
{{- end }} {{- end }}
{{- end }} {{- end }}
@ -308,7 +326,8 @@ func downloadManifests(version string, tmpDir string) error {
return nil return nil
} }
func genInstallManifests(version string, namespace string, components []string, registry, imagePullSecret, arch, tmpDir string) error { func genInstallManifests(version string, namespace string, components []string,
watchAllNamespaces bool, registry, imagePullSecret, arch, tmpDir string) error {
eventsAddr := "" eventsAddr := ""
if utils.containsItemString(components, defaultNotification) { if utils.containsItemString(components, defaultNotification) {
eventsAddr = fmt.Sprintf("http://%s/", defaultNotification) eventsAddr = fmt.Sprintf("http://%s/", defaultNotification)
@ -322,6 +341,7 @@ func genInstallManifests(version string, namespace string, components []string,
Registry string Registry string
ImagePullSecret string ImagePullSecret string
Arch string Arch string
WatchAllNamespaces bool
}{ }{
Version: version, Version: version,
Namespace: namespace, Namespace: namespace,
@ -330,6 +350,7 @@ func genInstallManifests(version string, namespace string, components []string,
Registry: registry, Registry: registry,
ImagePullSecret: imagePullSecret, ImagePullSecret: imagePullSecret,
Arch: arch, Arch: arch,
WatchAllNamespaces: watchAllNamespaces,
} }
if err := downloadManifests(version, tmpDir); err != nil { if err := downloadManifests(version, tmpDir); err != nil {

@ -16,6 +16,7 @@ The bootstrap sub-commands bootstrap the toolkit components on the targeted Git
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry --image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
--registry string container registry where the toolkit images are published (default "ghcr.io/fluxcd") --registry string container registry where the toolkit images are published (default "ghcr.io/fluxcd")
-v, --version string toolkit version (default "latest") -v, --version string toolkit version (default "latest")
--watch-all-namespaces watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed (default true)
``` ```
### Options inherited from parent commands ### Options inherited from parent commands

@ -67,6 +67,7 @@ gotk bootstrap github [flags]
--timeout duration timeout for this operation (default 5m0s) --timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects --verbose print generated objects
-v, --version string toolkit version (default "latest") -v, --version string toolkit version (default "latest")
--watch-all-namespaces watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed (default true)
``` ```
### SEE ALSO ### SEE ALSO

@ -64,6 +64,7 @@ gotk bootstrap gitlab [flags]
--timeout duration timeout for this operation (default 5m0s) --timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects --verbose print generated objects
-v, --version string toolkit version (default "latest") -v, --version string toolkit version (default "latest")
--watch-all-namespaces watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed (default true)
``` ```
### SEE ALSO ### SEE ALSO

@ -40,6 +40,7 @@ gotk install [flags]
--manifests string path to the manifest directory, dev only --manifests string path to the manifest directory, dev only
--registry string container registry where the toolkit images are published (default "ghcr.io/fluxcd") --registry string container registry where the toolkit images are published (default "ghcr.io/fluxcd")
-v, --version string toolkit version (default "latest") -v, --version string toolkit version (default "latest")
--watch-all-namespaces watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed (default true)
``` ```
### Options inherited from parent commands ### Options inherited from parent commands

Loading…
Cancel
Save