@@ -34,14 +34,6 @@ var filterCmd = &cobra.Command{
34
34
log .Panic (err )
35
35
}
36
36
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
-
45
37
var outObjs []unstructured.Unstructured
46
38
for _ , obj := range objs {
47
39
// filter out generic stuff: .status, .metadata.annotations, etc.
@@ -50,6 +42,23 @@ var filterCmd = &cobra.Command{
50
42
log .Panic (err )
51
43
}
52
44
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
+
53
62
// handle specific objects
54
63
filter , err := filterSpecificObjects (& obj )
55
64
if err != nil {
@@ -60,6 +69,14 @@ var filterCmd = &cobra.Command{
60
69
}
61
70
}
62
71
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
+
63
80
// pretty print to stdout
64
81
bytes , err := json .MarshalIndent (outObjs , "" , " " )
65
82
if err != nil {
@@ -93,6 +110,9 @@ func filterGenericStuff(obj *unstructured.Unstructured) (err error) {
93
110
svc := asService (obj )
94
111
svc .Spec .Selector = filterLabels (svc .Spec .Selector )
95
112
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
+ })
96
116
obj .Object , err = runtime .DefaultUnstructuredConverter .ToUnstructured (svc )
97
117
case "Deployment" :
98
118
dep := asDeployment (obj )
@@ -133,7 +153,7 @@ func filterGenericStuff(obj *unstructured.Unstructured) (err error) {
133
153
// (needs to be below the kind-specific stuff to override converter artifacts!)
134
154
obj .SetAnnotations (emptyMap )
135
155
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?
137
157
138
158
delete (obj .Object , "status" )
139
159
delete (obj .Object , "automountServiceAccountToken" )
@@ -180,15 +200,25 @@ func sortContainersAndEnvVars(containers []corev1.Container) {
180
200
}
181
201
182
202
func filterSpecificObjects (obj * unstructured.Unstructured ) (filter bool , err error ) {
203
+ id := fmt .Sprintf ("%s:%s" , obj .GetKind (), obj .GetName ())
204
+
183
205
// TODO(gpl) revise later: generic
184
206
switch obj .GetKind () {
185
- case "Certificate" , "ClusterRole" , "ClusterRoleBinding" , "RoleBinding" , "Role" , "NetworkPolicy" :
207
+ case "Certificate" , "ClusterRole" , "ClusterRoleBinding" , "RoleBinding" , "Role" , "NetworkPolicy" , "PodSecurityPolicy" , "PodDisruptionBudget" , "ServiceAccount" :
186
208
return false , nil
187
209
}
188
210
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" :
192
222
return false , nil
193
223
}
194
224
@@ -202,9 +232,7 @@ func filterSpecificObjects(obj *unstructured.Unstructured) (filter bool, err err
202
232
return false , nil
203
233
}
204
234
205
-
206
235
// filter/format individual fields
207
- id := fmt .Sprintf ("%s:%s" , obj .GetKind (), obj .GetName ())
208
236
switch id {
209
237
case "ConfigMap:content-service-config" , "ConfigMap:content-service" , "ConfigMap:server-config" :
210
238
cm := asConfigMap (obj )
0 commit comments