Add watch all namespaces flag
This commit is contained in:
@@ -45,12 +45,13 @@ var bootstrapCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
var (
|
||||
bootstrapVersion string
|
||||
bootstrapComponents []string
|
||||
bootstrapRegistry string
|
||||
bootstrapImagePullSecret string
|
||||
bootstrapArch string
|
||||
bootstrapBranch string
|
||||
bootstrapVersion string
|
||||
bootstrapComponents []string
|
||||
bootstrapRegistry string
|
||||
bootstrapImagePullSecret string
|
||||
bootstrapArch string
|
||||
bootstrapBranch string
|
||||
bootstrapWatchAllNamespaces bool
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -74,6 +75,8 @@ func init() {
|
||||
bootstrapCmd.PersistentFlags().StringVar(&bootstrapBranch, "branch", bootstrapDefaultBranch,
|
||||
"default branch (for GitHub this must match the default branch setting for the organization)")
|
||||
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) {
|
||||
@@ -84,7 +87,8 @@ func generateInstallManifests(targetPath, namespace, tmpDir string) (string, 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)
|
||||
}
|
||||
|
||||
|
||||
@@ -55,14 +55,15 @@ If a previous version is installed, then an in-place upgrade will be performed.`
|
||||
}
|
||||
|
||||
var (
|
||||
installExport bool
|
||||
installDryRun bool
|
||||
installManifestsPath string
|
||||
installVersion string
|
||||
installComponents []string
|
||||
installRegistry string
|
||||
installImagePullSecret string
|
||||
installArch string
|
||||
installExport bool
|
||||
installDryRun bool
|
||||
installManifestsPath string
|
||||
installVersion string
|
||||
installComponents []string
|
||||
installRegistry string
|
||||
installImagePullSecret string
|
||||
installArch string
|
||||
installWatchAllNamespaces bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -82,6 +83,8 @@ func init() {
|
||||
"Kubernetes secret name used for pulling the toolkit images from a private registry")
|
||||
installCmd.Flags().StringVar(&installArch, "arch", "amd64",
|
||||
"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)
|
||||
}
|
||||
|
||||
@@ -111,7 +114,8 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
||||
logger.Generatef("generating manifests")
|
||||
}
|
||||
if kustomizePath == "" {
|
||||
err = genInstallManifests(installVersion, namespace, installComponents, installRegistry, installImagePullSecret, installArch, tmpDir)
|
||||
err = genInstallManifests(installVersion, namespace, installComponents,
|
||||
installWatchAllNamespaces, installRegistry, installImagePullSecret, installArch, tmpDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
@@ -199,6 +203,7 @@ fieldSpecs:
|
||||
|
||||
var kustomizationTmpl = `---
|
||||
{{- $eventsAddr := .EventsAddr }}
|
||||
{{- $watchAllNamespaces := .WatchAllNamespaces }}
|
||||
{{- $registry := .Registry }}
|
||||
{{- $arch := .Arch }}
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
@@ -223,7 +228,17 @@ patches:
|
||||
|
||||
patchesJson6902:
|
||||
{{- 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:
|
||||
group: apps
|
||||
version: v1
|
||||
@@ -233,6 +248,9 @@ patchesJson6902:
|
||||
- op: replace
|
||||
path: /spec/template/spec/containers/0/args/0
|
||||
value: --events-addr={{$eventsAddr}}
|
||||
- op: replace
|
||||
path: /spec/template/spec/containers/0/args/1
|
||||
value: --watch-all-namespaces={{$watchAllNamespaces}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
@@ -308,28 +326,31 @@ func downloadManifests(version string, tmpDir string) error {
|
||||
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 := ""
|
||||
if utils.containsItemString(components, defaultNotification) {
|
||||
eventsAddr = fmt.Sprintf("http://%s/", defaultNotification)
|
||||
}
|
||||
|
||||
model := struct {
|
||||
Version string
|
||||
Namespace string
|
||||
Components []string
|
||||
EventsAddr string
|
||||
Registry string
|
||||
ImagePullSecret string
|
||||
Arch string
|
||||
Version string
|
||||
Namespace string
|
||||
Components []string
|
||||
EventsAddr string
|
||||
Registry string
|
||||
ImagePullSecret string
|
||||
Arch string
|
||||
WatchAllNamespaces bool
|
||||
}{
|
||||
Version: version,
|
||||
Namespace: namespace,
|
||||
Components: components,
|
||||
EventsAddr: eventsAddr,
|
||||
Registry: registry,
|
||||
ImagePullSecret: imagePullSecret,
|
||||
Arch: arch,
|
||||
Version: version,
|
||||
Namespace: namespace,
|
||||
Components: components,
|
||||
EventsAddr: eventsAddr,
|
||||
Registry: registry,
|
||||
ImagePullSecret: imagePullSecret,
|
||||
Arch: arch,
|
||||
WatchAllNamespaces: watchAllNamespaces,
|
||||
}
|
||||
|
||||
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
|
||||
--registry string container registry where the toolkit images are published (default "ghcr.io/fluxcd")
|
||||
-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
|
||||
|
||||
@@ -67,6 +67,7 @@ gotk bootstrap github [flags]
|
||||
--timeout duration timeout for this operation (default 5m0s)
|
||||
--verbose print generated objects
|
||||
-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
|
||||
|
||||
@@ -64,6 +64,7 @@ gotk bootstrap gitlab [flags]
|
||||
--timeout duration timeout for this operation (default 5m0s)
|
||||
--verbose print generated objects
|
||||
-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
|
||||
|
||||
@@ -40,6 +40,7 @@ gotk install [flags]
|
||||
--manifests string path to the manifest directory, dev only
|
||||
--registry string container registry where the toolkit images are published (default "ghcr.io/fluxcd")
|
||||
-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
|
||||
|
||||
Reference in New Issue
Block a user