Skip to content

Commit 7726e49

Browse files
geroplroboquat
authored andcommitted
[installer-diff] Filter out unwanted objects, and reduce noise
1 parent e955e75 commit 7726e49

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

dev/installer-diff/cmd/filter.go

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ var filterCmd = &cobra.Command{
3434
log.Panic(err)
3535
}
3636

37-
// sort by .kind and .metadata.name
38-
sort.SliceStable(objs, func(i, j int) bool {
39-
id := func(i int) string {
40-
return fmt.Sprintf("%s:%s", objs[i].GetKind(), objs[i].GetName())
41-
}
42-
return id(i) < id(j)
43-
})
44-
4537
var outObjs []unstructured.Unstructured
4638
for _, obj := range objs {
4739
// filter out generic stuff: .status, .metadata.annotations, etc.
@@ -50,6 +42,23 @@ var filterCmd = &cobra.Command{
5042
log.Panic(err)
5143
}
5244

45+
// rename objects and components (to allow to compare re-named objects)
46+
nameMappings := map[string]string{
47+
"db": "cloudsqlproxy-cloud-sql-proxy",
48+
}
49+
if newName, hasEntry := nameMappings[obj.GetName()]; hasEntry {
50+
obj.SetName(newName)
51+
}
52+
53+
componentMapping := map[string]string{
54+
"db": "cloudsqlproxy",
55+
}
56+
lbls := obj.GetLabels()
57+
if newComponent, hasEntry := componentMapping[lbls["component"]]; hasEntry {
58+
lbls["component"] = newComponent
59+
obj.SetLabels(lbls)
60+
}
61+
5362
// handle specific objects
5463
filter, err := filterSpecificObjects(&obj)
5564
if err != nil {
@@ -60,6 +69,14 @@ var filterCmd = &cobra.Command{
6069
}
6170
}
6271

72+
// sort by .kind and .metadata.name
73+
sort.SliceStable(outObjs, func(i, j int) bool {
74+
id := func(i int) string {
75+
return fmt.Sprintf("%s:%s", outObjs[i].GetKind(), outObjs[i].GetName())
76+
}
77+
return id(i) < id(j)
78+
})
79+
6380
// pretty print to stdout
6481
bytes, err := json.MarshalIndent(outObjs, "", " ")
6582
if err != nil {
@@ -93,6 +110,9 @@ func filterGenericStuff(obj *unstructured.Unstructured) (err error) {
93110
svc := asService(obj)
94111
svc.Spec.Selector = filterLabels(svc.Spec.Selector)
95112
svc.Spec.SessionAffinity = "" // gpl: new relies on k8s default ("None"), old always sets "None" everywhere
113+
sort.SliceStable(svc.Spec.Ports, func(i, j int) bool {
114+
return svc.Spec.Ports[i].Name < svc.Spec.Ports[j].Name
115+
})
96116
obj.Object, err = runtime.DefaultUnstructuredConverter.ToUnstructured(svc)
97117
case "Deployment":
98118
dep := asDeployment(obj)
@@ -133,7 +153,7 @@ func filterGenericStuff(obj *unstructured.Unstructured) (err error) {
133153
// (needs to be below the kind-specific stuff to override converter artifacts!)
134154
obj.SetAnnotations(emptyMap)
135155
obj.SetNamespace("")
136-
obj.SetCreationTimestamp(v1.Time{}) // results in "null". How to set to "nil" w/o writing by hand?
156+
obj.SetCreationTimestamp(v1.Time{}) // results in "null". How to set to "nil" w/o writing by hand?
137157

138158
delete(obj.Object, "status")
139159
delete(obj.Object, "automountServiceAccountToken")
@@ -180,15 +200,25 @@ func sortContainersAndEnvVars(containers []corev1.Container) {
180200
}
181201

182202
func filterSpecificObjects(obj *unstructured.Unstructured) (filter bool, err error) {
203+
id := fmt.Sprintf("%s:%s", obj.GetKind(), obj.GetName())
204+
183205
// TODO(gpl) revise later: generic
184206
switch obj.GetKind() {
185-
case "Certificate", "ClusterRole", "ClusterRoleBinding", "RoleBinding", "Role", "NetworkPolicy":
207+
case "Certificate", "ClusterRole", "ClusterRoleBinding", "RoleBinding", "Role", "NetworkPolicy", "PodSecurityPolicy", "PodDisruptionBudget", "ServiceAccount":
186208
return false, nil
187209
}
188210

189-
// TODO(gpl) revise later: NetworkPolicy
190-
switch obj.GetKind() {
191-
case "NetworkPolicy":
211+
// filter out: messagebus
212+
switch obj.GetLabels()["component"] {
213+
case "messagebus", "rabbitmq":
214+
return false, nil
215+
}
216+
switch obj.GetName() {
217+
case "messagebus-config":
218+
return false, nil
219+
}
220+
switch id {
221+
case "Service:messagebus", "Service:messagebus-headless", "StatefulSet:messagebus":
192222
return false, nil
193223
}
194224

@@ -202,9 +232,7 @@ func filterSpecificObjects(obj *unstructured.Unstructured) (filter bool, err err
202232
return false, nil
203233
}
204234

205-
206235
// filter/format individual fields
207-
id := fmt.Sprintf("%s:%s", obj.GetKind(), obj.GetName())
208236
switch id {
209237
case "ConfigMap:content-service-config", "ConfigMap:content-service", "ConfigMap:server-config":
210238
cm := asConfigMap(obj)

0 commit comments

Comments
 (0)