-
Notifications
You must be signed in to change notification settings - Fork 53
/
system.go
92 lines (82 loc) · 2.82 KB
/
system.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
package gateway
import (
"context"
"os"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
capabilityv1 "github.com/rancher/opni/pkg/apis/capability/v1"
corev1 "github.com/rancher/opni/pkg/apis/core/v1"
managementv1 "github.com/rancher/opni/pkg/apis/management/v1"
"github.com/rancher/opni/pkg/config/v1beta1"
"github.com/rancher/opni/pkg/machinery"
"github.com/rancher/opni/pkg/plugins/apis/system"
"github.com/rancher/opni/pkg/storage"
"github.com/rancher/opni/pkg/task"
"github.com/rancher/opni/plugins/metrics/pkg/apis/node"
"github.com/rancher/opni/plugins/metrics/pkg/backend"
"github.com/rancher/opni/plugins/metrics/pkg/cortex"
_ "github.com/rancher/opni/pkg/storage/etcd"
_ "github.com/rancher/opni/pkg/storage/jetstream"
)
func (p *Plugin) UseManagementAPI(client managementv1.ManagementClient) {
p.mgmtClient.Set(client)
cfg, err := client.GetConfig(context.Background(), &emptypb.Empty{}, grpc.WaitForReady(true))
if err != nil {
p.logger.With(
zap.Error(err),
).Error("failed to get config")
os.Exit(1)
}
objectList, err := machinery.LoadDocuments(cfg.Documents)
if err != nil {
p.logger.With(
zap.Error(err),
).Error("failed to load config")
os.Exit(1)
}
machinery.LoadAuthProviders(p.ctx, objectList)
objectList.Visit(func(config *v1beta1.GatewayConfig) {
backend, err := machinery.ConfigureStorageBackend(p.ctx, &config.Spec.Storage)
if err != nil {
p.logger.With(
zap.Error(err),
).Error("failed to configure storage backend")
os.Exit(1)
}
p.storageBackend.Set(backend)
p.config.Set(config)
tlsConfig := p.loadCortexCerts()
p.cortexTlsConfig.Set(tlsConfig)
clientset, err := cortex.NewClientSet(p.ctx, &config.Spec.Cortex, tlsConfig)
if err != nil {
p.logger.With(
zap.Error(err),
).Error("failed to configure cortex clientset")
os.Exit(1)
}
p.cortexClientSet.Set(clientset)
p.configureCortexManagement()
})
p.authMw.Set(machinery.LoadAuthProviders(p.ctx, objectList))
<-p.ctx.Done()
}
func (p *Plugin) UseNodeManagerClient(client capabilityv1.NodeManagerClient) {
p.nodeManagerClient.Set(client)
<-p.ctx.Done()
}
func (p *Plugin) UseKeyValueStore(client system.KeyValueStoreClient) {
ctrl, err := task.NewController(p.ctx, "uninstall", system.NewKVStoreClient[*corev1.TaskStatus](client), &p.uninstallRunner)
if err != nil {
p.logger.With(
zap.Error(err),
).Error("failed to create task controller")
os.Exit(1)
}
p.uninstallController.Set(ctrl)
p.backendKvClients.Set(&backend.KVClients{
DefaultCapabilitySpec: storage.NewValueStore(system.NewKVStoreClient[*node.MetricsCapabilitySpec](client), "/config/capability/default"),
NodeCapabilitySpecs: storage.NewKeyValueStoreWithPrefix(system.NewKVStoreClient[*node.MetricsCapabilitySpec](client), "/config/capability/nodes/"),
})
<-p.ctx.Done()
}