This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
adapt.go
87 lines (75 loc) · 2.61 KB
/
adapt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package orb
import (
"github.com/caos/orbos/internal/operator/orbiter/kinds/clusters/kubernetes"
"github.com/caos/orbos/internal/operator/zitadel"
"github.com/caos/orbos/internal/operator/zitadel/kinds/iam"
"github.com/caos/orbos/internal/secret"
"github.com/caos/orbos/internal/tree"
"github.com/caos/orbos/mntr"
"github.com/pkg/errors"
)
func AdaptFunc(timestamp string, features ...string) zitadel.AdaptFunc {
return func(monitor mntr.Monitor, desiredTree *tree.Tree, currentTree *tree.Tree) (queryFunc zitadel.QueryFunc, destroyFunc zitadel.DestroyFunc, secrets map[string]*secret.Secret, err error) {
defer func() {
err = errors.Wrapf(err, "building %s failed", desiredTree.Common.Kind)
}()
orbMonitor := monitor.WithField("kind", "orb")
desiredKind, err := ParseDesiredV0(desiredTree)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "parsing desired state failed")
}
desiredTree.Parsed = desiredKind
currentTree = &tree.Tree{}
if desiredKind.Spec.Verbose && !orbMonitor.IsVerbose() {
orbMonitor = orbMonitor.Verbose()
}
query := zitadel.EnsureFuncToQueryFunc(func(k8sClient *kubernetes.Client) error {
imageRegistry := desiredKind.Spec.CustomImageRegistry
if imageRegistry == "" {
imageRegistry = "ghcr.io"
}
if err := kubernetes.EnsureZitadelArtifacts(monitor, k8sClient, desiredKind.Spec.Version, desiredKind.Spec.NodeSelector, desiredKind.Spec.Tolerations, imageRegistry); err != nil {
monitor.Error(errors.Wrap(err, "Failed to deploy zitadel-operator into k8s-cluster"))
return err
}
return nil
})
iamCurrent := &tree.Tree{}
queryIAM, destroyIAM, secrets, err := iam.GetQueryAndDestroyFuncs(
orbMonitor,
desiredKind.IAM,
iamCurrent,
desiredKind.Spec.NodeSelector,
desiredKind.Spec.Tolerations,
timestamp,
features...)
if err != nil {
return nil, nil, nil, err
}
queriers := []zitadel.QueryFunc{
query,
queryIAM,
}
destroyers := []zitadel.DestroyFunc{
destroyIAM,
}
currentTree.Parsed = &DesiredV0{
Common: &tree.Common{
Kind: "zitadel.caos.ch/Orb",
Version: "v0",
},
IAM: iamCurrent,
}
return func(k8sClient *kubernetes.Client, _ map[string]interface{}) (zitadel.EnsureFunc, error) {
queried := map[string]interface{}{}
monitor.WithField("queriers", len(queriers)).Info("Querying")
return zitadel.QueriersToEnsureFunc(monitor, true, queriers, k8sClient, queried)
},
func(k8sClient *kubernetes.Client) error {
monitor.WithField("destroyers", len(queriers)).Info("Destroy")
return zitadel.DestroyersToDestroyFunc(monitor, destroyers)(k8sClient)
},
secrets,
nil
}
}