mirror of
https://github.com/fluxcd/flux2.git
synced 2025-11-02 10:48:03 +08:00
Add log level flag
This commit is contained in:
@ -52,6 +52,7 @@ var (
|
||||
bootstrapArch string
|
||||
bootstrapBranch string
|
||||
bootstrapWatchAllNamespaces bool
|
||||
bootstrapLogLevel string
|
||||
)
|
||||
|
||||
const (
|
||||
@ -77,6 +78,19 @@ func init() {
|
||||
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")
|
||||
bootstrapCmd.PersistentFlags().StringVar(&bootstrapLogLevel, "log-level", "info", "set the controllers log level")
|
||||
}
|
||||
|
||||
func bootstrapValidate() error {
|
||||
if !utils.containsItemString(supportedArch, bootstrapArch) {
|
||||
return fmt.Errorf("arch %s is not supported, can be %v", bootstrapArch, supportedArch)
|
||||
}
|
||||
|
||||
if !utils.containsItemString(supportedLogLevels, bootstrapLogLevel) {
|
||||
return fmt.Errorf("log level %s is not supported, can be %v", bootstrapLogLevel, supportedLogLevels)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateInstallManifests(targetPath, namespace, tmpDir string) (string, error) {
|
||||
@ -88,7 +102,8 @@ func generateInstallManifests(targetPath, namespace, tmpDir string) (string, err
|
||||
}
|
||||
|
||||
if err := genInstallManifests(bootstrapVersion, namespace, bootstrapComponents,
|
||||
bootstrapWatchAllNamespaces, bootstrapRegistry, bootstrapImagePullSecret, bootstrapArch, gotkDir); err != nil {
|
||||
bootstrapWatchAllNamespaces, bootstrapRegistry, bootstrapImagePullSecret,
|
||||
bootstrapArch, bootstrapLogLevel, gotkDir); err != nil {
|
||||
return "", fmt.Errorf("generating manifests failed: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@ -100,8 +100,8 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("%s environment variable not found", git.GitHubTokenName)
|
||||
}
|
||||
|
||||
if !utils.containsItemString(supportedArch, bootstrapArch) {
|
||||
return fmt.Errorf("arch %s is not supported, can be %v", bootstrapArch, supportedArch)
|
||||
if err := bootstrapValidate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
repository, err := git.NewRepository(ghRepository, ghOwner, ghHostname, ghToken, "gotk", ghOwner+"@users.noreply.github.com")
|
||||
|
||||
@ -89,8 +89,8 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("%s environment variable not found", git.GitLabTokenName)
|
||||
}
|
||||
|
||||
if !utils.containsItemString(supportedArch, bootstrapArch) {
|
||||
return fmt.Errorf("arch %s is not supported, can be %v", bootstrapArch, supportedArch)
|
||||
if err := bootstrapValidate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
repository, err := git.NewRepository(glRepository, glOwner, glHostname, glToken, "gotk", glOwner+"@users.noreply.gitlab.com")
|
||||
|
||||
@ -64,6 +64,7 @@ var (
|
||||
installImagePullSecret string
|
||||
installArch string
|
||||
installWatchAllNamespaces bool
|
||||
installLogLevel string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -85,6 +86,7 @@ func init() {
|
||||
"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")
|
||||
installCmd.Flags().StringVar(&installLogLevel, "log-level", "info", "set the controllers log level")
|
||||
rootCmd.AddCommand(installCmd)
|
||||
}
|
||||
|
||||
@ -93,6 +95,10 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("arch %s is not supported, can be %v", installArch, supportedArch)
|
||||
}
|
||||
|
||||
if !utils.containsItemString(supportedLogLevels, installLogLevel) {
|
||||
return fmt.Errorf("log level %s is not supported, can be %v", bootstrapLogLevel, installLogLevel)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -115,7 +121,8 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
if kustomizePath == "" {
|
||||
err = genInstallManifests(installVersion, namespace, installComponents,
|
||||
installWatchAllNamespaces, installRegistry, installImagePullSecret, installArch, tmpDir)
|
||||
installWatchAllNamespaces, installRegistry, installImagePullSecret,
|
||||
installArch, installLogLevel, tmpDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
@ -206,6 +213,7 @@ var kustomizationTmpl = `---
|
||||
{{- $watchAllNamespaces := .WatchAllNamespaces }}
|
||||
{{- $registry := .Registry }}
|
||||
{{- $arch := .Arch }}
|
||||
{{- $logLevel := .LogLevel }}
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
namespace: {{.Namespace}}
|
||||
@ -238,6 +246,9 @@ patchesJson6902:
|
||||
- op: replace
|
||||
path: /spec/template/spec/containers/0/args/0
|
||||
value: --watch-all-namespaces={{$watchAllNamespaces}}
|
||||
- op: replace
|
||||
path: /spec/template/spec/containers/0/args/1
|
||||
value: --log-level={{$logLevel}}
|
||||
{{- else }}
|
||||
- target:
|
||||
group: apps
|
||||
@ -251,6 +262,9 @@ patchesJson6902:
|
||||
- op: replace
|
||||
path: /spec/template/spec/containers/0/args/1
|
||||
value: --watch-all-namespaces={{$watchAllNamespaces}}
|
||||
- op: replace
|
||||
path: /spec/template/spec/containers/0/args/2
|
||||
value: --log-level={{$logLevel}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
@ -327,7 +341,7 @@ func downloadManifests(version string, tmpDir string) error {
|
||||
}
|
||||
|
||||
func genInstallManifests(version string, namespace string, components []string,
|
||||
watchAllNamespaces bool, registry, imagePullSecret, arch, tmpDir string) error {
|
||||
watchAllNamespaces bool, registry, imagePullSecret, arch, logLevel, tmpDir string) error {
|
||||
eventsAddr := ""
|
||||
if utils.containsItemString(components, defaultNotification) {
|
||||
eventsAddr = fmt.Sprintf("http://%s/", defaultNotification)
|
||||
@ -342,6 +356,7 @@ func genInstallManifests(version string, namespace string, components []string,
|
||||
ImagePullSecret string
|
||||
Arch string
|
||||
WatchAllNamespaces bool
|
||||
LogLevel string
|
||||
}{
|
||||
Version: version,
|
||||
Namespace: namespace,
|
||||
@ -351,6 +366,7 @@ func genInstallManifests(version string, namespace string, components []string,
|
||||
ImagePullSecret: imagePullSecret,
|
||||
Arch: arch,
|
||||
WatchAllNamespaces: watchAllNamespaces,
|
||||
LogLevel: logLevel,
|
||||
}
|
||||
|
||||
if err := downloadManifests(version, tmpDir); err != nil {
|
||||
|
||||
@ -113,6 +113,7 @@ var (
|
||||
supportedArch = []string{"arm64", "amd64"}
|
||||
supportedDecryptionProviders = []string{"sops"}
|
||||
supportedHelmChartSourceKinds = []string{sourcev1.HelmRepositoryKind, sourcev1.GitRepositoryKind}
|
||||
supportedLogLevels = []string{"debug", "info", "error"}
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@ -14,6 +14,7 @@ The bootstrap sub-commands bootstrap the toolkit components on the targeted Git
|
||||
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
||||
-h, --help help for bootstrap
|
||||
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||
--log-level string set the controllers log level (default "info")
|
||||
--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)
|
||||
|
||||
@ -62,6 +62,7 @@ gotk bootstrap github [flags]
|
||||
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
||||
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||
--log-level string set the controllers log level (default "info")
|
||||
--namespace string the namespace scope for this operation (default "gitops-system")
|
||||
--registry string container registry where the toolkit images are published (default "ghcr.io/fluxcd")
|
||||
--timeout duration timeout for this operation (default 5m0s)
|
||||
|
||||
@ -59,6 +59,7 @@ gotk bootstrap gitlab [flags]
|
||||
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
||||
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||
--log-level string set the controllers log level (default "info")
|
||||
--namespace string the namespace scope for this operation (default "gitops-system")
|
||||
--registry string container registry where the toolkit images are published (default "ghcr.io/fluxcd")
|
||||
--timeout duration timeout for this operation (default 5m0s)
|
||||
|
||||
@ -37,6 +37,7 @@ gotk install [flags]
|
||||
--export write the install manifests to stdout and exit
|
||||
-h, --help help for install
|
||||
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||
--log-level string set the controllers log level (default "info")
|
||||
--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")
|
||||
|
||||
Reference in New Issue
Block a user