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
115 lines (98 loc) · 3.63 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package hosts
import (
"github.com/caos/orbos/internal/operator/orbiter/kinds/clusters/kubernetes"
"github.com/caos/orbos/internal/operator/orbiter/kinds/clusters/kubernetes/resources/ambassador/host"
"github.com/caos/orbos/internal/operator/zitadel"
"github.com/caos/orbos/internal/operator/zitadel/kinds/networking/core"
"github.com/caos/orbos/mntr"
)
func AdaptFunc(
monitor mntr.Monitor,
namespace string,
labels map[string]string,
) (
zitadel.QueryFunc,
zitadel.DestroyFunc,
error,
) {
internalMonitor := monitor.WithField("part", "hosts")
accountsHostName := "accounts"
apiHostName := "api"
consoleHostName := "console"
issuerHostName := "issuer"
destroyAccounts, err := host.AdaptFuncToDestroy(namespace, accountsHostName)
if err != nil {
return nil, nil, err
}
destroyAPI, err := host.AdaptFuncToDestroy(namespace, apiHostName)
if err != nil {
return nil, nil, err
}
destroyConsole, err := host.AdaptFuncToDestroy(namespace, consoleHostName)
if err != nil {
return nil, nil, err
}
destroyIssuer, err := host.AdaptFuncToDestroy(namespace, issuerHostName)
if err != nil {
return nil, nil, err
}
destroyers := []zitadel.DestroyFunc{
zitadel.ResourceDestroyToZitadelDestroy(destroyAccounts),
zitadel.ResourceDestroyToZitadelDestroy(destroyAPI),
zitadel.ResourceDestroyToZitadelDestroy(destroyConsole),
zitadel.ResourceDestroyToZitadelDestroy(destroyIssuer),
}
return func(k8sClient *kubernetes.Client, queried map[string]interface{}) (zitadel.EnsureFunc, error) {
crd, err := k8sClient.CheckCRD("hosts.getambassador.io")
if crd == nil || err != nil {
return func(k8sClient *kubernetes.Client) error { return nil }, nil
}
currentNW, err := core.ParseQueriedForNetworking(queried)
if err != nil {
return nil, err
}
accountsDomain := currentNW.GetAccountsSubDomain() + "." + currentNW.GetDomain()
apiDomain := currentNW.GetAPISubDomain() + "." + currentNW.GetDomain()
consoleDomain := currentNW.GetConsoleSubDomain() + "." + currentNW.GetDomain()
issuerDomain := currentNW.GetIssuerSubDomain() + "." + currentNW.GetDomain()
originCASecretName := currentNW.GetTlsCertName()
accountsSelector := map[string]string{
"hostname": accountsDomain,
}
queryAccounts, err := host.AdaptFuncToEnsure(namespace, accountsHostName, labels, accountsDomain, "none", "", accountsSelector, originCASecretName)
if err != nil {
return nil, err
}
apiSelector := map[string]string{
"hostname": apiDomain,
}
queryAPI, err := host.AdaptFuncToEnsure(namespace, apiHostName, labels, apiDomain, "none", "", apiSelector, originCASecretName)
if err != nil {
return nil, err
}
consoleSelector := map[string]string{
"hostname": consoleDomain,
}
queryConsole, err := host.AdaptFuncToEnsure(namespace, consoleHostName, labels, consoleDomain, "none", "", consoleSelector, originCASecretName)
if err != nil {
return nil, err
}
issuerSelector := map[string]string{
"hostname": issuerDomain,
}
queryIssuer, err := host.AdaptFuncToEnsure(namespace, issuerHostName, labels, issuerDomain, "none", "", issuerSelector, originCASecretName)
if err != nil {
return nil, err
}
queriers := []zitadel.QueryFunc{
zitadel.EnsureFuncToQueryFunc(currentNW.GetReadyCertificate()),
zitadel.ResourceQueryToZitadelQuery(queryAccounts),
zitadel.ResourceQueryToZitadelQuery(queryAPI),
zitadel.ResourceQueryToZitadelQuery(queryConsole),
zitadel.ResourceQueryToZitadelQuery(queryIssuer),
}
return zitadel.QueriersToEnsureFunc(internalMonitor, false, queriers, k8sClient, queried)
},
zitadel.DestroyersToDestroyFunc(internalMonitor, destroyers),
nil
}