@@ -29,26 +29,24 @@ func Example_aReadField() {
2929}
3030
3131func readField (rl * fn.ResourceList ) (bool , error ) {
32- for _ , obj := range rl .Items {
33- if obj .IsGVK ("apps/v1" , "Deployment" ) {
34- // Style 1: like using unstrucuted.Unstructured, get/set the value from field paths*
35- replicas := obj .NestedInt64OrDie ("spec" , "replicas" )
36- fn .Logf ("replicas is %v\n " , replicas )
37- paused := obj .NestedBoolOrDie ("spec" , "paused" )
38- fn .Logf ("paused is %v\n " , paused )
39- // Update strategy from Recreate to RollingUpdate.
40- if strategy := obj .NestedStringOrDie ("spec" , "strategy" , "type" ); strategy == "Recreate" {
41- obj .SetNestedStringOrDie ("RollingUpdate" , "spec" , "strategy" , "type" )
42- }
32+ for _ , obj := range rl .Items .Where (fn .IsGVK ("apps" , "v1" , "Deployment" )) {
33+ // Style 1: like using unstrucuted.Unstructured, get/set the value from field paths*
34+ replicas := obj .NestedInt64OrDie ("spec" , "replicas" )
35+ fn .Logf ("replicas is %v\n " , replicas )
36+ paused := obj .NestedBoolOrDie ("spec" , "paused" )
37+ fn .Logf ("paused is %v\n " , paused )
38+ // Update strategy from Recreate to RollingUpdate.
39+ if strategy := obj .NestedStringOrDie ("spec" , "strategy" , "type" ); strategy == "Recreate" {
40+ obj .SetNestedStringOrDie ("RollingUpdate" , "spec" , "strategy" , "type" )
41+ }
4342
44- // Style 2: operate each resource layer via `GetMap`
45- spec := obj .GetMap ("spec" )
46- replicas = spec .GetInt ("replicas" )
47- fn .Logf ("replicas is %v\n " , replicas )
48- nodeSelector := spec .GetMap ("template" ).GetMap ("spec" ).GetMap ("nodeSelector" )
49- if nodeSelector .GetString ("disktype" ) != "ssd" {
50- nodeSelector .SetNestedStringOrDie ("ssd" , "disktype" )
51- }
43+ // Style 2: operate each resource layer via `GetMap`
44+ spec := obj .GetMap ("spec" )
45+ replicas = spec .GetInt ("replicas" )
46+ fn .Logf ("replicas is %v\n " , replicas )
47+ nodeSelector := spec .GetMap ("template" ).GetMap ("spec" ).GetMap ("nodeSelector" )
48+ if nodeSelector .GetString ("disktype" ) != "ssd" {
49+ nodeSelector .SetNestedStringOrDie ("ssd" , "disktype" )
5250 }
5351 }
5452 return true , nil
0 commit comments