mirror of https://github.com/fluxcd/flux2.git
Add suspend source commands
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>pull/512/head
parent
dd8dc90c1e
commit
072138deff
@ -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)
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue