Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add Kubernetes context option to CLI commands #412

Merged
merged 1 commit into from Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/flux/bootstrap_github.go
Expand Up @@ -184,7 +184,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
logger.Successf("components are up to date")
}

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/bootstrap_gitlab.go
Expand Up @@ -113,7 +113,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
IsPersonal: glPersonal,
}

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/create_alert.go
Expand Up @@ -120,7 +120,7 @@ func createAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/create_alertprovider.go
Expand Up @@ -116,7 +116,7 @@ func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/create_helmrelease.go
Expand Up @@ -177,7 +177,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/create_kustomization.go
Expand Up @@ -209,7 +209,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/create_receiver.go
Expand Up @@ -128,7 +128,7 @@ func createReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/create_source_bucket.go
Expand Up @@ -140,7 +140,7 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/create_source_git.go
Expand Up @@ -176,7 +176,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/create_source_helm.go
Expand Up @@ -136,7 +136,7 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/create_tenant.go
Expand Up @@ -145,7 +145,7 @@ func createTenantCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/delete_alert.go
Expand Up @@ -51,7 +51,7 @@ func deleteAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/delete_alertprovider.go
Expand Up @@ -51,7 +51,7 @@ func deleteAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/delete_helmrelease.go
Expand Up @@ -52,7 +52,7 @@ func deleteHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/delete_kustomization.go
Expand Up @@ -51,7 +51,7 @@ func deleteKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/delete_receiver.go
Expand Up @@ -51,7 +51,7 @@ func deleteReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/delete_source_bucket.go
Expand Up @@ -50,7 +50,7 @@ func deleteSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/delete_source_git.go
Expand Up @@ -50,7 +50,7 @@ func deleteSourceGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/delete_source_helm.go
Expand Up @@ -50,7 +50,7 @@ func deleteSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/export_alert.go
Expand Up @@ -55,7 +55,7 @@ func exportAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/export_alertprovider.go
Expand Up @@ -55,7 +55,7 @@ func exportAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/export_helmrelease.go
Expand Up @@ -56,7 +56,7 @@ func exportHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/export_kustomization.go
Expand Up @@ -56,7 +56,7 @@ func exportKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/export_receiver.go
Expand Up @@ -55,7 +55,7 @@ func exportReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/export_source_bucket.go
Expand Up @@ -56,7 +56,7 @@ func exportSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/export_source_git.go
Expand Up @@ -56,7 +56,7 @@ func exportSourceGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/export_source_helm.go
Expand Up @@ -56,7 +56,7 @@ func exportSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/get_alert.go
Expand Up @@ -49,7 +49,7 @@ func getAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/get_alertprovider.go
Expand Up @@ -47,7 +47,7 @@ func getAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/get_helmrelease.go
Expand Up @@ -51,7 +51,7 @@ func getHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/get_kustomization.go
Expand Up @@ -50,7 +50,7 @@ func getKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/get_receiver.go
Expand Up @@ -49,7 +49,7 @@ func getReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/get_source_bucket.go
Expand Up @@ -47,7 +47,7 @@ func getSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/get_source_git.go
Expand Up @@ -47,7 +47,7 @@ func getSourceGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/get_source_helm.go
Expand Up @@ -47,7 +47,7 @@ func getSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/flux/main.go
Expand Up @@ -96,6 +96,7 @@ var rootCmd = &cobra.Command{

var (
kubeconfig string
kubecontext string
namespace string
timeout time.Duration
verbose bool
Expand All @@ -108,6 +109,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "n", defaults.Namespace, "the namespace scope for this operation")
rootCmd.PersistentFlags().DurationVar(&timeout, "timeout", 5*time.Minute, "timeout for this operation")
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "print generated objects")
rootCmd.PersistentFlags().StringVarP(&kubecontext, "context", "", "", "kubernetes context to use")
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/reconcile_alert.go
Expand Up @@ -54,7 +54,7 @@ func reconcileAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/reconcile_alertprovider.go
Expand Up @@ -54,7 +54,7 @@ func reconcileAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/reconcile_helmrelease.go
Expand Up @@ -69,7 +69,7 @@ func reconcileHrCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/reconcile_kustomization.go
Expand Up @@ -69,7 +69,7 @@ func reconcileKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/reconcile_receiver.go
Expand Up @@ -54,7 +54,7 @@ func reconcileReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/reconcile_source_bucket.go
Expand Up @@ -56,7 +56,7 @@ func reconcileSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/reconcile_source_git.go
Expand Up @@ -54,7 +54,7 @@ func reconcileSourceGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

kubeClient, err := utils.KubeClient(kubeconfig)
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
if err != nil {
return err
}
Expand Down