This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
/
reconcile.go
94 lines (71 loc) · 2.72 KB
/
reconcile.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
85
86
87
88
89
90
91
92
93
94
package nginxingress
import (
"k8s.io/api/policy/v1beta1"
"reflect"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)
func reconcileDeployment(foundDeployment v1.Deployment, newDeployment v1.Deployment) (bool, v1.Deployment) {
reconcileRequired := false
if !reflect.DeepEqual(foundDeployment.Spec.Replicas, newDeployment.Spec.Replicas) {
foundDeployment.Spec.Replicas = newDeployment.Spec.Replicas
reconcileRequired = true
}
if !reflect.DeepEqual(foundDeployment.Labels, newDeployment.Labels) {
foundDeployment.Labels = newDeployment.Labels
reconcileRequired = true
}
if !reflect.DeepEqual(foundDeployment.Spec.Template, newDeployment.Spec.Template) {
foundDeployment.Spec.Template = newDeployment.Spec.Template
reconcileRequired = true
}
return reconcileRequired, foundDeployment
}
func reconcilePdb(foundPdb v1beta1.PodDisruptionBudget, newPdb v1beta1.PodDisruptionBudget) (bool, v1beta1.PodDisruptionBudget) {
reconcileRequired := false
if !reflect.DeepEqual(foundPdb.Spec.Selector, newPdb.Spec.Selector) {
foundPdb.Spec.Selector = newPdb.Spec.Selector
reconcileRequired = true
}
if !reflect.DeepEqual(foundPdb.Spec.MaxUnavailable, newPdb.Spec.MaxUnavailable) {
foundPdb.Spec.MaxUnavailable = newPdb.Spec.MaxUnavailable
reconcileRequired = true
}
if !reflect.DeepEqual(foundPdb.Spec.MinAvailable, newPdb.Spec.MinAvailable) {
foundPdb.Spec.MinAvailable = newPdb.Spec.MinAvailable
reconcileRequired = true
}
return reconcileRequired, foundPdb
}
func reconcileService(foundService corev1.Service, newService corev1.Service) (bool, corev1.Service) {
reconcileRequired := false
if !reflect.DeepEqual(foundService.Spec.Type, newService.Spec.Type) {
foundService.Spec.Type = newService.Spec.Type
reconcileRequired = true
}
if !reflect.DeepEqual(foundService.Spec.ExternalTrafficPolicy, newService.Spec.ExternalTrafficPolicy) {
foundService.Spec.Type = newService.Spec.Type
reconcileRequired = true
}
if !reflect.DeepEqual(foundService.Labels, newService.Labels) {
foundService.Labels = newService.Labels
reconcileRequired = true
}
if !reflect.DeepEqual(foundService.Annotations, newService.Annotations) {
foundService.Annotations = newService.Annotations
reconcileRequired = true
}
return reconcileRequired, foundService
}
func reconcileConfigmap(foundConfigmap corev1.ConfigMap, newConfigmap corev1.ConfigMap) (bool, corev1.ConfigMap) {
reconcileRequired := false
if !reflect.DeepEqual(foundConfigmap.Data, newConfigmap.Data) {
foundConfigmap.Data = newConfigmap.Data
reconcileRequired = true
}
if !reflect.DeepEqual(foundConfigmap.Labels, newConfigmap.Labels) {
foundConfigmap.Labels = newConfigmap.Labels
reconcileRequired = true
}
return reconcileRequired, foundConfigmap
}