mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-17 21:37:35 +00:00
c0878e4509
* docs: describe crd mode * docs: fix links * docs: fix commands and crdb resources * feat: add configure command * chore: use latest ORBOS * chore: use latest ORBOS * docs: start gitops docs * fix: compile * chore: fix build script path * chore: remove redundant prebuild * chore: add configure.go * docs: describe gitops mode * docs: point template links to main branch * docs: fix versions * feat: initialize empty keys * feat: reconfigure running ZITADEL * docs: describe crd mode * docs: fix links * docs: fix commands and crdb resources * feat: add configure command * chore: use latest ORBOS * chore: use latest ORBOS * docs: start gitops docs * fix: compile * chore: fix build script path * chore: remove redundant prebuild * chore: add configure.go * docs: describe gitops mode * docs: point template links to main branch * docs: fix versions * feat: initialize empty keys * feat: reconfigure running ZITADEL * test: fix * docs: keys are generated with configure * docs: remove keys from template * chore: pass compile time data * chore: use latest ORBOS * fix: when in-cluster, use in-cluster k8s client * fix: try in-cluster config if kubeconfig is empty * fix: reduce unneeded side effects for configure command * docs: boom version * chore: use latest ORBOS * chore: use latest ORBOS * initial commit * inital changes * commit WIP Information Architecture * commit a working state * add static assets and project * add org and fix img names * add plausible * remove img * change sidebar to easier mgmt * add openid oauth and domains * lint md * quickstarts * add auth flow * identity brokering * remove site * fix broken links * extend footer * extend readme * fix: styling * fix: zitadel logo on index * styling * border * fix: nav * fix: nav * fix: index * fix: corrected zitadelctl examples * fix: rename architecture to concepts * fix: introductions * fix: introductions * fix: introductions * docs: cli r/w secrets examples * docs: finish ZITADEL Enterprise Cloud * docs: mention ZITADEL Enterprise Cloud tier * docs: comment configuration options * docs: fix broken links * docs: move some introduction texts around * docs: twilio and email are mandatory * docs: download latest binaries Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: fabi <fabienne.gerschwiler@gmail.com> Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Stefan Benz <stefan@caos.ch>
128 lines
3.3 KiB
Go
128 lines
3.3 KiB
Go
package operator
|
|
|
|
import (
|
|
"github.com/caos/orbos/mntr"
|
|
"github.com/caos/orbos/pkg/git"
|
|
"github.com/caos/orbos/pkg/kubernetes"
|
|
"github.com/caos/orbos/pkg/kubernetes/resources"
|
|
"github.com/caos/orbos/pkg/secret"
|
|
"github.com/caos/orbos/pkg/tree"
|
|
"github.com/pkg/errors"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type AdaptFunc func(
|
|
monitor mntr.Monitor,
|
|
desired *tree.Tree,
|
|
current *tree.Tree,
|
|
) (
|
|
QueryFunc,
|
|
DestroyFunc,
|
|
ConfigureFunc,
|
|
map[string]*secret.Secret,
|
|
map[string]*secret.Existing,
|
|
bool,
|
|
error,
|
|
)
|
|
|
|
type EnsureFunc func(k8sClient kubernetes.ClientInt) error
|
|
|
|
type DestroyFunc func(k8sClient kubernetes.ClientInt) error
|
|
|
|
type ConfigureFunc func(k8sClient kubernetes.ClientInt, queried map[string]interface{}, gitops bool) error
|
|
|
|
type QueryFunc func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (EnsureFunc, error)
|
|
|
|
func Parse(gitClient *git.Client, file string) (*tree.Tree, error) {
|
|
if err := gitClient.Clone(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
tree := &tree.Tree{}
|
|
if err := yaml.Unmarshal(gitClient.Read(file), tree); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return tree, nil
|
|
}
|
|
|
|
func ResourceDestroyToZitadelDestroy(destroyFunc resources.DestroyFunc) DestroyFunc {
|
|
return func(k8sClient kubernetes.ClientInt) error {
|
|
return destroyFunc(k8sClient)
|
|
}
|
|
}
|
|
|
|
func ResourceQueryToZitadelQuery(queryFunc resources.QueryFunc) QueryFunc {
|
|
return func(k8sClient kubernetes.ClientInt, _ map[string]interface{}) (EnsureFunc, error) {
|
|
ensure, err := queryFunc(k8sClient)
|
|
ensureInternal := ResourceEnsureToZitadelEnsure(ensure)
|
|
|
|
return func(k8sClient kubernetes.ClientInt) error {
|
|
return ensureInternal(k8sClient)
|
|
}, err
|
|
}
|
|
}
|
|
|
|
func ResourceEnsureToZitadelEnsure(ensureFunc resources.EnsureFunc) EnsureFunc {
|
|
return func(k8sClient kubernetes.ClientInt) error {
|
|
return ensureFunc(k8sClient)
|
|
}
|
|
}
|
|
func EnsureFuncToQueryFunc(ensure EnsureFunc) QueryFunc {
|
|
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (ensureFunc EnsureFunc, err error) {
|
|
return ensure, err
|
|
}
|
|
}
|
|
|
|
func QueriersToEnsureFunc(monitor mntr.Monitor, infoLogs bool, queriers []QueryFunc, k8sClient kubernetes.ClientInt, queried map[string]interface{}) (EnsureFunc, error) {
|
|
if infoLogs {
|
|
monitor.Info("querying...")
|
|
} else {
|
|
monitor.Debug("querying...")
|
|
}
|
|
ensurers := make([]EnsureFunc, 0)
|
|
for _, querier := range queriers {
|
|
ensurer, err := querier(k8sClient, queried)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "error while querying")
|
|
}
|
|
ensurers = append(ensurers, ensurer)
|
|
}
|
|
if infoLogs {
|
|
monitor.Info("queried")
|
|
} else {
|
|
monitor.Debug("queried")
|
|
}
|
|
return func(k8sClient kubernetes.ClientInt) error {
|
|
if infoLogs {
|
|
monitor.Info("ensuring...")
|
|
} else {
|
|
monitor.Debug("ensuring...")
|
|
}
|
|
for _, ensurer := range ensurers {
|
|
if err := ensurer(k8sClient); err != nil {
|
|
return errors.Wrap(err, "error while ensuring")
|
|
}
|
|
}
|
|
if infoLogs {
|
|
monitor.Info("ensured")
|
|
} else {
|
|
monitor.Debug("ensured")
|
|
}
|
|
return nil
|
|
}, nil
|
|
}
|
|
|
|
func DestroyersToDestroyFunc(monitor mntr.Monitor, destroyers []DestroyFunc) DestroyFunc {
|
|
return func(k8sClient kubernetes.ClientInt) error {
|
|
monitor.Info("destroying...")
|
|
for _, destroyer := range destroyers {
|
|
if err := destroyer(k8sClient); err != nil {
|
|
return errors.Wrap(err, "error while destroying")
|
|
}
|
|
}
|
|
monitor.Info("destroyed")
|
|
return nil
|
|
}
|
|
}
|