1
0
mirror of synced 2026-03-01 11:16:56 +00:00

Compare commits

...

13 Commits

Author SHA1 Message Date
Stefan Prodan
503e5ec950 Merge pull request #358 from fluxcd/update-components
Update toolkit components
2020-10-19 17:56:48 +03:00
fluxcdbot
414aeb0ac3 Update toolkit components 2020-10-19 14:23:20 +00:00
Stefan Prodan
55b8544d32 Merge pull request #350 from allymparker/source-git-secret-ref
Add secret-ref flag to create source git
2020-10-19 17:21:14 +03:00
Ally Parker
2d67ea5f7f Add secret-ref flag to git source
Add secret-ref flag to Helm source

Add secret-ref to bucket source
2020-10-19 14:49:14 +01:00
Stefan Prodan
4eaf72fa3e Merge pull request #356 from StupidScience/custom-flags
Implement custom flags for options with validation rules
2020-10-19 13:41:47 +03:00
“Anton
95ef3c1782 Update docs 2020-10-19 13:09:53 +03:00
“Anton
b3ef410fb7 Add source bucket provider flag 2020-10-19 13:05:56 +03:00
“Anton
0c55bca218 Add helm chart source flag 2020-10-19 12:55:34 +03:00
“Anton
5fd28439dc Add kustomization source and decryption provider flags 2020-10-19 12:46:10 +03:00
“Anton
a58c18e992 Refresh bootstrap and install docs 2020-10-17 23:47:20 +03:00
“Anton
058dfdfcd6 Move flags and utils to internal packages 2020-10-17 23:35:09 +03:00
Stefan Prodan
637fdac28a Merge pull request #354 from fluxcd/windows-exe
Add Windows OS to CLI install docs
2020-10-17 15:43:54 +03:00
Stefan Prodan
a8b667780a Add Windows OS to CLI install docs
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-10-17 14:05:17 +03:00
85 changed files with 835 additions and 382 deletions

View File

