-
Notifications
You must be signed in to change notification settings - Fork 151
/
helmrelease.go
70 lines (59 loc) · 2.24 KB
/
helmrelease.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
package types
import (
"fmt"
"github.com/fluxcd/helm-controller/api/v2beta1"
pb "github.com/weaveworks/weave-gitops/pkg/api/core"
)
type HelmReleaseStorage struct {
Name string `json:"name,omitempty"`
Manifest string `json:"manifest,omitempty"`
}
func HelmReleaseToProto(helmrelease *v2beta1.HelmRelease, clusterName string, inventory []*pb.GroupVersionKind, tenant string) *pb.HelmRelease {
var chartInterval *pb.Interval
if helmrelease.Spec.Chart.Spec.Interval != nil {
chartInterval = durationToInterval(*helmrelease.Spec.Chart.Spec.Interval)
}
var sourceNamespace string
if helmrelease.Spec.Chart.Spec.SourceRef.Namespace != "" {
sourceNamespace = helmrelease.Spec.Chart.Spec.SourceRef.Namespace
} else {
sourceNamespace = helmrelease.Namespace
}
version, _ := helmrelease.GroupVersionKind().ToAPIVersionAndKind()
dependsOn := []*pb.NamespacedObjectReference{}
for _, v := range helmrelease.Spec.DependsOn {
dependsOn = append(dependsOn, &pb.NamespacedObjectReference{
Name: v.Name,
Namespace: v.Namespace,
})
}
return &pb.HelmRelease{
Name: helmrelease.Name,
ReleaseName: helmrelease.Spec.ReleaseName,
Namespace: helmrelease.Namespace,
Interval: durationToInterval(helmrelease.Spec.Interval),
HelmChart: &pb.HelmChart{
Chart: helmrelease.Spec.Chart.Spec.Chart,
Version: helmrelease.Spec.Chart.Spec.Version,
Name: fmt.Sprintf("%s-%s", helmrelease.Namespace, helmrelease.Name),
Namespace: sourceNamespace,
Interval: chartInterval,
SourceRef: &pb.FluxObjectRef{
Namespace: sourceNamespace,
Name: helmrelease.Spec.Chart.Spec.SourceRef.Name,
Kind: getSourceKind(helmrelease.Spec.Chart.Spec.SourceRef.Kind),
},
},
Inventory: inventory,
Conditions: mapConditions(helmrelease.Status.Conditions),
Suspended: helmrelease.Spec.Suspend,
HelmChartName: helmrelease.Status.HelmChart,
ClusterName: clusterName,
LastAppliedRevision: helmrelease.Status.LastAppliedRevision,
LastAttemptedRevision: helmrelease.Status.LastAttemptedRevision,
ApiVersion: version,
Tenant: tenant,
Uid: string(helmrelease.GetUID()),
DependsOn: dependsOn,
}
}