fix: operator reconciling (#1478)

* fix(operator): align backup and restore commands (#1465)

* fix: crd mode broke backup and restore commands

* fix: remove obscure gitops-per-operator flags

(cherry picked from commit 041cacc4af8aeb89723a049bc4dbfcbc33cd987f)

* fix: gitops backup and restore need a kubernetes client too (#1475)

(cherry picked from commit 50bc317d2797b819124cdb1119db76bb00ab0df6)

Co-authored-by: Elio Bischof <[email protected]>
This commit is contained in:
Livio Amstutz
2021-03-25 16:39:19 +01:00
committed by GitHub
co-authored by Elio Bischof
parent ae66e40ace
commit c9b3839f3d
10 changed files with 73 additions and 104 deletions
+17 -28
View File
@@ -1,9 +1,10 @@
package cmds
import (
"io/ioutil"
"errors"
"github.com/caos/orbos/pkg/kubernetes/cli"
"github.com/caos/orbos/pkg/kubernetes"
"github.com/caos/zitadel/operator/api"
"github.com/caos/zitadel/operator/crtlgitops"
"github.com/spf13/cobra"
@@ -11,9 +12,8 @@ import (
func BackupCommand(getRv GetRootValues) *cobra.Command {
var (
kubeconfig string
backup string
cmd = &cobra.Command{
backup string
cmd = &cobra.Command{
Use: "backup",
Short: "Instant backup",
Long: "Instant backup",
@@ -21,7 +21,6 @@ func BackupCommand(getRv GetRootValues) *cobra.Command {
)
flags := cmd.Flags()
flags.StringVar(&kubeconfig, "kubeconfig", "~/.kube/config", "Kubeconfig of cluster where the backup should be done")
flags.StringVar(&backup, "backup", "", "Name used for backup folder")
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
@@ -38,11 +37,12 @@ func BackupCommand(getRv GetRootValues) *cobra.Command {
gitClient := rv.GitClient
version := rv.Version
if err := gitClient.Configure(orbConfig.URL, []byte(orbConfig.Repokey)); err != nil {
return err
if !rv.Gitops {
return errors.New("backup command is only supported with the --gitops flag yet")
}
if err := gitClient.Clone(); err != nil {
k8sClient, _, err := cli.Client(monitor, orbConfig, gitClient, rv.Kubeconfig, rv.Gitops)
if err != nil {
return err
}
@@ -52,26 +52,15 @@ func BackupCommand(getRv GetRootValues) *cobra.Command {
}
if found {
value, err := ioutil.ReadFile(kubeconfig)
if err != nil {
monitor.Error(err)
return nil
if err := crtlgitops.Backup(
monitor,
orbConfig.Path,
k8sClient,
backup,
&version,
); err != nil {
return err
}
kubeconfigStr := string(value)
k8sClient := kubernetes.NewK8sClient(monitor, &kubeconfigStr)
if k8sClient.Available() {
if err := crtlgitops.Backup(
monitor,
orbConfig.Path,
k8sClient,
backup,
&version,
); err != nil {
return err
}
}
}
return nil
}