forked from weaveworks/weave-gitops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helm_release.go
44 lines (33 loc) · 1.04 KB
/
helm_release.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
package server
import (
"context"
"fmt"
"strings"
helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
"github.com/weaveworks/weave-gitops/core/clustersmngr"
pb "github.com/weaveworks/weave-gitops/pkg/api/core"
)
func getHelmReleaseInventory(ctx context.Context, helmRelease helmv2.HelmRelease, c clustersmngr.Client, cluster string) ([]*pb.GroupVersionKind, error) {
k8sClient, err := c.Scoped(cluster)
if err != nil {
return nil, fmt.Errorf("error getting scoped client for cluster=%s: %w", cluster, err)
}
objects, err := getHelmReleaseObjects(ctx, k8sClient, &helmRelease)
if err != nil {
return nil, err
}
var gvk []*pb.GroupVersionKind
found := map[string]bool{}
for _, entry := range objects {
idstr := strings.Join([]string{entry.GetAPIVersion(), entry.GetKind()}, "_")
if !found[idstr] {
found[idstr] = true
gvk = append(gvk, &pb.GroupVersionKind{
Group: entry.GroupVersionKind().Group,
Version: entry.GroupVersionKind().Version,
Kind: entry.GroupVersionKind().Kind,
})
}
}
return gvk, nil
}