@@ -33,7 +33,7 @@ curl -s https://toolkit.fluxcd.io/install.sh | sudo bash
. <(gotk completion bash) . <(gotk completion bash)
``` ```
Binaries for macOS and Linux AMD64/ARM64 are available to download on the Binaries for macOS, Windows and Linux AMD64/ARM are available to download on the
[release page](https://github.com/fluxcd/toolkit/releases). [release page](https://github.com/fluxcd/toolkit/releases).
Verify that your cluster satisfies the prerequisites with: Verify that your cluster satisfies the prerequisites with:

View File

@@ -38,6 +38,8 @@ import (
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/flags"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/fluxcd/toolkit/pkg/install" "github.com/fluxcd/toolkit/pkg/install"
) )
@@ -52,11 +54,11 @@ var (
bootstrapComponents []string bootstrapComponents []string
bootstrapRegistry string bootstrapRegistry string
bootstrapImagePullSecret string bootstrapImagePullSecret string
bootstrapArch string bootstrapArch flags.Arch = "amd64"
bootstrapBranch string bootstrapBranch string
bootstrapWatchAllNamespaces bool bootstrapWatchAllNamespaces bool
bootstrapNetworkPolicy bool bootstrapNetworkPolicy bool
bootstrapLogLevel string bootstrapLogLevel flags.LogLevel = "info"
bootstrapManifestsPath string bootstrapManifestsPath string
bootstrapRequiredComponents = []string{"source-controller", "kustomize-controller"} bootstrapRequiredComponents = []string{"source-controller", "kustomize-controller"}
) )
@@ -77,8 +79,7 @@ func init() {
"container registry where the toolkit images are published") "container registry where the toolkit images are published")
bootstrapCmd.PersistentFlags().StringVar(&bootstrapImagePullSecret, "image-pull-secret", "", bootstrapCmd.PersistentFlags().StringVar(&bootstrapImagePullSecret, "image-pull-secret", "",
"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")
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArch, "arch", "amd64", bootstrapCmd.PersistentFlags().Var(&bootstrapArch, "arch", bootstrapArch.Description())
"arch can be amd64 or arm64")
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)
@@ -86,22 +87,14 @@ func init() {
"watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed") "watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed")
bootstrapCmd.PersistentFlags().BoolVar(&bootstrapNetworkPolicy, "network-policy", true, bootstrapCmd.PersistentFlags().BoolVar(&bootstrapNetworkPolicy, "network-policy", true,
"deny ingress access to the toolkit controllers from other namespaces using network policies") "deny ingress access to the toolkit controllers from other namespaces using network policies")
bootstrapCmd.PersistentFlags().StringVar(&bootstrapLogLevel, "log-level", "info", "set the controllers log level") bootstrapCmd.PersistentFlags().Var(&bootstrapLogLevel, "log-level", bootstrapLogLevel.Description())
bootstrapCmd.PersistentFlags().StringVar(&bootstrapManifestsPath, "manifests", "", "path to the manifest directory") bootstrapCmd.PersistentFlags().StringVar(&bootstrapManifestsPath, "manifests", "", "path to the manifest directory")
bootstrapCmd.PersistentFlags().MarkHidden("manifests") bootstrapCmd.PersistentFlags().MarkHidden("manifests")
} }
func bootstrapValidate() error { 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)
}
for _, component := range bootstrapRequiredComponents { for _, component := range bootstrapRequiredComponents {
if !utils.containsItemString(bootstrapComponents, component) { if !utils.ContainsItemString(bootstrapComponents, component) {
return fmt.Errorf("component %s is required", component) return fmt.Errorf("component %s is required", component)
} }
} }
@@ -124,10 +117,10 @@ func generateInstallManifests(targetPath, namespace, tmpDir string, localManifes
Components: bootstrapComponents, Components: bootstrapComponents,
Registry: bootstrapRegistry, Registry: bootstrapRegistry,
ImagePullSecret: bootstrapImagePullSecret, ImagePullSecret: bootstrapImagePullSecret,
Arch: bootstrapArch, Arch: bootstrapArch.String(),
WatchAllNamespaces: bootstrapWatchAllNamespaces, WatchAllNamespaces: bootstrapWatchAllNamespaces,
NetworkPolicy: bootstrapNetworkPolicy, NetworkPolicy: bootstrapNetworkPolicy,
LogLevel: bootstrapLogLevel, LogLevel: bootstrapLogLevel.String(),
NotificationController: defaultNotification, NotificationController: defaultNotification,
ManifestsFile: fmt.Sprintf("%s.yaml", namespace), ManifestsFile: fmt.Sprintf("%s.yaml", namespace),
Timeout: timeout, Timeout: timeout,
@@ -151,13 +144,13 @@ func generateInstallManifests(targetPath, namespace, tmpDir string, localManifes
func applyInstallManifests(ctx context.Context, manifestPath string, components []string) error { func applyInstallManifests(ctx context.Context, manifestPath string, components []string) error {
kubectlArgs := []string{"apply", "-f", manifestPath} kubectlArgs := []string{"apply", "-f", manifestPath}
if _, err := utils.execKubectlCommand(ctx, ModeOS, kubectlArgs...); err != nil { if _, err := utils.ExecKubectlCommand(ctx, utils.ModeOS, kubectlArgs...); err != nil {
return fmt.Errorf("install failed") return fmt.Errorf("install failed")
} }
for _, deployment := range components { for _, deployment := range components {
kubectlArgs = []string{"-n", namespace, "rollout", "status", "deployment", deployment, "--timeout", timeout.String()} kubectlArgs = []string{"-n", namespace, "rollout", "status", "deployment", deployment, "--timeout", timeout.String()}
if _, err := utils.execKubectlCommand(ctx, ModeOS, kubectlArgs...); err != nil { if _, err := utils.ExecKubectlCommand(ctx, utils.ModeOS, kubectlArgs...); err != nil {
return fmt.Errorf("install failed") return fmt.Errorf("install failed")
} }
} }
@@ -194,7 +187,7 @@ func generateSyncManifests(url, branch, name, namespace, targetPath, tmpDir stri
return err return err
} }
if err := utils.writeFile(string(gitData), filepath.Join(tmpDir, targetPath, namespace, bootstrapSourceManifest)); err != nil { if err := utils.WriteFile(string(gitData), filepath.Join(tmpDir, targetPath, namespace, bootstrapSourceManifest)); err != nil {
return err return err
} }
@@ -227,11 +220,11 @@ func generateSyncManifests(url, branch, name, namespace, targetPath, tmpDir stri
return err return err
} }
if err := utils.writeFile(string(ksData), filepath.Join(tmpDir, targetPath, namespace, bootstrapKustomizationManifest)); err != nil { if err := utils.WriteFile(string(ksData), filepath.Join(tmpDir, targetPath, namespace, bootstrapKustomizationManifest)); err != nil {
return err return err
} }
if err := utils.generateKustomizationYaml(filepath.Join(tmpDir, targetPath, namespace)); err != nil { if err := utils.GenerateKustomizationYaml(filepath.Join(tmpDir, targetPath, namespace)); err != nil {
return err return err
} }
@@ -240,7 +233,7 @@ func generateSyncManifests(url, branch, name, namespace, targetPath, tmpDir stri
func applySyncManifests(ctx context.Context, kubeClient client.Client, name, namespace, targetPath, tmpDir string) error { func applySyncManifests(ctx context.Context, kubeClient client.Client, name, namespace, targetPath, tmpDir string) error {
kubectlArgs := []string{"apply", "-k", filepath.Join(tmpDir, targetPath, namespace)} kubectlArgs := []string{"apply", "-k", filepath.Join(tmpDir, targetPath, namespace)}
if _, err := utils.execKubectlCommand(ctx, ModeStderrOS, kubectlArgs...); err != nil { if _, err := utils.ExecKubectlCommand(ctx, utils.ModeStderrOS, kubectlArgs...); err != nil {
return err return err
} }

View File

@@ -28,6 +28,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/fluxcd/pkg/git" "github.com/fluxcd/pkg/git"
"github.com/fluxcd/toolkit/internal/utils"
) )
var bootstrapGitHubCmd = &cobra.Command{ var bootstrapGitHubCmd = &cobra.Command{
@@ -183,7 +184,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
logger.Successf("components are up to date") logger.Successf("components are up to date")
} }
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -30,6 +30,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/fluxcd/pkg/git" "github.com/fluxcd/pkg/git"
"github.com/fluxcd/toolkit/internal/utils"
) )
var bootstrapGitLabCmd = &cobra.Command{ var bootstrapGitLabCmd = &cobra.Command{
@@ -112,7 +113,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
IsPersonal: glPersonal, IsPersonal: glPersonal,
} }
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -24,6 +24,7 @@ import (
"strings" "strings"
"github.com/blang/semver/v4" "github.com/blang/semver/v4"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
apimachineryversion "k8s.io/apimachinery/pkg/version" apimachineryversion "k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
@@ -103,7 +104,7 @@ func kubectlCheck(ctx context.Context, version string) bool {
} }
kubectlArgs := []string{"version", "--client", "--output", "json"} kubectlArgs := []string{"version", "--client", "--output", "json"}
output, err := utils.execKubectlCommand(ctx, ModeCapture, kubectlArgs...) output, err := utils.ExecKubectlCommand(ctx, utils.ModeCapture, kubectlArgs...)
if err != nil { if err != nil {
logger.Failuref("kubectl version can't be determined") logger.Failuref("kubectl version can't be determined")
return false return false
@@ -173,7 +174,7 @@ func componentsCheck() bool {
ok := true ok := true
for _, deployment := range checkComponents { for _, deployment := range checkComponents {
kubectlArgs := []string{"-n", namespace, "rollout", "status", "deployment", deployment, "--timeout", timeout.String()} kubectlArgs := []string{"-n", namespace, "rollout", "status", "deployment", deployment, "--timeout", timeout.String()}
if output, err := utils.execKubectlCommand(ctx, ModeCapture, kubectlArgs...); err != nil { if output, err := utils.ExecKubectlCommand(ctx, utils.ModeCapture, kubectlArgs...); err != nil {
logger.Failuref("%s: %s", deployment, strings.TrimSuffix(output, "\n")) logger.Failuref("%s: %s", deployment, strings.TrimSuffix(output, "\n"))
ok = false ok = false
} else { } else {

View File

@@ -19,7 +19,9 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@@ -71,7 +73,7 @@ func createAlertCmdRun(cmd *cobra.Command, args []string) error {
eventSources := []notificationv1.CrossNamespaceObjectReference{} eventSources := []notificationv1.CrossNamespaceObjectReference{}
for _, eventSource := range aEventSources { for _, eventSource := range aEventSources {
kind, name := utils.parseObjectKindName(eventSource) kind, name := utils.ParseObjectKindName(eventSource)
if kind == "" { if kind == "" {
return fmt.Errorf("invalid event source '%s', must be in format <kind>/<name>", eventSource) return fmt.Errorf("invalid event source '%s', must be in format <kind>/<name>", eventSource)
} }
@@ -118,7 +120,7 @@ func createAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -30,6 +30,7 @@ import (
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
) )
var createAlertProviderCmd = &cobra.Command{ var createAlertProviderCmd = &cobra.Command{
@@ -115,7 +116,7 @@ func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -22,6 +22,8 @@ import (
"io/ioutil" "io/ioutil"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/flags"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -89,7 +91,7 @@ var createHelmReleaseCmd = &cobra.Command{
var ( var (
hrName string hrName string
hrSource string hrSource flags.HelmChartSource
hrDependsOn []string hrDependsOn []string
hrChart string hrChart string
hrChartVersion string hrChartVersion string
@@ -99,7 +101,7 @@ var (
func init() { func init() {
createHelmReleaseCmd.Flags().StringVar(&hrName, "release-name", "", "name used for the Helm release, defaults to a composition of '[<target-namespace>-]<HelmRelease-name>'") createHelmReleaseCmd.Flags().StringVar(&hrName, "release-name", "", "name used for the Helm release, defaults to a composition of '[<target-namespace>-]<HelmRelease-name>'")
createHelmReleaseCmd.Flags().StringVar(&hrSource, "source", "", "source that contains the chart (<kind>/<name>)") createHelmReleaseCmd.Flags().Var(&hrSource, "source", hrSource.Description())
createHelmReleaseCmd.Flags().StringVar(&hrChart, "chart", "", "Helm chart name or path") createHelmReleaseCmd.Flags().StringVar(&hrChart, "chart", "", "Helm chart name or path")
createHelmReleaseCmd.Flags().StringVar(&hrChartVersion, "chart-version", "", "Helm chart version, accepts a semver range (ignored for charts from GitRepository sources)") createHelmReleaseCmd.Flags().StringVar(&hrChartVersion, "chart-version", "", "Helm chart version, accepts a semver range (ignored for charts from GitRepository sources)")
createHelmReleaseCmd.Flags().StringArrayVar(&hrDependsOn, "depends-on", nil, "HelmReleases that must be ready before this release can be installed, supported formats '<name>' and '<namespace>/<name>'") createHelmReleaseCmd.Flags().StringArrayVar(&hrDependsOn, "depends-on", nil, "HelmReleases that must be ready before this release can be installed, supported formats '<name>' and '<namespace>/<name>'")
@@ -114,17 +116,6 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
} }
name := args[0] name := args[0]
if hrSource == "" {
return fmt.Errorf("source is required")
}
sourceKind, sourceName := utils.parseObjectKindName(hrSource)
if sourceKind == "" {
return fmt.Errorf("invalid source '%s', must be in format <kind>/<name>", hrSource)
}
if !utils.containsItemString(supportedHelmChartSourceKinds, sourceKind) {
return fmt.Errorf("source kind %s is not supported, can be %v",
sourceKind, supportedHelmChartSourceKinds)
}
if hrChart == "" { if hrChart == "" {
return fmt.Errorf("chart name or path is required") return fmt.Errorf("chart name or path is required")
} }
@@ -146,7 +137,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
}, },
Spec: helmv2.HelmReleaseSpec{ Spec: helmv2.HelmReleaseSpec{
ReleaseName: hrName, ReleaseName: hrName,
DependsOn: utils.makeDependsOn(hrDependsOn), DependsOn: utils.MakeDependsOn(hrDependsOn),
Interval: metav1.Duration{ Interval: metav1.Duration{
Duration: interval, Duration: interval,
}, },
@@ -156,8 +147,8 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
Chart: hrChart, Chart: hrChart,
Version: hrChartVersion, Version: hrChartVersion,
SourceRef: helmv2.CrossNamespaceObjectReference{ SourceRef: helmv2.CrossNamespaceObjectReference{
Kind: sourceKind, Kind: hrSource.Kind,
Name: sourceName, Name: hrSource.Name,
}, },
}, },
}, },
@@ -186,7 +177,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -33,7 +33,8 @@ import (
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1" helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" "github.com/fluxcd/toolkit/internal/flags"
"github.com/fluxcd/toolkit/internal/utils"
) )
var createKsCmd = &cobra.Command{ var createKsCmd = &cobra.Command{
@@ -71,7 +72,7 @@ var createKsCmd = &cobra.Command{
} }
var ( var (
ksSource string ksSource flags.KustomizationSource
ksPath string ksPath string
ksPrune bool ksPrune bool
ksDependsOn []string ksDependsOn []string
@@ -80,13 +81,12 @@ var (
ksHealthTimeout time.Duration ksHealthTimeout time.Duration
ksSAName string ksSAName string
ksSANamespace string ksSANamespace string
ksDecryptionProvider string ksDecryptionProvider flags.DecryptionProvider
ksDecryptionSecret string ksDecryptionSecret string
) )
func init() { func init() {
createKsCmd.Flags().StringVar(&ksSource, "source", "", createKsCmd.Flags().Var(&ksSource, "source", ksSource.Description())
"source that contains the Kubernetes manifests in the format '[<kind>/]<name>', where kind can be GitRepository or Bucket, if kind is not specified it defaults to GitRepository")
createKsCmd.Flags().StringVar(&ksPath, "path", "./", "path to the directory containing the Kustomization file") createKsCmd.Flags().StringVar(&ksPath, "path", "./", "path to the directory containing the Kustomization file")
createKsCmd.Flags().BoolVar(&ksPrune, "prune", false, "enable garbage collection") createKsCmd.Flags().BoolVar(&ksPrune, "prune", false, "enable garbage collection")
createKsCmd.Flags().StringArrayVar(&ksHealthCheck, "health-check", nil, "workload to be included in the health assessment, in the format '<kind>/<name>.<namespace>'") createKsCmd.Flags().StringArrayVar(&ksHealthCheck, "health-check", nil, "workload to be included in the health assessment, in the format '<kind>/<name>.<namespace>'")
@@ -95,7 +95,7 @@ func init() {
createKsCmd.Flags().StringArrayVar(&ksDependsOn, "depends-on", nil, "Kustomization that must be ready before this Kustomization can be applied, supported formats '<name>' and '<namespace>/<name>'") createKsCmd.Flags().StringArrayVar(&ksDependsOn, "depends-on", nil, "Kustomization that must be ready before this Kustomization can be applied, supported formats '<name>' and '<namespace>/<name>'")
createKsCmd.Flags().StringVar(&ksSAName, "sa-name", "", "service account name") createKsCmd.Flags().StringVar(&ksSAName, "sa-name", "", "service account name")
createKsCmd.Flags().StringVar(&ksSANamespace, "sa-namespace", "", "service account namespace") createKsCmd.Flags().StringVar(&ksSANamespace, "sa-namespace", "", "service account namespace")
createKsCmd.Flags().StringVar(&ksDecryptionProvider, "decryption-provider", "", "enables secrets decryption, provider can be 'sops'") createKsCmd.Flags().Var(&ksDecryptionProvider, "decryption-provider", ksDecryptionProvider.Description())
createKsCmd.Flags().StringVar(&ksDecryptionSecret, "decryption-secret", "", "set the Kubernetes secret name that contains the OpenPGP private keys used for sops decryption") createKsCmd.Flags().StringVar(&ksDecryptionSecret, "decryption-secret", "", "set the Kubernetes secret name that contains the OpenPGP private keys used for sops decryption")
createCmd.AddCommand(createKsCmd) createCmd.AddCommand(createKsCmd)
} }
@@ -106,19 +106,6 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
} }
name := args[0] name := args[0]
if ksSource == "" {
return fmt.Errorf("source is required")
}
sourceKind, sourceName := utils.parseObjectKindName(ksSource)
if sourceKind == "" {
sourceKind = sourcev1.GitRepositoryKind
}
if !utils.containsItemString(supportedKustomizationSourceKinds, sourceKind) {
return fmt.Errorf("source kind %s is not supported, can be %v",
sourceKind, supportedKustomizationSourceKinds)
}
if ksPath == "" { if ksPath == "" {
return fmt.Errorf("path is required") return fmt.Errorf("path is required")
} }
@@ -142,15 +129,15 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
Labels: ksLabels, Labels: ksLabels,
}, },
Spec: kustomizev1.KustomizationSpec{ Spec: kustomizev1.KustomizationSpec{
DependsOn: utils.makeDependsOn(ksDependsOn), DependsOn: utils.MakeDependsOn(ksDependsOn),
Interval: metav1.Duration{ Interval: metav1.Duration{
Duration: interval, Duration: interval,
}, },
Path: ksPath, Path: ksPath,
Prune: ksPrune, Prune: ksPrune,
SourceRef: kustomizev1.CrossNamespaceSourceReference{ SourceRef: kustomizev1.CrossNamespaceSourceReference{
Kind: sourceKind, Kind: ksSource.Kind,
Name: sourceName, Name: ksSource.Name,
}, },
Suspend: false, Suspend: false,
Validation: ksValidation, Validation: ksValidation,
@@ -206,13 +193,8 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
} }
if ksDecryptionProvider != "" { if ksDecryptionProvider != "" {
if !utils.containsItemString(supportedDecryptionProviders, ksDecryptionProvider) {
return fmt.Errorf("decryption provider %s is not supported, can be %v",
ksDecryptionProvider, supportedDecryptionProviders)
}
kustomization.Spec.Decryption = &kustomizev1.Decryption{ kustomization.Spec.Decryption = &kustomizev1.Decryption{
Provider: ksDecryptionProvider, Provider: ksDecryptionProvider.String(),
} }
if ksDecryptionSecret != "" { if ksDecryptionSecret != "" {
@@ -227,7 +209,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -30,6 +30,7 @@ import (
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
) )
var createReceiverCmd = &cobra.Command{ var createReceiverCmd = &cobra.Command{
@@ -79,7 +80,7 @@ func createReceiverCmdRun(cmd *cobra.Command, args []string) error {
resources := []notificationv1.CrossNamespaceObjectReference{} resources := []notificationv1.CrossNamespaceObjectReference{}
for _, resource := range rcvResources { for _, resource := range rcvResources {
kind, name := utils.parseObjectKindName(resource) kind, name := utils.ParseObjectKindName(resource)
if kind == "" { if kind == "" {
return fmt.Errorf("invalid event source '%s', must be in format <kind>/<name>", resource) return fmt.Errorf("invalid event source '%s', must be in format <kind>/<name>", resource)
} }
@@ -127,7 +128,7 @@ func createReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -31,6 +31,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/flags"
"github.com/fluxcd/toolkit/internal/utils"
) )
var createSourceBucketCmd = &cobra.Command{ var createSourceBucketCmd = &cobra.Command{
@@ -61,22 +63,24 @@ For Buckets with static authentication, the credentials are stored in a Kubernet
var ( var (
sourceBucketName string sourceBucketName string
sourceBucketProvider string sourceBucketProvider = flags.SourceBucketProvider(sourcev1.GenericBucketProvider)
sourceBucketEndpoint string sourceBucketEndpoint string
sourceBucketAccessKey string sourceBucketAccessKey string
sourceBucketSecretKey string sourceBucketSecretKey string
sourceBucketRegion string sourceBucketRegion string
sourceBucketInsecure bool sourceBucketInsecure bool
sourceBucketSecretRef string
) )
func init() { func init() {
createSourceBucketCmd.Flags().StringVar(&sourceBucketProvider, "provider", sourcev1.GenericBucketProvider, "the S3 compatible storage provider name, can be 'generic' or 'aws'") createSourceBucketCmd.Flags().Var(&sourceBucketProvider, "provider", sourceBucketProvider.Description())
createSourceBucketCmd.Flags().StringVar(&sourceBucketName, "bucket-name", "", "the bucket name") createSourceBucketCmd.Flags().StringVar(&sourceBucketName, "bucket-name", "", "the bucket name")
createSourceBucketCmd.Flags().StringVar(&sourceBucketEndpoint, "endpoint", "", "the bucket endpoint address") createSourceBucketCmd.Flags().StringVar(&sourceBucketEndpoint, "endpoint", "", "the bucket endpoint address")
createSourceBucketCmd.Flags().StringVar(&sourceBucketAccessKey, "access-key", "", "the bucket access key") createSourceBucketCmd.Flags().StringVar(&sourceBucketAccessKey, "access-key", "", "the bucket access key")
createSourceBucketCmd.Flags().StringVar(&sourceBucketSecretKey, "secret-key", "", "the bucket secret key") createSourceBucketCmd.Flags().StringVar(&sourceBucketSecretKey, "secret-key", "", "the bucket secret key")
createSourceBucketCmd.Flags().StringVar(&sourceBucketRegion, "region", "", "the bucket region") createSourceBucketCmd.Flags().StringVar(&sourceBucketRegion, "region", "", "the bucket region")
createSourceBucketCmd.Flags().BoolVar(&sourceBucketInsecure, "insecure", false, "for when connecting to a non-TLS S3 HTTP endpoint") createSourceBucketCmd.Flags().BoolVar(&sourceBucketInsecure, "insecure", false, "for when connecting to a non-TLS S3 HTTP endpoint")
createSourceBucketCmd.Flags().StringVar(&sourceBucketSecretRef, "secret-ref", "", "the name of an existing secret containing credentials")
createSourceCmd.AddCommand(createSourceBucketCmd) createSourceCmd.AddCommand(createSourceBucketCmd)
} }
@@ -86,12 +90,6 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("Bucket source name is required") return fmt.Errorf("Bucket source name is required")
} }
name := args[0] name := args[0]
secretName := fmt.Sprintf("bucket-%s", name)
if !utils.containsItemString(supportedSourceBucketProviders, sourceBucketProvider) {
return fmt.Errorf("Bucket provider %s is not supported, can be %v",
sourceBucketProvider, supportedSourceBucketProviders)
}
if sourceBucketName == "" { if sourceBucketName == "" {
return fmt.Errorf("bucket-name is required") return fmt.Errorf("bucket-name is required")
@@ -120,7 +118,7 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
}, },
Spec: sourcev1.BucketSpec{ Spec: sourcev1.BucketSpec{
BucketName: sourceBucketName, BucketName: sourceBucketName,
Provider: sourceBucketProvider, Provider: sourceBucketProvider.String(),
Insecure: sourceBucketInsecure, Insecure: sourceBucketInsecure,
Endpoint: sourceBucketEndpoint, Endpoint: sourceBucketEndpoint,
Region: sourceBucketRegion, Region: sourceBucketRegion,
@@ -129,6 +127,11 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
}, },
}, },
} }
if sourceHelmSecretRef != "" {
bucket.Spec.SecretRef = &corev1.LocalObjectReference{
Name: sourceBucketSecretRef,
}
}
if export { if export {
return exportBucket(*bucket) return exportBucket(*bucket)
@@ -137,35 +140,39 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
logger.Generatef("generating Bucket source") logger.Generatef("generating Bucket source")
secret := corev1.Secret{ if sourceBucketSecretRef == "" {
ObjectMeta: metav1.ObjectMeta{ secretName := fmt.Sprintf("bucket-%s", name)
Name: secretName,
Namespace: namespace,
},
StringData: map[string]string{},
}
if sourceBucketAccessKey != "" && sourceBucketSecretKey != "" { secret := corev1.Secret{
secret.StringData["accesskey"] = sourceBucketAccessKey ObjectMeta: metav1.ObjectMeta{
secret.StringData["secretkey"] = sourceBucketSecretKey Name: secretName,
} Namespace: namespace,
},
StringData: map[string]string{},
}
if len(secret.StringData) > 0 { if sourceBucketAccessKey != "" && sourceBucketSecretKey != "" {
logger.Actionf("applying secret with the bucket credentials") secret.StringData["accesskey"] = sourceBucketAccessKey
if err := upsertSecret(ctx, kubeClient, secret); err != nil { secret.StringData["secretkey"] = sourceBucketSecretKey
return err
} }
bucket.Spec.SecretRef = &corev1.LocalObjectReference{
Name: secretName, if len(secret.StringData) > 0 {
logger.Actionf("applying secret with the bucket credentials")
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
return err
}
bucket.Spec.SecretRef = &corev1.LocalObjectReference{
Name: secretName,
}
logger.Successf("authentication configured")
} }
logger.Successf("authentication configured")
} }
logger.Actionf("applying Bucket source") logger.Actionf("applying Bucket source")

View File

@@ -20,12 +20,15 @@ import (
"context" "context"
"crypto/elliptic" "crypto/elliptic"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta"
"io/ioutil" "io/ioutil"
"net/url" "net/url"
"os" "os"
"time" "time"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/flags"
"github.com/fluxcd/toolkit/internal/utils"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/manifoldco/promptui" "github.com/manifoldco/promptui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -84,15 +87,17 @@ For private Git repositories, the basic authentication credentials are stored in
} }
var ( var (
sourceGitURL string sourceGitURL string
sourceGitBranch string sourceGitBranch string
sourceGitTag string sourceGitTag string
sourceGitSemver string sourceGitSemver string
sourceGitUsername string sourceGitUsername string
sourceGitPassword string sourceGitPassword string
sourceGitKeyAlgorithm PublicKeyAlgorithm = "rsa"
sourceGitRSABits RSAKeyBits = 2048 sourceGitKeyAlgorithm flags.PublicKeyAlgorithm = "rsa"
sourceGitECDSACurve = ECDSACurve{elliptic.P384()} sourceGitRSABits flags.RSAKeyBits = 2048
sourceGitECDSACurve = flags.ECDSACurve{Curve: elliptic.P384()}
sourceGitSecretRef string
) )
func init() { func init() {
@@ -105,6 +110,7 @@ func init() {
createSourceGitCmd.Flags().Var(&sourceGitKeyAlgorithm, "ssh-key-algorithm", sourceGitKeyAlgorithm.Description()) createSourceGitCmd.Flags().Var(&sourceGitKeyAlgorithm, "ssh-key-algorithm", sourceGitKeyAlgorithm.Description())
createSourceGitCmd.Flags().Var(&sourceGitRSABits, "ssh-rsa-bits", sourceGitRSABits.Description()) createSourceGitCmd.Flags().Var(&sourceGitRSABits, "ssh-rsa-bits", sourceGitRSABits.Description())
createSourceGitCmd.Flags().Var(&sourceGitECDSACurve, "ssh-ecdsa-curve", sourceGitECDSACurve.Description()) createSourceGitCmd.Flags().Var(&sourceGitECDSACurve, "ssh-ecdsa-curve", sourceGitECDSACurve.Description())
createSourceGitCmd.Flags().StringVarP(&sourceGitSecretRef, "secret-ref", "", "", "the name of an existing secret containing SSH or basic credentials")
createSourceCmd.AddCommand(createSourceGitCmd) createSourceCmd.AddCommand(createSourceGitCmd)
} }
@@ -159,20 +165,27 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
} }
if export { if export {
if sourceGitSecretRef != "" {
gitRepository.Spec.SecretRef = &corev1.LocalObjectReference{
Name: sourceGitSecretRef,
}
}
return exportGit(gitRepository) return exportGit(gitRepository)
} }
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
withAuth := false withAuth := false
// TODO(hidde): move all auth prep to separate func? // TODO(hidde): move all auth prep to separate func?
if u.Scheme == "ssh" { if sourceGitSecretRef != "" {
withAuth = true
} else if u.Scheme == "ssh" {
logger.Actionf("generating deploy key pair") logger.Actionf("generating deploy key pair")
pair, err := generateKeyPair(ctx) pair, err := generateKeyPair(ctx)
if err != nil { if err != nil {
@@ -237,8 +250,12 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
logger.Generatef("generating GitRepository source") logger.Generatef("generating GitRepository source")
if withAuth { if withAuth {
secretName := name
if sourceGitSecretRef != "" {
secretName = sourceGitSecretRef
}
gitRepository.Spec.SecretRef = &corev1.LocalObjectReference{ gitRepository.Spec.SecretRef = &corev1.LocalObjectReference{
Name: name, Name: secretName,
} }
} }

View File

@@ -32,6 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var createSourceHelmCmd = &cobra.Command{ var createSourceHelmCmd = &cobra.Command{
@@ -62,12 +63,13 @@ For private Helm repositories, the basic authentication credentials are stored i
} }
var ( var (
sourceHelmURL string sourceHelmURL string
sourceHelmUsername string sourceHelmUsername string
sourceHelmPassword string sourceHelmPassword string
sourceHelmCertFile string sourceHelmCertFile string
sourceHelmKeyFile string sourceHelmKeyFile string
sourceHelmCAFile string sourceHelmCAFile string
sourceHelmSecretRef string
) )
func init() { func init() {
@@ -77,6 +79,7 @@ func init() {
createSourceHelmCmd.Flags().StringVar(&sourceHelmCertFile, "cert-file", "", "TLS authentication cert file path") createSourceHelmCmd.Flags().StringVar(&sourceHelmCertFile, "cert-file", "", "TLS authentication cert file path")
createSourceHelmCmd.Flags().StringVar(&sourceHelmKeyFile, "key-file", "", "TLS authentication key file path") createSourceHelmCmd.Flags().StringVar(&sourceHelmKeyFile, "key-file", "", "TLS authentication key file path")
createSourceHelmCmd.Flags().StringVar(&sourceHelmCAFile, "ca-file", "", "TLS authentication CA file path") createSourceHelmCmd.Flags().StringVar(&sourceHelmCAFile, "ca-file", "", "TLS authentication CA file path")
createSourceHelmCmd.Flags().StringVarP(&sourceHelmSecretRef, "secret-ref", "", "", "the name of an existing secret containing TLS or basic auth credentials")
createSourceCmd.AddCommand(createSourceHelmCmd) createSourceCmd.AddCommand(createSourceHelmCmd)
} }
@@ -86,7 +89,6 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("HelmRepository source name is required") return fmt.Errorf("HelmRepository source name is required")
} }
name := args[0] name := args[0]
secretName := fmt.Sprintf("helm-%s", name)
if sourceHelmURL == "" { if sourceHelmURL == "" {
return fmt.Errorf("url is required") return fmt.Errorf("url is required")
@@ -121,6 +123,12 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
}, },
} }
if sourceHelmSecretRef != "" {
helmRepository.Spec.SecretRef = &corev1.LocalObjectReference{
Name: sourceHelmSecretRef,
}
}
if export { if export {
return exportHelmRepository(*helmRepository) return exportHelmRepository(*helmRepository)
} }
@@ -128,57 +136,60 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
logger.Generatef("generating HelmRepository source") logger.Generatef("generating HelmRepository source")
if sourceHelmSecretRef == "" {
secretName := fmt.Sprintf("helm-%s", name)
secret := corev1.Secret{ secret := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: secretName, Name: secretName,
Namespace: namespace, Namespace: namespace,
}, },
StringData: map[string]string{}, StringData: map[string]string{},
}
if sourceHelmUsername != "" && sourceHelmPassword != "" {
secret.StringData["username"] = sourceHelmUsername
secret.StringData["password"] = sourceHelmPassword
}
if sourceHelmCertFile != "" && sourceHelmKeyFile != "" {
cert, err := ioutil.ReadFile(sourceHelmCertFile)
if err != nil {
return fmt.Errorf("failed to read repository cert file '%s': %w", sourceHelmCertFile, err)
} }
secret.StringData["certFile"] = string(cert)
key, err := ioutil.ReadFile(sourceHelmKeyFile) if sourceHelmUsername != "" && sourceHelmPassword != "" {
if err != nil { secret.StringData["username"] = sourceHelmUsername
return fmt.Errorf("failed to read repository key file '%s': %w", sourceHelmKeyFile, err) secret.StringData["password"] = sourceHelmPassword
} }
secret.StringData["keyFile"] = string(key)
}
if sourceHelmCAFile != "" { if sourceHelmCertFile != "" && sourceHelmKeyFile != "" {
ca, err := ioutil.ReadFile(sourceHelmCAFile) cert, err := ioutil.ReadFile(sourceHelmCertFile)
if err != nil { if err != nil {
return fmt.Errorf("failed to read repository CA file '%s': %w", sourceHelmCAFile, err) return fmt.Errorf("failed to read repository cert file '%s': %w", sourceHelmCertFile, err)
} }
secret.StringData["caFile"] = string(ca) secret.StringData["certFile"] = string(cert)
}
if len(secret.StringData) > 0 { key, err := ioutil.ReadFile(sourceHelmKeyFile)
logger.Actionf("applying secret with repository credentials") if err != nil {
if err := upsertSecret(ctx, kubeClient, secret); err != nil { return fmt.Errorf("failed to read repository key file '%s': %w", sourceHelmKeyFile, err)
return err }
secret.StringData["keyFile"] = string(key)
} }
helmRepository.Spec.SecretRef = &corev1.LocalObjectReference{
Name: secretName, if sourceHelmCAFile != "" {
ca, err := ioutil.ReadFile(sourceHelmCAFile)
if err != nil {
return fmt.Errorf("failed to read repository CA file '%s': %w", sourceHelmCAFile, err)
}
secret.StringData["caFile"] = string(ca)
}
if len(secret.StringData) > 0 {
logger.Actionf("applying secret with repository credentials")
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
return err
}
helmRepository.Spec.SecretRef = &corev1.LocalObjectReference{
Name: secretName,
}
logger.Successf("authentication configured")
} }
logger.Successf("authentication configured")
} }
logger.Actionf("applying HelmRepository source") logger.Actionf("applying HelmRepository source")

View File

@@ -21,6 +21,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1" rbacv1 "k8s.io/api/rbac/v1"
@@ -144,7 +145,7 @@ func createTenantCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var deleteAlertCmd = &cobra.Command{ var deleteAlertCmd = &cobra.Command{
@@ -50,7 +51,7 @@ func deleteAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var deleteAlertProviderCmd = &cobra.Command{ var deleteAlertProviderCmd = &cobra.Command{
@@ -50,7 +51,7 @@ func deleteAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1" helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var deleteHelmReleaseCmd = &cobra.Command{ var deleteHelmReleaseCmd = &cobra.Command{
@@ -51,7 +52,7 @@ func deleteHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -21,6 +21,7 @@ import (
"fmt" "fmt"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/manifoldco/promptui" "github.com/manifoldco/promptui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
@@ -50,7 +51,7 @@ func deleteKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var deleteReceiverCmd = &cobra.Command{ var deleteReceiverCmd = &cobra.Command{
@@ -50,7 +51,7 @@ func deleteReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -21,6 +21,7 @@ import (
"fmt" "fmt"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/manifoldco/promptui" "github.com/manifoldco/promptui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
@@ -49,7 +50,7 @@ func deleteSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -21,6 +21,7 @@ import (
"fmt" "fmt"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/manifoldco/promptui" "github.com/manifoldco/promptui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
@@ -49,7 +50,7 @@ func deleteSourceGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -21,6 +21,7 @@ import (
"fmt" "fmt"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/manifoldco/promptui" "github.com/manifoldco/promptui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
@@ -49,7 +50,7 @@ func deleteSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -27,6 +27,7 @@ import (
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var exportAlertCmd = &cobra.Command{ var exportAlertCmd = &cobra.Command{
@@ -54,7 +55,7 @@ func exportAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -27,6 +27,7 @@ import (
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var exportAlertProviderCmd = &cobra.Command{ var exportAlertProviderCmd = &cobra.Command{
@@ -54,7 +55,7 @@ func exportAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -27,6 +27,7 @@ import (
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1" helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var exportHelmReleaseCmd = &cobra.Command{ var exportHelmReleaseCmd = &cobra.Command{
@@ -55,7 +56,7 @@ func exportHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -27,6 +27,7 @@ import (
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var exportKsCmd = &cobra.Command{ var exportKsCmd = &cobra.Command{
@@ -55,7 +56,7 @@ func exportKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -27,6 +27,7 @@ import (
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var exportReceiverCmd = &cobra.Command{ var exportReceiverCmd = &cobra.Command{
@@ -54,7 +55,7 @@ func exportReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -28,6 +28,7 @@ import (
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var exportSourceBucketCmd = &cobra.Command{ var exportSourceBucketCmd = &cobra.Command{
@@ -55,7 +56,7 @@ func exportSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -28,6 +28,7 @@ import (
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var exportSourceGitCmd = &cobra.Command{ var exportSourceGitCmd = &cobra.Command{
@@ -55,7 +56,7 @@ func exportSourceGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -28,6 +28,7 @@ import (
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var exportSourceHelmCmd = &cobra.Command{ var exportSourceHelmCmd = &cobra.Command{
@@ -55,7 +56,7 @@ func exportSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -28,6 +28,7 @@ import (
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
) )
var getAlertCmd = &cobra.Command{ var getAlertCmd = &cobra.Command{
@@ -48,7 +49,7 @@ func getAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
@@ -97,6 +98,6 @@ func getAlertCmdRun(cmd *cobra.Command, args []string) error {
} }
rows = append(rows, row) rows = append(rows, row)
} }
utils.printTable(os.Stdout, header, rows) utils.PrintTable(os.Stdout, header, rows)
return nil return nil
} }

View File

@@ -26,6 +26,7 @@ import (
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
) )
var getAlertProviderCmd = &cobra.Command{ var getAlertProviderCmd = &cobra.Command{
@@ -46,7 +47,7 @@ func getAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
@@ -91,6 +92,6 @@ func getAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
} }
rows = append(rows, row) rows = append(rows, row)
} }
utils.printTable(os.Stdout, header, rows) utils.PrintTable(os.Stdout, header, rows)
return nil return nil
} }

View File

@@ -23,6 +23,7 @@ import (
"strings" "strings"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@@ -50,7 +51,7 @@ func getHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
@@ -99,6 +100,6 @@ func getHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
} }
rows = append(rows, row) rows = append(rows, row)
} }
utils.printTable(os.Stdout, header, rows) utils.PrintTable(os.Stdout, header, rows)
return nil return nil
} }

View File

@@ -23,6 +23,7 @@ import (
"strings" "strings"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -49,7 +50,7 @@ func getKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
@@ -98,6 +99,6 @@ func getKsCmdRun(cmd *cobra.Command, args []string) error {
} }
rows = append(rows, row) rows = append(rows, row)
} }
utils.printTable(os.Stdout, header, rows) utils.PrintTable(os.Stdout, header, rows)
return nil return nil
} }

View File

@@ -28,6 +28,7 @@ import (
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
) )
var getReceiverCmd = &cobra.Command{ var getReceiverCmd = &cobra.Command{
@@ -48,7 +49,7 @@ func getReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
@@ -92,6 +93,6 @@ func getReceiverCmdRun(cmd *cobra.Command, args []string) error {
} }
rows = append(rows, row) rows = append(rows, row)
} }
utils.printTable(os.Stdout, header, rows) utils.PrintTable(os.Stdout, header, rows)
return nil return nil
} }

View File

@@ -21,6 +21,7 @@ import (
"os" "os"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -46,7 +47,7 @@ func getSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
@@ -97,6 +98,6 @@ func getSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
} }
rows = append(rows, row) rows = append(rows, row)
} }
utils.printTable(os.Stdout, header, rows) utils.PrintTable(os.Stdout, header, rows)
return nil return nil
} }

View File

@@ -21,6 +21,7 @@ import (
"os" "os"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -46,7 +47,7 @@ func getSourceGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
@@ -97,6 +98,6 @@ func getSourceGitCmdRun(cmd *cobra.Command, args []string) error {
} }
rows = append(rows, row) rows = append(rows, row)
} }
utils.printTable(os.Stdout, header, rows) utils.PrintTable(os.Stdout, header, rows)
return nil return nil
} }

View File

@@ -21,6 +21,7 @@ import (
"os" "os"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -46,7 +47,7 @@ func getSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
@@ -97,6 +98,6 @@ func getSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
} }
rows = append(rows, row) rows = append(rows, row)
} }
utils.printTable(os.Stdout, header, rows) utils.PrintTable(os.Stdout, header, rows)
return nil return nil
} }

View File

@@ -26,6 +26,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/fluxcd/toolkit/internal/flags"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/fluxcd/toolkit/pkg/install" "github.com/fluxcd/toolkit/pkg/install"
) )
@@ -57,10 +59,10 @@ var (
installComponents []string installComponents []string
installRegistry string installRegistry string
installImagePullSecret string installImagePullSecret string
installArch string installArch flags.Arch = "amd64"
installWatchAllNamespaces bool installWatchAllNamespaces bool
installNetworkPolicy bool installNetworkPolicy bool
installLogLevel string installLogLevel flags.LogLevel = "info"
) )
func init() { func init() {
@@ -78,25 +80,16 @@ func init() {
"container registry where the toolkit images are published") "container registry where the toolkit images are published")
installCmd.Flags().StringVar(&installImagePullSecret, "image-pull-secret", "", installCmd.Flags().StringVar(&installImagePullSecret, "image-pull-secret", "",
"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().Var(&installArch, "arch", installArch.Description())
"arch can be amd64 or arm64")
installCmd.Flags().BoolVar(&installWatchAllNamespaces, "watch-all-namespaces", true, 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") "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") installCmd.Flags().Var(&installLogLevel, "log-level", installLogLevel.Description())
installCmd.Flags().BoolVar(&installNetworkPolicy, "network-policy", true, installCmd.Flags().BoolVar(&installNetworkPolicy, "network-policy", true,
"deny ingress access to the toolkit controllers from other namespaces using network policies") "deny ingress access to the toolkit controllers from other namespaces using network policies")
rootCmd.AddCommand(installCmd) rootCmd.AddCommand(installCmd)
} }
func installCmdRun(cmd *cobra.Command, args []string) error { func installCmdRun(cmd *cobra.Command, args []string) error {
if !utils.containsItemString(supportedArch, installArch) {
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) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
@@ -117,10 +110,10 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
Components: installComponents, Components: installComponents,
Registry: installRegistry, Registry: installRegistry,
ImagePullSecret: installImagePullSecret, ImagePullSecret: installImagePullSecret,
Arch: installArch, Arch: installArch.String(),
WatchAllNamespaces: installWatchAllNamespaces, WatchAllNamespaces: installWatchAllNamespaces,
NetworkPolicy: installNetworkPolicy, NetworkPolicy: installNetworkPolicy,
LogLevel: installLogLevel, LogLevel: installLogLevel.String(),
NotificationController: defaultNotification, NotificationController: defaultNotification,
ManifestsFile: fmt.Sprintf("%s.yaml", namespace), ManifestsFile: fmt.Sprintf("%s.yaml", namespace),
Timeout: timeout, Timeout: timeout,
@@ -154,17 +147,17 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
logger.Successf("manifests build completed") logger.Successf("manifests build completed")
logger.Actionf("installing components in %s namespace", namespace) logger.Actionf("installing components in %s namespace", namespace)
applyOutput := ModeStderrOS applyOutput := utils.ModeStderrOS
if verbose { if verbose {
applyOutput = ModeOS applyOutput = utils.ModeOS
} }
kubectlArgs := []string{"apply", "-f", manifest} kubectlArgs := []string{"apply", "-f", manifest}
if installDryRun { if installDryRun {
args = append(args, "--dry-run=client") args = append(args, "--dry-run=client")
applyOutput = ModeOS applyOutput = utils.ModeOS
} }
if _, err := utils.execKubectlCommand(ctx, applyOutput, kubectlArgs...); err != nil { if _, err := utils.ExecKubectlCommand(ctx, applyOutput, kubectlArgs...); err != nil {
return fmt.Errorf("install failed") return fmt.Errorf("install failed")
} }
@@ -178,7 +171,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
logger.Waitingf("verifying installation") logger.Waitingf("verifying installation")
for _, deployment := range installComponents { for _, deployment := range installComponents {
kubectlArgs = []string{"-n", namespace, "rollout", "status", "deployment", deployment, "--timeout", timeout.String()} kubectlArgs = []string{"-n", namespace, "rollout", "status", "deployment", deployment, "--timeout", timeout.String()}
if _, err := utils.execKubectlCommand(ctx, applyOutput, kubectlArgs...); err != nil { if _, err := utils.ExecKubectlCommand(ctx, applyOutput, kubectlArgs...); err != nil {
return fmt.Errorf("install failed") return fmt.Errorf("install failed")
} else { } else {
logger.Successf("%s ready", deployment) logger.Successf("%s ready", deployment)

View File

@@ -26,8 +26,6 @@ import (
"github.com/spf13/cobra/doc" "github.com/spf13/cobra/doc"
_ "k8s.io/client-go/plugin/pkg/client/auth" _ "k8s.io/client-go/plugin/pkg/client/auth"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
gotklog "github.com/fluxcd/toolkit/pkg/log" gotklog "github.com/fluxcd/toolkit/pkg/log"
) )
@@ -100,22 +98,15 @@ var (
namespace string namespace string
timeout time.Duration timeout time.Duration
verbose bool verbose bool
utils Utils
pollInterval = 2 * time.Second pollInterval = 2 * time.Second
logger gotklog.Logger = printLogger{} logger gotklog.Logger = printLogger{}
) )
var ( var (
defaultComponents = []string{"source-controller", "kustomize-controller", "helm-controller", "notification-controller"} defaultComponents = []string{"source-controller", "kustomize-controller", "helm-controller", "notification-controller"}
defaultVersion = "latest" defaultVersion = "latest"
defaultNamespace = "gotk-system" defaultNamespace = "gotk-system"
defaultNotification = "notification-controller" defaultNotification = "notification-controller"
supportedLogLevels = []string{"debug", "info", "error"}
supportedArch = []string{"amd64", "arm", "arm64"}
supportedDecryptionProviders = []string{"sops"}
supportedKustomizationSourceKinds = []string{sourcev1.GitRepositoryKind, sourcev1.BucketKind}
supportedHelmChartSourceKinds = []string{sourcev1.HelmRepositoryKind, sourcev1.GitRepositoryKind, sourcev1.BucketKind}
supportedSourceBucketProviders = []string{sourcev1.GenericBucketProvider, sourcev1.AmazonBucketProvider}
) )
func init() { func init() {

View File

@@ -19,9 +19,11 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta"
"time" "time"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
@@ -52,7 +54,7 @@ func reconcileAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,9 +19,11 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta"
"time" "time"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
@@ -52,7 +54,7 @@ func reconcileAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -29,6 +29,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1" helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
@@ -68,7 +69,7 @@ func reconcileHrCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -26,6 +26,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
@@ -68,7 +69,7 @@ func reconcileKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,9 +19,11 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta"
"time" "time"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
@@ -52,7 +54,7 @@ func reconcileReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,9 +19,11 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta"
"time" "time"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
@@ -54,7 +56,7 @@ func reconcileSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,9 +19,11 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta"
"time" "time"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
@@ -52,7 +54,7 @@ func reconcileSourceGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,9 +19,11 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta"
"time" "time"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
@@ -54,7 +56,7 @@ func reconcileSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,7 +19,9 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@@ -54,7 +56,7 @@ func resumeAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,7 +19,9 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@@ -55,7 +57,7 @@ func resumeHrCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,7 +19,9 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -54,7 +56,7 @@ func resumeKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,7 +19,9 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@@ -54,7 +56,7 @@ func resumeReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var suspendAlertCmd = &cobra.Command{ var suspendAlertCmd = &cobra.Command{
@@ -49,7 +50,7 @@ func suspendAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1" helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var suspendHrCmd = &cobra.Command{ var suspendHrCmd = &cobra.Command{
@@ -50,7 +51,7 @@ func suspendHrCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,7 +19,9 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
) )
@@ -48,7 +50,7 @@ func suspendKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var suspendReceiverCmd = &cobra.Command{ var suspendReceiverCmd = &cobra.Command{
@@ -49,7 +50,7 @@ func suspendReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -27,6 +27,7 @@ import (
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1" helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
) )
var uninstallCmd = &cobra.Command{ var uninstallCmd = &cobra.Command{
@@ -66,7 +67,7 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.KubeClient(kubeconfig)
if err != nil { if err != nil {
return err return err
} }
@@ -111,7 +112,7 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
if uninstallDryRun { if uninstallDryRun {
kubectlArgs = append(kubectlArgs, dryRun) kubectlArgs = append(kubectlArgs, dryRun)
} }
if _, err := utils.execKubectlCommand(ctx, ModeOS, kubectlArgs...); err != nil { if _, err := utils.ExecKubectlCommand(ctx, utils.ModeOS, kubectlArgs...); err != nil {
return fmt.Errorf("uninstall failed: %w", err) return fmt.Errorf("uninstall failed: %w", err)
} }
} }
@@ -135,7 +136,7 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
if uninstallDryRun { if uninstallDryRun {
kubectlArgs = append(kubectlArgs, dryRun) kubectlArgs = append(kubectlArgs, dryRun)
} }
if _, err := utils.execKubectlCommand(ctx, ModeOS, kubectlArgs...); err != nil { if _, err := utils.ExecKubectlCommand(ctx, utils.ModeOS, kubectlArgs...); err != nil {
return fmt.Errorf("uninstall failed: %w", err) return fmt.Errorf("uninstall failed: %w", err)
} }
} }

View File

@@ -9,12 +9,12 @@ The bootstrap sub-commands bootstrap the toolkit components on the targeted Git
### Options ### Options
``` ```
--arch string arch can be amd64 or arm64 (default "amd64") --arch arch cluster architecture, available options are: (amd64, arm, arm64) (default amd64)
--branch string default branch (for GitHub this must match the default branch setting for the organization) (default "main") --branch string default branch (for GitHub this must match the default branch setting for the organization) (default "main")
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
-h, --help help for bootstrap -h, --help help for bootstrap
--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
--log-level string set the controllers log level (default "info") --log-level logLevel log level, available options are: (debug, info, error) (default info)
--network-policy deny ingress access to the toolkit controllers from other namespaces using network policies (default true) --network-policy deny ingress access to the toolkit controllers from other namespaces using network policies (default true)
--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")

View File

@@ -57,12 +57,12 @@ gotk bootstrap github [flags]
### Options inherited from parent commands ### Options inherited from parent commands
``` ```
--arch string arch can be amd64 or arm64 (default "amd64") --arch arch cluster architecture, available options are: (amd64, arm, arm64) (default amd64)
--branch string default branch (for GitHub this must match the default branch setting for the organization) (default "main") --branch string default branch (for GitHub this must match the default branch setting for the organization) (default "main")
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --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 --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") --kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--log-level string set the controllers log level (default "info") --log-level logLevel log level, available options are: (debug, info, error) (default info)
-n, --namespace string the namespace scope for this operation (default "gotk-system") -n, --namespace string the namespace scope for this operation (default "gotk-system")
--network-policy deny ingress access to the toolkit controllers from other namespaces using network policies (default true) --network-policy deny ingress access to the toolkit controllers from other namespaces using network policies (default true)
--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")

View File

@@ -57,12 +57,12 @@ gotk bootstrap gitlab [flags]
### Options inherited from parent commands ### Options inherited from parent commands
``` ```
--arch string arch can be amd64 or arm64 (default "amd64") --arch arch cluster architecture, available options are: (amd64, arm, arm64) (default amd64)
--branch string default branch (for GitHub this must match the default branch setting for the organization) (default "main") --branch string default branch (for GitHub this must match the default branch setting for the organization) (default "main")
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --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 --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") --kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--log-level string set the controllers log level (default "info") --log-level logLevel log level, available options are: (debug, info, error) (default info)
-n, --namespace string the namespace scope for this operation (default "gotk-system") -n, --namespace string the namespace scope for this operation (default "gotk-system")
--network-policy deny ingress access to the toolkit controllers from other namespaces using network policies (default true) --network-policy deny ingress access to the toolkit controllers from other namespaces using network policies (default true)
--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")

View File

@@ -67,7 +67,7 @@ gotk create helmrelease [name] [flags]
--depends-on stringArray HelmReleases that must be ready before this release can be installed, supported formats '<name>' and '<namespace>/<name>' --depends-on stringArray HelmReleases that must be ready before this release can be installed, supported formats '<name>' and '<namespace>/<name>'
-h, --help help for helmrelease -h, --help help for helmrelease
--release-name string name used for the Helm release, defaults to a composition of '[<target-namespace>-]<HelmRelease-name>' --release-name string name used for the Helm release, defaults to a composition of '[<target-namespace>-]<HelmRelease-name>'
--source string source that contains the chart (<kind>/<name>) --source helmChartSource source that contains the chart in the format '<kind>/<name>',where kind can be one of: (HelmRepository, GitRepository, Bucket)
--target-namespace string namespace to install this release, defaults to the HelmRelease namespace --target-namespace string namespace to install this release, defaults to the HelmRelease namespace
--values string local path to the values.yaml file --values string local path to the values.yaml file
``` ```

View File

@@ -44,18 +44,18 @@ gotk create kustomization [name] [flags]
### Options ### Options
``` ```
--decryption-provider string enables secrets decryption, provider can be 'sops' --decryption-provider decryptionProvider decryption provider, available options are: (sops)
--decryption-secret string set the Kubernetes secret name that contains the OpenPGP private keys used for sops decryption --decryption-secret string set the Kubernetes secret name that contains the OpenPGP private keys used for sops decryption
--depends-on stringArray Kustomization that must be ready before this Kustomization can be applied, supported formats '<name>' and '<namespace>/<name>' --depends-on stringArray Kustomization that must be ready before this Kustomization can be applied, supported formats '<name>' and '<namespace>/<name>'
--health-check stringArray workload to be included in the health assessment, in the format '<kind>/<name>.<namespace>' --health-check stringArray workload to be included in the health assessment, in the format '<kind>/<name>.<namespace>'
--health-check-timeout duration timeout of health checking operations (default 2m0s) --health-check-timeout duration timeout of health checking operations (default 2m0s)
-h, --help help for kustomization -h, --help help for kustomization
--path string path to the directory containing the Kustomization file (default "./") --path string path to the directory containing the Kustomization file (default "./")
--prune enable garbage collection --prune enable garbage collection
--sa-name string service account name --sa-name string service account name
--sa-namespace string service account namespace --sa-namespace string service account namespace
--source string source that contains the Kubernetes manifests in the format '[<kind>/]<name>', where kind can be GitRepository or Bucket, if kind is not specified it defaults to GitRepository --source kustomizationSource source that contains the Kubernetes manifests in the format '[<kind>/]<name>',where kind can be one of: (GitRepository, Bucket), if kind is not specified it defaults to GitRepository
--validation string validate the manifests before applying them on the cluster, can be 'client' or 'server' --validation string validate the manifests before applying them on the cluster, can be 'client' or 'server'
``` ```
### Options inherited from parent commands ### Options inherited from parent commands

View File

@@ -37,14 +37,15 @@ gotk create source bucket [name] [flags]
### Options ### Options
``` ```
--access-key string the bucket access key --access-key string the bucket access key
--bucket-name string the bucket name --bucket-name string the bucket name
--endpoint string the bucket endpoint address --endpoint string the bucket endpoint address
-h, --help help for bucket -h, --help help for bucket
--insecure for when connecting to a non-TLS S3 HTTP endpoint --insecure for when connecting to a non-TLS S3 HTTP endpoint
--provider string the S3 compatible storage provider name, can be 'generic' or 'aws' (default "generic") --provider sourceBucketProvider the S3 compatible storage provider name, available options are: (generic, aws) (default generic)
--region string the bucket region --region string the bucket region
--secret-key string the bucket secret key --secret-key string the bucket secret key
--secret-ref string the name of an existing secret containing credentials
``` ```
### Options inherited from parent commands ### Options inherited from parent commands

View File

@@ -58,6 +58,7 @@ gotk create source git [name] [flags]
--branch string git branch (default "master") --branch string git branch (default "master")
-h, --help help for git -h, --help help for git
-p, --password string basic authentication password -p, --password string basic authentication password
--secret-ref string the name of an existing secret containing SSH or basic credentials
--ssh-ecdsa-curve ecdsaCurve SSH ECDSA public key curve (p256, p384, p521) (default p384) --ssh-ecdsa-curve ecdsaCurve SSH ECDSA public key curve (p256, p384, p521) (default p384)
--ssh-key-algorithm publicKeyAlgorithm SSH public key algorithm (rsa, ecdsa, ed25519) (default rsa) --ssh-key-algorithm publicKeyAlgorithm SSH public key algorithm (rsa, ecdsa, ed25519) (default rsa)
--ssh-rsa-bits rsaKeyBits SSH RSA public key bit size (multiplies of 8) (default 2048) --ssh-rsa-bits rsaKeyBits SSH RSA public key bit size (multiplies of 8) (default 2048)

View File

@@ -38,13 +38,14 @@ gotk create source helm [name] [flags]
### Options ### Options
``` ```
--ca-file string TLS authentication CA file path --ca-file string TLS authentication CA file path
--cert-file string TLS authentication cert file path --cert-file string TLS authentication cert file path
-h, --help help for helm -h, --help help for helm
--key-file string TLS authentication key file path --key-file string TLS authentication key file path
-p, --password string basic authentication password -p, --password string basic authentication password
--url string Helm repository address --secret-ref string the name of an existing secret containing TLS or basic auth credentials
-u, --username string basic authentication username --url string Helm repository address
-u, --username string basic authentication username
``` ```
### Options inherited from parent commands ### Options inherited from parent commands

View File

@@ -31,13 +31,13 @@ gotk install [flags]
### Options ### Options
``` ```
--arch string arch can be amd64 or arm64 (default "amd64") --arch arch cluster architecture, available options are: (amd64, arm, arm64) (default amd64)
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
--dry-run only print the object that would be applied --dry-run only print the object that would be applied
--export write the install manifests to stdout and exit --export write the install manifests to stdout and exit
-h, --help help for install -h, --help help for install
--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
--log-level string set the controllers log level (default "info") --log-level logLevel log level, available options are: (debug, info, error) (default info)
--network-policy deny ingress access to the toolkit controllers from other namespaces using network policies (default true) --network-policy deny ingress access to the toolkit controllers from other namespaces using network policies (default true)
--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")

View File

@@ -24,4 +24,4 @@ Features:
Links: Links:
- Source code [fluxcd/helm-controller](https://github.com/fluxcd/helm-controller) - Source code [fluxcd/helm-controller](https://github.com/fluxcd/helm-controller)
- Specification [docs](https://github.com/fluxcd/helm-controller/tree/master/docs/spec) - Specification [docs](https://github.com/fluxcd/helm-controller/tree/main/docs/spec)

View File

@@ -20,4 +20,4 @@ Features:
Links: Links:
- Source code [fluxcd/kustomize-controller](https://github.com/fluxcd/kustomize-controller) - Source code [fluxcd/kustomize-controller](https://github.com/fluxcd/kustomize-controller)
- Specification [docs](https://github.com/fluxcd/kustomize-controller/tree/master/docs/spec) - Specification [docs](https://github.com/fluxcd/kustomize-controller/tree/main/docs/spec)

View File

@@ -14,4 +14,4 @@ based on event severity and involved objects.
Links: Links:
- Source code [fluxcd/notification-controller](https://github.com/fluxcd/notification-controller) - Source code [fluxcd/notification-controller](https://github.com/fluxcd/notification-controller)
- Specification [docs](https://github.com/fluxcd/notification-controller/tree/master/docs/spec) - Specification [docs](https://github.com/fluxcd/notification-controller/tree/main/docs/spec)

View File

@@ -21,4 +21,4 @@ Features:
Links: Links:
- Source code [fluxcd/source-controller](https://github.com/fluxcd/source-controller) - Source code [fluxcd/source-controller](https://github.com/fluxcd/source-controller)
- Specification [docs](https://github.com/fluxcd/source-controller/tree/master/docs/spec) - Specification [docs](https://github.com/fluxcd/source-controller/tree/main/docs/spec)

View File

@@ -34,7 +34,8 @@ curl -s https://toolkit.fluxcd.io/install.sh | sudo bash
``` ```
The install script downloads the gotk binary to `/usr/local/bin`. The install script downloads the gotk binary to `/usr/local/bin`.
Binaries for macOS and Linux AMD64/ARM are available for download on the
Binaries for **macOS**, **Windows** and **Linux** AMD64/ARM are available for download on the
[release page](https://github.com/fluxcd/toolkit/releases). [release page](https://github.com/fluxcd/toolkit/releases).
To configure your shell to load gotk completions add to your Bash profile: To configure your shell to load gotk completions add to your Bash profile:

View File

@@ -29,7 +29,7 @@ curl -s https://toolkit.fluxcd.io/install.sh | sudo bash
Command-line completion for `zsh`, `fish`, and `powershell` Command-line completion for `zsh`, `fish`, and `powershell`
are also supported with their own sub-commands. are also supported with their own sub-commands.
Binaries for macOS and Linux AMD64/ARM are available for download on the Binaries for macOS, Windows and Linux AMD64/ARM are available for download on the
[release page](https://github.com/fluxcd/toolkit/releases). [release page](https://github.com/fluxcd/toolkit/releases).
Verify that your cluster satisfies the prerequisites with: Verify that your cluster satisfies the prerequisites with:

2
go.mod
View File

@@ -6,7 +6,7 @@ require (
github.com/blang/semver/v4 v4.0.0 github.com/blang/semver/v4 v4.0.0
github.com/fluxcd/helm-controller/api v0.1.3 github.com/fluxcd/helm-controller/api v0.1.3
github.com/fluxcd/kustomize-controller/api v0.1.2 github.com/fluxcd/kustomize-controller/api v0.1.2
github.com/fluxcd/notification-controller/api v0.1.1 github.com/fluxcd/notification-controller/api v0.1.2
github.com/fluxcd/pkg/apis/meta v0.0.2 github.com/fluxcd/pkg/apis/meta v0.0.2
github.com/fluxcd/pkg/git v0.0.7 github.com/fluxcd/pkg/git v0.0.7
github.com/fluxcd/pkg/runtime v0.1.0 github.com/fluxcd/pkg/runtime v0.1.0

4
go.sum
View File

@@ -115,8 +115,8 @@ github.com/fluxcd/helm-controller/api v0.1.3 h1:OztoSyxj5+2P38FRc9JXqnXP+f4eNQ0j
github.com/fluxcd/helm-controller/api v0.1.3/go.mod h1:eMkEzQrgDnOFa/iUey4VVjdqmPJFwcWb+3SFPDX9lJ0= github.com/fluxcd/helm-controller/api v0.1.3/go.mod h1:eMkEzQrgDnOFa/iUey4VVjdqmPJFwcWb+3SFPDX9lJ0=
github.com/fluxcd/kustomize-controller/api v0.1.2 h1:gocCnhlqTjzZy7DbTdA2QezFMdudfIXv5RRAP4D5lfc= github.com/fluxcd/kustomize-controller/api v0.1.2 h1:gocCnhlqTjzZy7DbTdA2QezFMdudfIXv5RRAP4D5lfc=
github.com/fluxcd/kustomize-controller/api v0.1.2/go.mod h1:MztOqUKfKn/CBzRofBMq/DAOjzQSoDTmFdIKR32BEQg= github.com/fluxcd/kustomize-controller/api v0.1.2/go.mod h1:MztOqUKfKn/CBzRofBMq/DAOjzQSoDTmFdIKR32BEQg=
github.com/fluxcd/notification-controller/api v0.1.1 h1:tu6+bi28vfHoSp2MUD9h42SIvqY+YtEwS9toH9k7cRA= github.com/fluxcd/notification-controller/api v0.1.2 h1:rxgjIWK19cr7cvbWKn68jPQJN+4SweiUss/IaNWA4DM=
github.com/fluxcd/notification-controller/api v0.1.1/go.mod h1:w1gILYTSqt3dFMYRmCihA/K84yDBfIkL5m5dcbaUyUY= github.com/fluxcd/notification-controller/api v0.1.2/go.mod h1:w1gILYTSqt3dFMYRmCihA/K84yDBfIkL5m5dcbaUyUY=
github.com/fluxcd/pkg/apis/meta v0.0.2 h1:kyA4Y0IzNjf1joBOnFqpWG7aNDHvtLExZcaHQM7qhRI= github.com/fluxcd/pkg/apis/meta v0.0.2 h1:kyA4Y0IzNjf1joBOnFqpWG7aNDHvtLExZcaHQM7qhRI=
github.com/fluxcd/pkg/apis/meta v0.0.2/go.mod h1:nCNps5JJOcEQr3MNDmZqI4o0chjePSUYL6Q2ktDtotU= github.com/fluxcd/pkg/apis/meta v0.0.2/go.mod h1:nCNps5JJOcEQr3MNDmZqI4o0chjePSUYL6Q2ktDtotU=
github.com/fluxcd/pkg/git v0.0.7 h1:tFSYPy7tcIYfOt8H5EUERXIRz7fk0id302oQZde1NtU= github.com/fluxcd/pkg/git v0.0.7 h1:tFSYPy7tcIYfOt8H5EUERXIRz7fk0id302oQZde1NtU=

54
internal/flags/arch.go Normal file
View File

@@ -0,0 +1,54 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flags
import (
"fmt"
"strings"
"github.com/fluxcd/toolkit/internal/utils"
)
var supportedArchs = []string{"amd64", "arm", "arm64"}
type Arch string
func (a *Arch) String() string {
return string(*a)
}
func (a *Arch) Set(str string) error {
if strings.TrimSpace(str) == "" {
return fmt.Errorf("no arch given, must be one of: %s",
strings.Join(supportedArchs, ", "))
}
if !utils.ContainsItemString(supportedArchs, str) {
return fmt.Errorf("unsupported arch '%s', must be one of: %s",
str, strings.Join(supportedArchs, ", "))
}
*a = Arch(str)
return nil
}
func (a *Arch) Type() string {
return "arch"
}
func (a *Arch) Description() string {
return fmt.Sprintf("cluster architecture, available options are: (%s)", strings.Join(supportedArchs, ", "))
}

View File

@@ -0,0 +1,50 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flags
import (
"fmt"
"strings"
"github.com/fluxcd/toolkit/internal/utils"
)
var supportedDecryptionProviders = []string{"sops"}
type DecryptionProvider string
func (d *DecryptionProvider) String() string {
return string(*d)
}
func (d *DecryptionProvider) Set(str string) error {
if !utils.ContainsItemString(supportedDecryptionProviders, str) {
return fmt.Errorf("unsupported decryption provider '%s', must be one of: %s",
str, strings.Join(supportedDecryptionProviders, ", "))
}
*d = DecryptionProvider(str)
return nil
}
func (d *DecryptionProvider) Type() string {
return "decryptionProvider"
}
func (d *DecryptionProvider) Description() string {
return fmt.Sprintf("decryption provider, available options are: (%s)", strings.Join(supportedDecryptionProviders, ", "))
}

View File

@@ -14,79 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package main package flags
import ( import (
"crypto/elliptic" "crypto/elliptic"
"fmt" "fmt"
"sort" "sort"
"strconv"
"strings" "strings"
) )
var supportedPublicKeyAlgorithms = []string{"rsa", "ecdsa", "ed25519"}
type PublicKeyAlgorithm string
func (a *PublicKeyAlgorithm) String() string {
return string(*a)
}
func (a *PublicKeyAlgorithm) Set(str string) error {
if strings.TrimSpace(str) == "" {
return fmt.Errorf("no public key algorithm given, must be one of: %s",
strings.Join(supportedPublicKeyAlgorithms, ", "))
}
for _, v := range supportedPublicKeyAlgorithms {
if str == v {
*a = PublicKeyAlgorithm(str)
return nil
}
}
return fmt.Errorf("unsupported public key algorithm '%s', must be one of: %s",
str, strings.Join(supportedPublicKeyAlgorithms, ", "))
}
func (a *PublicKeyAlgorithm) Type() string {
return "publicKeyAlgorithm"
}
func (a *PublicKeyAlgorithm) Description() string {
return fmt.Sprintf("SSH public key algorithm (%s)", strings.Join(supportedPublicKeyAlgorithms, ", "))
}
var defaultRSAKeyBits = 2048
type RSAKeyBits int
func (b *RSAKeyBits) String() string {
return strconv.Itoa(int(*b))
}
func (b *RSAKeyBits) Set(str string) error {
if strings.TrimSpace(str) == "" {
*b = RSAKeyBits(defaultRSAKeyBits)
return nil
}
bits, err := strconv.Atoi(str)
if err != nil {
return err
}
if bits%8 != 0 {
return fmt.Errorf("RSA key bit size should be a multiples of 8")
}
*b = RSAKeyBits(bits)
return nil
}
func (b *RSAKeyBits) Type() string {
return "rsaKeyBits"
}
func (b *RSAKeyBits) Description() string {
return "SSH RSA public key bit size (multiplies of 8)"
}
type ECDSACurve struct { type ECDSACurve struct {
elliptic.Curve elliptic.Curve
} }

View File

@@ -0,0 +1,72 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flags
import (
"fmt"
"strings"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
)
var supportedHelmChartSourceKinds = []string{sourcev1.HelmRepositoryKind, sourcev1.GitRepositoryKind, sourcev1.BucketKind}
type HelmChartSource struct {
Kind string
Name string
}
func (h *HelmChartSource) String() string {
if h.Name == "" {
return ""
}
return fmt.Sprintf("%s/%s", h.Kind, h.Name)
}
func (h *HelmChartSource) Set(str string) error {
if strings.TrimSpace(str) == "" {
return fmt.Errorf("no helm chart source given, please specify %s",
h.Description())
}
sourceKind, sourceName := utils.ParseObjectKindName(str)
if sourceKind == "" {
return fmt.Errorf("invalid helm chart source '%s', must be in format <kind>/<name>", str)
}
if !utils.ContainsItemString(supportedHelmChartSourceKinds, sourceKind) {
return fmt.Errorf("source kind '%s' is not supported, can be one of: %s",
sourceKind, strings.Join(supportedHelmChartSourceKinds, ", "))
}
h.Name = sourceName
h.Kind = sourceKind
return nil
}
func (h *HelmChartSource) Type() string {
return "helmChartSource"
}
func (h *HelmChartSource) Description() string {
return fmt.Sprintf(
"source that contains the chart in the format '<kind>/<name>',"+
"where kind can be one of: (%s)",
strings.Join(supportedHelmChartSourceKinds, ", "),
)
}

View File

@@ -0,0 +1,72 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flags
import (
"fmt"
"strings"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
)
var supportedKustomizationSourceKinds = []string{sourcev1.GitRepositoryKind, sourcev1.BucketKind}
type KustomizationSource struct {
Kind string
Name string
}
func (k *KustomizationSource) String() string {
if k.Name == "" {
return ""
}
return fmt.Sprintf("%s/%s", k.Kind, k.Name)
}
func (k *KustomizationSource) Set(str string) error {
if strings.TrimSpace(str) == "" {
return fmt.Errorf("no kustomization source given, please specify %s",
k.Description())
}
sourceKind, sourceName := utils.ParseObjectKindName(str)
if sourceKind == "" {
sourceKind = sourcev1.GitRepositoryKind
}
if !utils.ContainsItemString(supportedKustomizationSourceKinds, sourceKind) {
return fmt.Errorf("source kind '%s' is not supported, can be one of: %s",
sourceKind, strings.Join(supportedKustomizationSourceKinds, ", "))
}
k.Name = sourceName
k.Kind = sourceKind
return nil
}
func (k *KustomizationSource) Type() string {
return "kustomizationSource"
}
func (k *KustomizationSource) Description() string {
return fmt.Sprintf(
"source that contains the Kubernetes manifests in the format '[<kind>/]<name>',"+
"where kind can be one of: (%s), if kind is not specified it defaults to GitRepository",
strings.Join(supportedKustomizationSourceKinds, ", "),
)
}

View File

@@ -0,0 +1,54 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flags
import (
"fmt"
"strings"
"github.com/fluxcd/toolkit/internal/utils"
)
var supportedLogLevels = []string{"debug", "info", "error"}
type LogLevel string
func (l *LogLevel) String() string {
return string(*l)
}
func (l *LogLevel) Set(str string) error {
if strings.TrimSpace(str) == "" {
return fmt.Errorf("no log level given, must be one of: %s",
strings.Join(supportedLogLevels, ", "))
}
if !utils.ContainsItemString(supportedLogLevels, str) {
return fmt.Errorf("unsupported log level '%s', must be one of: %s",
str, strings.Join(supportedLogLevels, ", "))
}
*l = LogLevel(str)
return nil
}
func (l *LogLevel) Type() string {
return "logLevel"
}
func (l *LogLevel) Description() string {
return fmt.Sprintf("log level, available options are: (%s)", strings.Join(supportedLogLevels, ", "))
}

View File

@@ -0,0 +1,53 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flags
import (
"fmt"
"strings"
)
var supportedPublicKeyAlgorithms = []string{"rsa", "ecdsa", "ed25519"}
type PublicKeyAlgorithm string
func (a *PublicKeyAlgorithm) String() string {
return string(*a)
}
func (a *PublicKeyAlgorithm) Set(str string) error {
if strings.TrimSpace(str) == "" {
return fmt.Errorf("no public key algorithm given, must be one of: %s",
strings.Join(supportedPublicKeyAlgorithms, ", "))
}
for _, v := range supportedPublicKeyAlgorithms {
if str == v {
*a = PublicKeyAlgorithm(str)
return nil
}
}
return fmt.Errorf("unsupported public key algorithm '%s', must be one of: %s",
str, strings.Join(supportedPublicKeyAlgorithms, ", "))
}
func (a *PublicKeyAlgorithm) Type() string {
return "publicKeyAlgorithm"
}
func (a *PublicKeyAlgorithm) Description() string {
return fmt.Sprintf("SSH public key algorithm (%s)", strings.Join(supportedPublicKeyAlgorithms, ", "))
}

View File

@@ -0,0 +1,55 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flags
import (
"fmt"
"strconv"
"strings"
)
var defaultRSAKeyBits = 2048
type RSAKeyBits int
func (b *RSAKeyBits) String() string {
return strconv.Itoa(int(*b))
}
func (b *RSAKeyBits) Set(str string) error {
if strings.TrimSpace(str) == "" {
*b = RSAKeyBits(defaultRSAKeyBits)
return nil
}
bits, err := strconv.Atoi(str)
if err != nil {
return err
}
if bits%8 != 0 {
return fmt.Errorf("RSA key bit size should be a multiples of 8")
}
*b = RSAKeyBits(bits)
return nil
}
func (b *RSAKeyBits) Type() string {
return "rsaKeyBits"
}
func (b *RSAKeyBits) Description() string {
return "SSH RSA public key bit size (multiplies of 8)"
}

View File

@@ -0,0 +1,58 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flags
import (
"fmt"
"strings"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/toolkit/internal/utils"
)
var supportedSourceBucketProviders = []string{sourcev1.GenericBucketProvider, sourcev1.AmazonBucketProvider}
type SourceBucketProvider string
func (s *SourceBucketProvider) String() string {
return string(*s)
}
func (s *SourceBucketProvider) Set(str string) error {
if strings.TrimSpace(str) == "" {
return fmt.Errorf("no source bucket provider given, please specify %s",
s.Description())
}
if !utils.ContainsItemString(supportedSourceBucketProviders, str) {
return fmt.Errorf("source bucket provider '%s' is not supported, can be one of: %v",
str, strings.Join(supportedSourceBucketProviders, ", "))
}
return nil
}
func (s *SourceBucketProvider) Type() string {
return "sourceBucketProvider"
}
func (s *SourceBucketProvider) Description() string {
return fmt.Sprintf(
"the S3 compatible storage provider name, available options are: (%s)",
strings.Join(supportedSourceBucketProviders, ", "),
)
}

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package main package utils
import ( import (
"bufio" "bufio"
@@ -60,7 +60,7 @@ const (
ModeCapture ExecMode = "capture.stderr|stdout" ModeCapture ExecMode = "capture.stderr|stdout"
) )
func (*Utils) execKubectlCommand(ctx context.Context, mode ExecMode, args ...string) (string, error) { func ExecKubectlCommand(ctx context.Context, mode ExecMode, args ...string) (string, error) {
var stdoutBuf, stderrBuf bytes.Buffer var stdoutBuf, stderrBuf bytes.Buffer
c := exec.CommandContext(ctx, "kubectl", args...) c := exec.CommandContext(ctx, "kubectl", args...)
@@ -94,7 +94,7 @@ func (*Utils) execKubectlCommand(ctx context.Context, mode ExecMode, args ...str
return "", nil return "", nil
} }
func (*Utils) execTemplate(obj interface{}, tmpl, filename string) error { func ExecTemplate(obj interface{}, tmpl, filename string) error {
t, err := template.New("tmpl").Parse(tmpl) t, err := template.New("tmpl").Parse(tmpl)
if err != nil { if err != nil {
return err return err
@@ -124,8 +124,8 @@ func (*Utils) execTemplate(obj interface{}, tmpl, filename string) error {
return file.Sync() return file.Sync()
} }
func (*Utils) kubeClient(kubeConfigPath string) (client.Client, error) { func KubeClient(kubeConfigPath string) (client.Client, error) {
configFiles := utils.splitKubeConfigPath(kubeConfigPath) configFiles := SplitKubeConfigPath(kubeConfigPath)
cfg, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( cfg, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{Precedence: configFiles}, &clientcmd.ClientConfigLoadingRules{Precedence: configFiles},
&clientcmd.ConfigOverrides{}).ClientConfig() &clientcmd.ConfigOverrides{}).ClientConfig()
@@ -151,11 +151,11 @@ func (*Utils) kubeClient(kubeConfigPath string) (client.Client, error) {
return kubeClient, nil return kubeClient, nil
} }
// splitKubeConfigPath splits the given KUBECONFIG path based on the runtime OS // SplitKubeConfigPath splits the given KUBECONFIG path based on the runtime OS
// target. // target.
// //
// Ref: https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#the-kubeconfig-environment-variable // Ref: https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#the-kubeconfig-environment-variable
func (*Utils) splitKubeConfigPath(path string) []string { func SplitKubeConfigPath(path string) []string {
var sep string var sep string
switch runtime.GOOS { switch runtime.GOOS {
case "windows": case "windows":
@@ -166,7 +166,7 @@ func (*Utils) splitKubeConfigPath(path string) []string {
return strings.Split(path, sep) return strings.Split(path, sep)
} }
func (*Utils) writeFile(content, filename string) error { func WriteFile(content, filename string) error {
file, err := os.Create(filename) file, err := os.Create(filename)
if err != nil { if err != nil {
return err return err
@@ -181,7 +181,7 @@ func (*Utils) writeFile(content, filename string) error {
return file.Sync() return file.Sync()
} }
func (*Utils) copyFile(src, dst string) error { func CopyFile(src, dst string) error {
in, err := os.Open(src) in, err := os.Open(src)
if err != nil { if err != nil {
return err return err
@@ -201,7 +201,7 @@ func (*Utils) copyFile(src, dst string) error {
return out.Close() return out.Close()
} }
func (*Utils) containsItemString(s []string, e string) bool { func ContainsItemString(s []string, e string) bool {
for _, a := range s { for _, a := range s {
if a == e { if a == e {
return true return true
@@ -210,7 +210,7 @@ func (*Utils) containsItemString(s []string, e string) bool {
return false return false
} }
func (*Utils) parseObjectKindName(input string) (string, string) { func ParseObjectKindName(input string) (string, string) {
kind := "" kind := ""
name := input name := input
parts := strings.Split(input, "/") parts := strings.Split(input, "/")
@@ -221,7 +221,7 @@ func (*Utils) parseObjectKindName(input string) (string, string) {
return kind, name return kind, name
} }
func (*Utils) makeDependsOn(deps []string) []dependency.CrossNamespaceDependencyReference { func MakeDependsOn(deps []string) []dependency.CrossNamespaceDependencyReference {
refs := []dependency.CrossNamespaceDependencyReference{} refs := []dependency.CrossNamespaceDependencyReference{}
for _, dep := range deps { for _, dep := range deps {
parts := strings.Split(dep, "/") parts := strings.Split(dep, "/")
@@ -241,9 +241,9 @@ func (*Utils) makeDependsOn(deps []string) []dependency.CrossNamespaceDependency
return refs return refs
} }
// generateKustomizationYaml is the equivalent of running // GenerateKustomizationYaml is the equivalent of running
// 'kustomize create --autodetect' in the specified dir // 'kustomize create --autodetect' in the specified dir
func (*Utils) generateKustomizationYaml(dirPath string) error { func GenerateKustomizationYaml(dirPath string) error {
fs := filesys.MakeFsOnDisk() fs := filesys.MakeFsOnDisk()
kfile := filepath.Join(dirPath, "kustomization.yaml") kfile := filepath.Join(dirPath, "kustomization.yaml")
@@ -321,7 +321,7 @@ func (*Utils) generateKustomizationYaml(dirPath string) error {
return nil return nil
} }
func (*Utils) printTable(writer io.Writer, header []string, rows [][]string) { func PrintTable(writer io.Writer, header []string, rows [][]string) {
table := tablewriter.NewWriter(writer) table := tablewriter.NewWriter(writer)
table.SetHeader(header) table.SetHeader(header)
table.SetAutoWrapText(false) table.SetAutoWrapText(false)

View File

@@ -1,5 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1 apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization kind: Kustomization
resources: resources:
- https://github.com/fluxcd/notification-controller/archive/v0.1.1.zip//notification-controller-0.1.1/config/crd - https://github.com/fluxcd/notification-controller/archive/v0.1.2.zip//notification-controller-0.1.2/config/crd
- https://github.com/fluxcd/notification-controller/archive/v0.1.1.zip//notification-controller-0.1.1/config/manager - https://github.com/fluxcd/notification-controller/archive/v0.1.2.zip//notification-controller-0.1.2/config/manager