Livio Amstutz c9b3839f3d
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 <eliobischof@gmail.com>
2021-03-25 16:39:19 +01:00

50 lines
1.3 KiB
Go

package orb
import (
"github.com/caos/orbos/mntr"
"github.com/caos/orbos/pkg/kubernetes"
"github.com/caos/orbos/pkg/tree"
"github.com/caos/orbos/pkg/treelabels"
"github.com/caos/zitadel/operator"
zitadelKubernetes "github.com/caos/zitadel/pkg/kubernetes"
"github.com/pkg/errors"
)
func Reconcile(
monitor mntr.Monitor,
spec *Spec,
gitops bool,
) operator.EnsureFunc {
return func(k8sClient kubernetes.ClientInt) (err error) {
recMonitor := monitor.WithField("version", spec.Version)
if spec.Version == "" {
err := errors.New("No version provided for self-reconciling")
recMonitor.Error(err)
return err
}
imageRegistry := spec.CustomImageRegistry
if imageRegistry == "" {
imageRegistry = "ghcr.io"
}
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, imageRegistry, 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
}
}