-
Notifications
You must be signed in to change notification settings - Fork 401
/
machineconfig.go
69 lines (59 loc) · 3.1 KB
/
machineconfig.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
package resourcemerge
import (
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"k8s.io/apimachinery/pkg/api/equality"
)
// EnsureMachineConfig ensures that the existing matches the required.
// modified is set to true when existing had to be updated with required.
func EnsureMachineConfig(modified *bool, existing *mcfgv1.MachineConfig, required mcfgv1.MachineConfig) {
EnsureObjectMeta(modified, &existing.ObjectMeta, required.ObjectMeta)
ensureMachineConfigSpec(modified, &existing.Spec, required.Spec)
}
// EnsureControllerConfig ensures that the existing matches the required.
// modified is set to true when existing had to be updated with required.
func EnsureControllerConfig(modified *bool, existing *mcfgv1.ControllerConfig, required mcfgv1.ControllerConfig) {
EnsureObjectMeta(modified, &existing.ObjectMeta, required.ObjectMeta)
ensureControllerConfigSpec(modified, &existing.Spec, required.Spec)
}
// EnsureMachineConfigPool ensures that the existing matches the required.
// modified is set to true when existing had to be updated with required.
func EnsureMachineConfigPool(modified *bool, existing *mcfgv1.MachineConfigPool, required mcfgv1.MachineConfigPool) {
EnsureObjectMeta(modified, &existing.ObjectMeta, required.ObjectMeta)
if existing.Spec.MachineConfigSelector == nil {
*modified = true
existing.Spec.MachineConfigSelector = required.Spec.MachineConfigSelector
}
if !equality.Semantic.DeepEqual(existing.Spec.MachineConfigSelector, required.Spec.MachineConfigSelector) {
*modified = true
existing.Spec.MachineConfigSelector = required.Spec.MachineConfigSelector
}
if existing.Spec.MachineSelector == nil {
*modified = true
existing.Spec.MachineSelector = required.Spec.MachineSelector
}
if !equality.Semantic.DeepEqual(existing.Spec.MachineSelector, required.Spec.MachineSelector) {
*modified = true
existing.Spec.MachineSelector = required.Spec.MachineSelector
}
}
func ensureMachineConfigSpec(modified *bool, existing *mcfgv1.MachineConfigSpec, required mcfgv1.MachineConfigSpec) {
setStringIfSet(modified, &existing.OSImageURL, required.OSImageURL)
if !equality.Semantic.DeepEqual(existing.Config, required.Config) {
*modified = true
(*existing).Config = required.Config
}
}
func ensureControllerConfigSpec(modified *bool, existing *mcfgv1.ControllerConfigSpec, required mcfgv1.ControllerConfigSpec) {
setStringIfSet(modified, &existing.ClusterDNSIP, required.ClusterDNSIP)
setStringIfSet(modified, &existing.CloudProviderConfig, required.CloudProviderConfig)
setStringIfSet(modified, &existing.ClusterName, required.ClusterName)
setStringIfSet(modified, &existing.Platform, required.Platform)
setStringIfSet(modified, &existing.BaseDomain, required.BaseDomain)
setStringIfSet(modified, &existing.Platform, required.Platform)
setBytesIfSet(modified, &existing.EtcdCAData, required.EtcdCAData)
setBytesIfSet(modified, &existing.RootCAData, required.RootCAData)
if required.PullSecret != nil && !equality.Semantic.DeepEqual(existing.PullSecret, required.PullSecret) {
existing.PullSecret = required.PullSecret
*modified = true
}
}