fix(zitadelctl): implementation for commands in crd mode (#1685)

* fix(zitadelctl): implement takedown command

* fix(zitadelctl): correct destroy flow

* fix(zitadelctl): correct backup commands to read crds beforehand

* fix: add of destroyfile

* fix: clean for userlist

* fix: determine mode by --gitops flag for backups

* refactor: return error instead of higher order function

* fix(destroy): needs no self-reconciling

Co-authored-by: Elio Bischof <[email protected]>

* fix(destroy): needs no self-reconciling

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

* fix(logs): fix double handled error

Co-authored-by: Elio Bischof <[email protected]>

Co-authored-by: Elio Bischof <[email protected]>
This commit is contained in:
Stefan Benz
2021-07-20 15:47:48 +02:00
committed by GitHub
co-authored by Elio Bischof
parent 413ed80611
commit 25c9d7371d
48 changed files with 1084 additions and 275 deletions
+14 -8
View File
@@ -91,22 +91,28 @@ func AdaptFunc(
return nil, nil, nil, nil, nil, migrate, err
}
rec, _ := Reconcile(monitor, desiredKind.Spec, gitops)
destroyers := make([]operator.DestroyFunc, 0)
queriers := make([]operator.QueryFunc, 0)
dbOrBackup := false
for _, feature := range features {
switch feature {
case "database", backup.Instant, backup.Normal, restore.Instant, clean.Instant:
queriers = append(queriers,
operator.ResourceQueryToZitadelQuery(queryNS),
queryDB,
)
destroyers = append(destroyers,
destroyDB,
)
if !dbOrBackup {
dbOrBackup = true
queriers = append(queriers,
operator.ResourceQueryToZitadelQuery(queryNS),
queryDB,
)
destroyers = append(destroyers,
destroyDB,
)
}
case "operator":
queriers = append(queriers,
operator.ResourceQueryToZitadelQuery(queryNS),
operator.EnsureFuncToQueryFunc(Reconcile(monitor, desiredKind.Spec, gitops)),
operator.EnsureFuncToQueryFunc(rec),
)
}
}
+4 -3
View File
@@ -2,13 +2,14 @@ package orb
import (
"github.com/caos/orbos/mntr"
"github.com/caos/orbos/pkg/kubernetes"
"github.com/caos/orbos/pkg/tree"
"github.com/caos/zitadel/operator/database/kinds/databases"
"github.com/pkg/errors"
)
func BackupListFunc() func(monitor mntr.Monitor, desiredTree *tree.Tree) (strings []string, err error) {
return func(monitor mntr.Monitor, desiredTree *tree.Tree) (strings []string, err error) {
func BackupListFunc() func(monitor mntr.Monitor, k8sClient kubernetes.ClientInt, desiredTree *tree.Tree) (strings []string, err error) {
return func(monitor mntr.Monitor, k8sClient kubernetes.ClientInt, desiredTree *tree.Tree) (strings []string, err error) {
desiredKind, err := ParseDesiredV0(desiredTree)
if err != nil {
return nil, errors.Wrap(err, "parsing desired state failed")
@@ -19,6 +20,6 @@ func BackupListFunc() func(monitor mntr.Monitor, desiredTree *tree.Tree) (string
monitor = monitor.Verbose()
}
return databases.GetBackupList(monitor, desiredKind.Database)
return databases.GetBackupList(monitor, k8sClient, desiredKind.Database)
}
}
+31 -22
View File
@@ -3,6 +3,7 @@ package orb
import (
"github.com/caos/orbos/mntr"
"github.com/caos/orbos/pkg/kubernetes"
"github.com/caos/orbos/pkg/labels"
"github.com/caos/orbos/pkg/tree"
"github.com/caos/orbos/pkg/treelabels"
"github.com/caos/zitadel/operator"
@@ -14,31 +15,39 @@ func Reconcile(
monitor mntr.Monitor,
spec *Spec,
gitops bool,
) operator.EnsureFunc {
) (
operator.EnsureFunc,
operator.DestroyFunc,
) {
return func(k8sClient kubernetes.ClientInt) (err error) {
recMonitor := monitor.WithField("version", spec.Version)
recMonitor := monitor.WithField("version", spec.Version)
if spec.Version == "" {
err := errors.New("No version provided for self-reconciling")
recMonitor.Error(err)
return err
}
if spec.SelfReconciling {
desiredTree := &tree.Tree{
Common: &tree.Common{
Kind: "databases.caos.ch/Orb",
Version: "v0",
},
}
if err := zitadelKubernetes.EnsureDatabaseArtifacts(monitor, treelabels.MustForAPI(desiredTree, mustDatabaseOperator(&spec.Version)), k8sClient, spec.Version, spec.NodeSelector, spec.Tolerations, spec.CustomImageRegistry, gitops); err != nil {
recMonitor.Error(errors.Wrap(err, "Failed to deploy database-operator into k8s-cluster"))
if spec.Version == "" {
err := errors.New("No version provided for self-reconciling")
return err
}
recMonitor.Info("Applied database-operator")
}
return nil
}
if spec.SelfReconciling {
desiredTree := &tree.Tree{
Common: &tree.Common{
Kind: "databases.caos.ch/Orb",
Version: "v0",
},
}
if err := zitadelKubernetes.EnsureDatabaseArtifacts(monitor, treelabels.MustForAPI(desiredTree, mustDatabaseOperator(&spec.Version)), k8sClient, spec.Version, spec.NodeSelector, spec.Tolerations, spec.CustomImageRegistry, gitops); err != nil {
recMonitor.Error(errors.Wrap(err, "Failed to deploy database-operator into k8s-cluster"))
return err
}
recMonitor.Info("Applied database-operator")
}
return nil
}, func(k8sClient kubernetes.ClientInt) error {
if err := zitadelKubernetes.DestroyDatabaseOperator(monitor, labels.MustForAPI(labels.NoopOperator("database-operator"), "database", "v0"), k8sClient, gitops); err != nil {
monitor.Error(errors.Wrap(err, "Failed to destroy database-operator in k8s-cluster"))
return err
}
monitor.Info("Destroyed database-operator")
return nil
}
}