diff --git a/cmd/flux/suspend_source.go b/cmd/flux/suspend_source.go new file mode 100644 index 00000000..c255afbf --- /dev/null +++ b/cmd/flux/suspend_source.go @@ -0,0 +1,31 @@ +/* +Copyright 2020 The Flux authors + +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 main + +import ( + "github.com/spf13/cobra" +) + +var suspendSourceCmd = &cobra.Command{ + Use: "source", + Short: "Suspend sources", + Long: "The suspend sub-commands suspend the reconciliation of a source.", +} + +func init() { + suspendCmd.AddCommand(suspendSourceCmd) +} diff --git a/cmd/flux/suspend_source_bucket.go b/cmd/flux/suspend_source_bucket.go new file mode 100644 index 00000000..e2f82673 --- /dev/null +++ b/cmd/flux/suspend_source_bucket.go @@ -0,0 +1,75 @@ +/* +Copyright 2020 The Flux authors + +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 main + +import ( + "context" + "fmt" + sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" + + "github.com/fluxcd/flux2/internal/utils" + "github.com/spf13/cobra" + "k8s.io/apimachinery/pkg/types" +) + +var suspendSourceBucketCmd = &cobra.Command{ + Use: "bucket [name]", + Short: "Suspend reconciliation of a Bucket", + Long: "The suspend command disables the reconciliation of a Bucket resource.", + Example: ` # Suspend reconciliation for an existing Bucket + flux suspend source bucket podinfo +`, + RunE: suspendSourceBucketCmdRun, +} + +func init() { + suspendSourceCmd.AddCommand(suspendSourceBucketCmd) +} + +func suspendSourceBucketCmdRun(cmd *cobra.Command, args []string) error { + if len(args) < 1 { + return fmt.Errorf("source name is required") + } + name := args[0] + + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + kubeClient, err := utils.KubeClient(kubeconfig, kubecontext) + if err != nil { + return err + } + + namespacedName := types.NamespacedName{ + Namespace: namespace, + Name: name, + } + var bucket sourcev1.Bucket + err = kubeClient.Get(ctx, namespacedName, &bucket) + if err != nil { + return err + } + + logger.Actionf("suspending source %s in %s namespace", name, namespace) + bucket.Spec.Suspend = true + if err := kubeClient.Update(ctx, &bucket); err != nil { + return err + } + logger.Successf("source suspended") + + return nil +} diff --git a/cmd/flux/suspend_source_chart.go b/cmd/flux/suspend_source_chart.go new file mode 100644 index 00000000..5498a745 --- /dev/null +++ b/cmd/flux/suspend_source_chart.go @@ -0,0 +1,75 @@ +/* +Copyright 2020 The Flux authors + +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 main + +import ( + "context" + "fmt" + sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" + + "github.com/fluxcd/flux2/internal/utils" + "github.com/spf13/cobra" + "k8s.io/apimachinery/pkg/types" +) + +var suspendSourceHelmChartCmd = &cobra.Command{ + Use: "chart [name]", + Short: "Suspend reconciliation of a HelmChart", + Long: "The suspend command disables the reconciliation of a HelmChart resource.", + Example: ` # Suspend reconciliation for an existing HelmChart + flux suspend source chart podinfo +`, + RunE: suspendSourceHelmChartCmdRun, +} + +func init() { + suspendSourceCmd.AddCommand(suspendSourceHelmChartCmd) +} + +func suspendSourceHelmChartCmdRun(cmd *cobra.Command, args []string) error { + if len(args) < 1 { + return fmt.Errorf("source name is required") + } + name := args[0] + + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + kubeClient, err := utils.KubeClient(kubeconfig, kubecontext) + if err != nil { + return err + } + + namespacedName := types.NamespacedName{ + Namespace: namespace, + Name: name, + } + var chart sourcev1.HelmChart + err = kubeClient.Get(ctx, namespacedName, &chart) + if err != nil { + return err + } + + logger.Actionf("suspending source %s in %s namespace", name, namespace) + chart.Spec.Suspend = true + if err := kubeClient.Update(ctx, &chart); err != nil { + return err + } + logger.Successf("source suspended") + + return nil +} diff --git a/cmd/flux/suspend_source_git.go b/cmd/flux/suspend_source_git.go new file mode 100644 index 00000000..e96f3fc5 --- /dev/null +++ b/cmd/flux/suspend_source_git.go @@ -0,0 +1,75 @@ +/* +Copyright 2020 The Flux authors + +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 main + +import ( + "context" + "fmt" + sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" + + "github.com/fluxcd/flux2/internal/utils" + "github.com/spf13/cobra" + "k8s.io/apimachinery/pkg/types" +) + +var suspendSourceGitCmd = &cobra.Command{ + Use: "git [name]", + Short: "Suspend reconciliation of a GitRepository", + Long: "The suspend command disables the reconciliation of a GitRepository resource.", + Example: ` # Suspend reconciliation for an existing GitRepository + flux suspend source git podinfo +`, + RunE: suspendSourceGitCmdRun, +} + +func init() { + suspendSourceCmd.AddCommand(suspendSourceGitCmd) +} + +func suspendSourceGitCmdRun(cmd *cobra.Command, args []string) error { + if len(args) < 1 { + return fmt.Errorf("source name is required") + } + name := args[0] + + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + kubeClient, err := utils.KubeClient(kubeconfig, kubecontext) + if err != nil { + return err + } + + namespacedName := types.NamespacedName{ + Namespace: namespace, + Name: name, + } + var repository sourcev1.GitRepository + err = kubeClient.Get(ctx, namespacedName, &repository) + if err != nil { + return err + } + + logger.Actionf("suspending source %s in %s namespace", name, namespace) + repository.Spec.Suspend = true + if err := kubeClient.Update(ctx, &repository); err != nil { + return err + } + logger.Successf("source suspended") + + return nil +} diff --git a/cmd/flux/suspend_source_helm.go b/cmd/flux/suspend_source_helm.go new file mode 100644 index 00000000..fd132962 --- /dev/null +++ b/cmd/flux/suspend_source_helm.go @@ -0,0 +1,75 @@ +/* +Copyright 2020 The Flux authors + +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 main + +import ( + "context" + "fmt" + sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" + + "github.com/fluxcd/flux2/internal/utils" + "github.com/spf13/cobra" + "k8s.io/apimachinery/pkg/types" +) + +var suspendSourceHelmCmd = &cobra.Command{ + Use: "helm [name]", + Short: "Suspend reconciliation of a HelmRepository", + Long: "The suspend command disables the reconciliation of a HelmRepository resource.", + Example: ` # Suspend reconciliation for an existing HelmRepository + flux suspend source helm bitnami +`, + RunE: suspendSourceHelmCmdRun, +} + +func init() { + suspendSourceCmd.AddCommand(suspendSourceHelmCmd) +} + +func suspendSourceHelmCmdRun(cmd *cobra.Command, args []string) error { + if len(args) < 1 { + return fmt.Errorf("source name is required") + } + name := args[0] + + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + kubeClient, err := utils.KubeClient(kubeconfig, kubecontext) + if err != nil { + return err + } + + namespacedName := types.NamespacedName{ + Namespace: namespace, + Name: name, + } + var repository sourcev1.HelmRepository + err = kubeClient.Get(ctx, namespacedName, &repository) + if err != nil { + return err + } + + logger.Actionf("suspending source %s in %s namespace", name, namespace) + repository.Spec.Suspend = true + if err := kubeClient.Update(ctx, &repository); err != nil { + return err + } + logger.Successf("source suspended") + + return nil +} diff --git a/docs/cmd/flux_suspend.md b/docs/cmd/flux_suspend.md index 044c0805..b5e2f934 100644 --- a/docs/cmd/flux_suspend.md +++ b/docs/cmd/flux_suspend.md @@ -29,4 +29,5 @@ The suspend sub-commands suspend the reconciliation of a resource. * [flux suspend helmrelease](flux_suspend_helmrelease.md) - Suspend reconciliation of HelmRelease * [flux suspend kustomization](flux_suspend_kustomization.md) - Suspend reconciliation of Kustomization * [flux suspend receiver](flux_suspend_receiver.md) - Suspend reconciliation of Receiver +* [flux suspend source](flux_suspend_source.md) - Suspend sources diff --git a/docs/cmd/flux_suspend_source.md b/docs/cmd/flux_suspend_source.md new file mode 100644 index 00000000..c2246bf6 --- /dev/null +++ b/docs/cmd/flux_suspend_source.md @@ -0,0 +1,32 @@ +## flux suspend source + +Suspend sources + +### Synopsis + +The suspend sub-commands suspend the reconciliation of a source. + +### Options + +``` + -h, --help help for source +``` + +### Options inherited from parent commands + +``` + --context string kubernetes context to use + --kubeconfig string path to the kubeconfig file (default "~/.kube/config") + -n, --namespace string the namespace scope for this operation (default "flux-system") + --timeout duration timeout for this operation (default 5m0s) + --verbose print generated objects +``` + +### SEE ALSO + +* [flux suspend](flux_suspend.md) - Suspend resources +* [flux suspend source bucket](flux_suspend_source_bucket.md) - Suspend reconciliation of a Bucket +* [flux suspend source chart](flux_suspend_source_chart.md) - Suspend reconciliation of a HelmChart +* [flux suspend source git](flux_suspend_source_git.md) - Suspend reconciliation of a GitRepository +* [flux suspend source helm](flux_suspend_source_helm.md) - Suspend reconciliation of a HelmRepository + diff --git a/docs/cmd/flux_suspend_source_bucket.md b/docs/cmd/flux_suspend_source_bucket.md new file mode 100644 index 00000000..5af9ee3a --- /dev/null +++ b/docs/cmd/flux_suspend_source_bucket.md @@ -0,0 +1,40 @@ +## flux suspend source bucket + +Suspend reconciliation of a Bucket + +### Synopsis + +The suspend command disables the reconciliation of a Bucket resource. + +``` +flux suspend source bucket [name] [flags] +``` + +### Examples + +``` + # Suspend reconciliation for an existing Bucket + flux suspend source bucket podinfo + +``` + +### Options + +``` + -h, --help help for bucket +``` + +### Options inherited from parent commands + +``` + --context string kubernetes context to use + --kubeconfig string path to the kubeconfig file (default "~/.kube/config") + -n, --namespace string the namespace scope for this operation (default "flux-system") + --timeout duration timeout for this operation (default 5m0s) + --verbose print generated objects +``` + +### SEE ALSO + +* [flux suspend source](flux_suspend_source.md) - Suspend sources + diff --git a/docs/cmd/flux_suspend_source_chart.md b/docs/cmd/flux_suspend_source_chart.md new file mode 100644 index 00000000..9e7bd292 --- /dev/null +++ b/docs/cmd/flux_suspend_source_chart.md @@ -0,0 +1,40 @@ +## flux suspend source chart + +Suspend reconciliation of a HelmChart + +### Synopsis + +The suspend command disables the reconciliation of a HelmChart resource. + +``` +flux suspend source chart [name] [flags] +``` + +### Examples + +``` + # Suspend reconciliation for an existing HelmChart + flux suspend source chart podinfo + +``` + +### Options + +``` + -h, --help help for chart +``` + +### Options inherited from parent commands + +``` + --context string kubernetes context to use + --kubeconfig string path to the kubeconfig file (default "~/.kube/config") + -n, --namespace string the namespace scope for this operation (default "flux-system") + --timeout duration timeout for this operation (default 5m0s) + --verbose print generated objects +``` + +### SEE ALSO + +* [flux suspend source](flux_suspend_source.md) - Suspend sources + diff --git a/docs/cmd/flux_suspend_source_git.md b/docs/cmd/flux_suspend_source_git.md new file mode 100644 index 00000000..21588cae --- /dev/null +++ b/docs/cmd/flux_suspend_source_git.md @@ -0,0 +1,40 @@ +## flux suspend source git + +Suspend reconciliation of a GitRepository + +### Synopsis + +The suspend command disables the reconciliation of a GitRepository resource. + +``` +flux suspend source git [name] [flags] +``` + +### Examples + +``` + # Suspend reconciliation for an existing GitRepository + flux suspend source git podinfo + +``` + +### Options + +``` + -h, --help help for git +``` + +### Options inherited from parent commands + +``` + --context string kubernetes context to use + --kubeconfig string path to the kubeconfig file (default "~/.kube/config") + -n, --namespace string the namespace scope for this operation (default "flux-system") + --timeout duration timeout for this operation (default 5m0s) + --verbose print generated objects +``` + +### SEE ALSO + +* [flux suspend source](flux_suspend_source.md) - Suspend sources + diff --git a/docs/cmd/flux_suspend_source_helm.md b/docs/cmd/flux_suspend_source_helm.md new file mode 100644 index 00000000..20a823ce --- /dev/null +++ b/docs/cmd/flux_suspend_source_helm.md @@ -0,0 +1,40 @@ +## flux suspend source helm + +Suspend reconciliation of a HelmRepository + +### Synopsis + +The suspend command disables the reconciliation of a HelmRepository resource. + +``` +flux suspend source helm [name] [flags] +``` + +### Examples + +``` + # Suspend reconciliation for an existing HelmRepository + flux suspend source helm bitnami + +``` + +### Options + +``` + -h, --help help for helm +``` + +### Options inherited from parent commands + +``` + --context string kubernetes context to use + --kubeconfig string path to the kubeconfig file (default "~/.kube/config") + -n, --namespace string the namespace scope for this operation (default "flux-system") + --timeout duration timeout for this operation (default 5m0s) + --verbose print generated objects +``` + +### SEE ALSO + +* [flux suspend source](flux_suspend_source.md) - Suspend sources +