generated from giantswarm/template-operator
/
cluster.go
84 lines (65 loc) · 2.45 KB
/
cluster.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
package vintagemc
import (
appv1 "github.com/giantswarm/apiextensions-application/api/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/giantswarm/logging-operator/pkg/common"
loggedcluster "github.com/giantswarm/logging-operator/pkg/logged-cluster"
)
type Object struct {
client.Object
Options loggedcluster.Options
}
func (o Object) HasLoggingEnabled() bool {
return o.Options.EnableLoggingFlag
}
func (o Object) IsInsecureCA() bool {
return o.Options.InsecureCA
}
func (o Object) GetAppsNamespace() string {
return "giantswarm"
}
func (o Object) AppConfigName(app string) string {
return app
}
func (o Object) ObservabilityBundleConfigLabelName(config string) string {
return config
}
func (o Object) GetClusterName() string {
// return installation name for vintage MC
return o.Options.InstallationName
}
func (o Object) GetInstallationName() string {
return o.Options.InstallationName
}
func (o Object) GetEnableLoggingFlag() bool {
return o.Options.EnableLoggingFlag
}
func (o Object) GetObject() client.Object {
return o.Object
}
// On vintage MC, there's no support for extraconfig so we should use standard user values
func (o Object) GetObservabilityBundleConfigMap() string {
return "observability-bundle-user-values"
}
// UnwireLogging unsets the user value confimap in a copy of the app
func (o Object) UnwireLogging(currentApp appv1.App) *appv1.App {
desiredApp := currentApp.DeepCopy()
observabilityBundleConfigMapMeta := common.ObservabilityBundleConfigMapMeta(o)
if desiredApp.Spec.UserConfig.ConfigMap.Name == observabilityBundleConfigMapMeta.GetName() ||
desiredApp.Spec.UserConfig.ConfigMap.Namespace == observabilityBundleConfigMapMeta.GetNamespace() {
desiredApp.Spec.UserConfig.ConfigMap.Name = ""
desiredApp.Spec.UserConfig.ConfigMap.Namespace = ""
}
return desiredApp
}
// WireLogging sets the user value confimap in a copy of the app.
func (o Object) WireLogging(currentApp appv1.App) *appv1.App {
desiredApp := currentApp.DeepCopy()
observabilityBundleConfigMapMeta := common.ObservabilityBundleConfigMapMeta(o)
if desiredApp.Spec.UserConfig.ConfigMap.Name != observabilityBundleConfigMapMeta.GetName() ||
desiredApp.Spec.UserConfig.ConfigMap.Namespace != observabilityBundleConfigMapMeta.GetNamespace() {
desiredApp.Spec.UserConfig.ConfigMap.Name = observabilityBundleConfigMapMeta.GetName()
desiredApp.Spec.UserConfig.ConfigMap.Namespace = observabilityBundleConfigMapMeta.GetNamespace()
}
return desiredApp
}