-
Notifications
You must be signed in to change notification settings - Fork 149
/
kustomization.go
64 lines (51 loc) · 1.71 KB
/
kustomization.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
package server
import (
"context"
"errors"
"fmt"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
"github.com/weaveworks/weave-gitops/core/clustersmngr"
"github.com/weaveworks/weave-gitops/core/server/types"
pb "github.com/weaveworks/weave-gitops/pkg/api/core"
)
func (cs *coreServer) ListKustomizations(ctx context.Context, msg *pb.ListKustomizationsRequest) (*pb.ListKustomizationsResponse, error) {
clientsPool := clustersmngr.ClientsPoolFromCtx(ctx)
if clientsPool == nil {
return &pb.ListKustomizationsResponse{
Kustomizations: []*pb.Kustomization{},
}, errors.New("no clients pool present in context")
}
var results []*pb.Kustomization
//TODO: handle failures and parallelize
for _, c := range clientsPool.Clients() {
l := &kustomizev1.KustomizationList{}
if err := list(ctx, c, temporarilyEmptyAppName, msg.Namespace, l); err != nil {
return nil, err
}
for _, kustomization := range l.Items {
k, err := types.KustomizationToProto(&kustomization)
if err != nil {
return nil, fmt.Errorf("converting items: %w", err)
}
results = append(results, k)
}
}
return &pb.ListKustomizationsResponse{
Kustomizations: results,
}, nil
}
func (cs *coreServer) GetKustomization(ctx context.Context, msg *pb.GetKustomizationRequest) (*pb.GetKustomizationResponse, error) {
k8s, err := cs.k8s.Client(ctx)
if err != nil {
return nil, doClientError(err)
}
k := &kustomizev1.Kustomization{}
if err := get(ctx, k8s, msg.Name, msg.Namespace, k); err != nil {
return nil, err
}
res, err := types.KustomizationToProto(k)
if err != nil {
return nil, fmt.Errorf("converting kustomization to proto: %w", err)
}
return &pb.GetKustomizationResponse{Kustomization: res}, nil
}