Skip to content

Commit

Permalink
Update postrenderer to support pod spec templates. (#1678)
Browse files Browse the repository at this point in the history
  • Loading branch information
absoludity authored Apr 20, 2020
1 parent c125d3f commit 0d2315b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/agent/docker_secrets_postrenderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ func getResourcePodSpec(resource map[interface{}]interface{}) map[interface{}]in
return nil
}

// TODO: Update to support other kinds with pod specs as part of pod templates:
// https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#podtemplatespec-v1-core
switch kind {
case "Pod":
podSpec, ok := resource["spec"].(map[interface{}]interface{})
Expand All @@ -206,6 +204,25 @@ func getResourcePodSpec(resource map[interface{}]interface{}) map[interface{}]in
return nil
}
return podSpec
case "DaemonSet", "Deployment", "Job", "PodTemplate", "ReplicaSet", "ReplicationController", "StatefulSet":
// These resources all include a spec.template.spec PodSpec.
// https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#podtemplatespec-v1-core
spec, ok := resource["spec"].(map[interface{}]interface{})
if !ok {
log.Errorf("invalid resource: non-map spec. %+v", resource)
return nil
}
template, ok := spec["template"].(map[interface{}]interface{})
if !ok {
log.Errorf("invalid resource: non-map spec.template. %+v", resource)
return nil
}
podSpec, ok := template["spec"].(map[interface{}]interface{})
if !ok {
log.Errorf("invalid resource: non-map spec.template.spec. %+v", resource)
return nil
}
return podSpec
}

return nil
Expand Down
28 changes: 28 additions & 0 deletions pkg/agent/docker_secrets_postrenderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,34 @@ func TestGetResourcePodSpec(t *testing.T) {
"some": "spec",
},
},
{
name: "it returns the pod spec from a daemon set",
resource: map[interface{}]interface{}{
"kind": "DaemonSet",
"spec": map[interface{}]interface{}{
"template": map[interface{}]interface{}{
"spec": map[interface{}]interface{}{"some": "spec"},
},
},
},
result: map[interface{}]interface{}{
"some": "spec",
},
},
{
name: "it returns the pod spec from a deployment",
resource: map[interface{}]interface{}{
"kind": "Deployment",
"spec": map[interface{}]interface{}{
"template": map[interface{}]interface{}{
"spec": map[interface{}]interface{}{"some": "spec"},
},
},
},
result: map[interface{}]interface{}{
"some": "spec",
},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 0d2315b

Please sign in to comment.