-
Notifications
You must be signed in to change notification settings - Fork 34
/
builder_ctx.go
81 lines (66 loc) · 2.31 KB
/
builder_ctx.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
package utils
import (
"github.com/berops/claudie/internal/utils"
"github.com/berops/claudie/proto/pb"
)
// BuilderContext provides context for the Claudie workflow for a particular cluster.
type BuilderContext struct {
// ProjectName for this cluster
ProjectName string
// CurrentCluster is the current state of the cluster
// properties may change during processing.
CurrentCluster *pb.K8Scluster
// DesiredCluster is the desired state of the cluster
// properties may change during processing.
DesiredCluster *pb.K8Scluster
// CurrentLoadbalancers are the current loadbalancers of the cluster
// properties may change during processing.
CurrentLoadbalancers []*pb.LBcluster
// DesiredLoadbalancers are the current loadbalancers of the cluster
// properties may change during processing.
DesiredLoadbalancers []*pb.LBcluster
// DeletedLoadBalancers are the deleted loadbalancers for the cluster.
DeletedLoadBalancers []*pb.LBcluster
// Workflow is the current state of processing of the cluster.
Workflow *pb.Workflow
}
// GetClusterName returns name of the k8s cluster for a given builder context.
func (ctx *BuilderContext) GetClusterName() string {
if ctx.DesiredCluster != nil {
return ctx.DesiredCluster.ClusterInfo.Name
}
if ctx.CurrentCluster != nil {
return ctx.CurrentCluster.ClusterInfo.Name
}
// try to get the cluster name from the lbs if present
if len(ctx.DesiredLoadbalancers) != 0 {
return ctx.DesiredLoadbalancers[0].TargetedK8S
}
if len(ctx.CurrentLoadbalancers) != 0 {
return ctx.CurrentLoadbalancers[0].TargetedK8S
}
if len(ctx.DeletedLoadBalancers) != 0 {
return ctx.DeletedLoadBalancers[0].TargetedK8S
}
return ""
}
// GetClusterID returns ID of the k8s cluster for a given builder context.
func (ctx *BuilderContext) GetClusterID() string {
if ctx.DesiredCluster != nil {
return utils.GetClusterID(ctx.DesiredCluster.ClusterInfo)
}
if ctx.CurrentCluster != nil {
return utils.GetClusterID(ctx.CurrentCluster.ClusterInfo)
}
// try to get the cluster name from the lbs if present
if len(ctx.DesiredLoadbalancers) != 0 {
return ctx.DesiredLoadbalancers[0].TargetedK8S
}
if len(ctx.CurrentLoadbalancers) != 0 {
return ctx.CurrentLoadbalancers[0].TargetedK8S
}
if len(ctx.DeletedLoadBalancers) != 0 {
return ctx.DeletedLoadBalancers[0].TargetedK8S
}
return ""
}