-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathsubstitution.go
57 lines (48 loc) · 1.94 KB
/
substitution.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
package substitution
import (
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
v1 "k8s.io/api/apps/v1"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
)
const (
// Names in this list are unique and will be substituted with an image from config
// cloudControllerManagerName is a name for default CCM controller container any provider may have
cloudControllerManagerName = "cloud-controller-manager"
cloudNodeManagerName = "cloud-node-manager"
)
// setDeploymentImages substitutes controller containers in Deployment with correct image
func setDeploymentImages(config config.OperatorConfig, d *v1.Deployment) {
for i, container := range d.Spec.Template.Spec.Containers {
if container.Name != cloudControllerManagerName {
continue
}
klog.Infof("Substituting %q in Deployment %q with %s", container.Name, d.Name, config.ControllerImage)
d.Spec.Template.Spec.Containers[i].Image = config.ControllerImage
}
}
func setDaemonSetImage(config config.OperatorConfig, d *v1.DaemonSet) {
for i, container := range d.Spec.Template.Spec.Containers {
if container.Name != cloudNodeManagerName {
continue
}
klog.Infof("Substituting %q in DaemonSet %q with %s", container.Name, d.Name, config.ControllerImage)
d.Spec.Template.Spec.Containers[i].Image = config.CloudNodeImage
}
}
func FillConfigValues(config config.OperatorConfig, templates []client.Object) []client.Object {
objects := make([]client.Object, len(templates))
for i, objectTemplate := range templates {
templateCopy := objectTemplate.DeepCopyObject().(client.Object)
// Set namespaces for all object. Namespace on cluster-wide objects is stripped by API server and is not applied
templateCopy.SetNamespace(config.ManagedNamespace)
switch obj := templateCopy.(type) {
case *v1.Deployment:
setDeploymentImages(config, obj)
case *v1.DaemonSet:
setDaemonSetImage(config, obj)
}
objects[i] = templateCopy
}
return objects
}