Merge pull request #254 from fluxcd/uninstall-fix

Suspend bootstrap kustomization on uninstall
pull/258/head
Stefan Prodan 4 years ago committed by GitHub
commit b0e407bf30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,6 +22,7 @@ import (
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
@ -48,7 +49,7 @@ var (
)
func init() {
uninstallCmd.Flags().BoolVar(&uninstallResources, "resources", false,
uninstallCmd.Flags().BoolVar(&uninstallResources, "resources", true,
"removes custom resources such as Kustomizations, GitRepositories and HelmRepositories")
uninstallCmd.Flags().BoolVar(&uninstallCRDs, "crds", false,
"removes all CRDs previously installed")
@ -64,6 +65,11 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
dryRun := ""
if uninstallDryRun {
dryRun = "--dry-run=client"
@ -77,7 +83,20 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
}
}
if uninstallResources {
// suspend bootstrap kustomization if it exists
kustomizationName := types.NamespacedName{
Namespace: namespace,
Name: namespace,
}
var kustomization kustomizev1.Kustomization
if err := kubeClient.Get(ctx, kustomizationName, &kustomization); err == nil {
kustomization.Spec.Suspend = true
if err := kubeClient.Update(ctx, &kustomization); err != nil {
return fmt.Errorf("unable to suspend kustomization '%s': %w", kustomizationName.String(), err)
}
}
if uninstallResources || uninstallCRDs {
logger.Actionf("uninstalling custom resources")
for _, kind := range []string{
kustomizev1.KustomizationKind,

@ -27,7 +27,7 @@ gotk uninstall [flags]
--crds removes all CRDs previously installed
--dry-run only print the object that would be deleted
-h, --help help for uninstall
--resources removes custom resources such as Kustomizations, GitRepositories and HelmRepositories
--resources removes custom resources such as Kustomizations, GitRepositories and HelmRepositories (default true)
-s, --silent delete components without asking for confirmation
```

@ -353,7 +353,7 @@ gotk create helmrelease sealed-secrets \
--chart-version="1.10.x"
```
### Monitoring with Prometheus and Grafana
## Monitoring with Prometheus and Grafana
The GitOps Toolkit comes with an optional monitoring stack.
You can install the stack in the `gitops-system` namespace with:
@ -379,3 +379,14 @@ If you wish to use your own Prometheus and Grafana instances, then you can impor
When using Prometheus Operator you should create `PodMonitor` objects to configure scraping.
When Prometheus is running outside of the `gitops-system` namespace, you have to create a network policy
that allows traffic on port `8080` from the namespace where Prometheus is deployed.
## Uninstall
You can uninstall the toolkit components with:
```sh
gotk uninstall --crds
```
The above command will delete the toolkit custom resources definitions, the controllers
and the namespace where they were installed.

Loading…
Cancel
Save