|
@@ -65,15 +65,24 @@ func (parsed *ParsedObjs) GetControlRel() {
|
|
|
children := []Object{}
|
|
children := []Object{}
|
|
|
for i, obj := range parsed.Objects {
|
|
for i, obj := range parsed.Objects {
|
|
|
yaml := obj.RawYAML
|
|
yaml := obj.RawYAML
|
|
|
|
|
+ kind := getField(yaml, "kind")
|
|
|
|
|
|
|
|
- switch kind := getField(yaml, "kind").(string); kind {
|
|
|
|
|
|
|
+ if kind == nil {
|
|
|
|
|
+ kind = ""
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ switch kind.(string) {
|
|
|
// Parse for all possible controller types
|
|
// Parse for all possible controller types
|
|
|
case "Deployment", "StatefulSet", "ReplicaSet", "DaemonSet", "Job":
|
|
case "Deployment", "StatefulSet", "ReplicaSet", "DaemonSet", "Job":
|
|
|
rs := getField(yaml, "spec", "replicas")
|
|
rs := getField(yaml, "spec", "replicas")
|
|
|
|
|
|
|
|
if rs != nil && rs.(int) > 0 {
|
|
if rs != nil && rs.(int) > 0 {
|
|
|
// Add Pods for controller objects
|
|
// Add Pods for controller objects
|
|
|
- template := getField(yaml, "spec", "template").(map[string]interface{})
|
|
|
|
|
|
|
+ template := getField(yaml, "spec", "template")
|
|
|
|
|
+ if template == nil {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for j := 0; j < rs.(int); j++ {
|
|
for j := 0; j < rs.(int); j++ {
|
|
|
cid := len(parsed.Objects) + len(children)
|
|
cid := len(parsed.Objects) + len(children)
|
|
|
crel := ControlRel{
|
|
crel := ControlRel{
|
|
@@ -89,7 +98,7 @@ func (parsed *ParsedObjs) GetControlRel() {
|
|
|
Kind: "Pod",
|
|
Kind: "Pod",
|
|
|
Name: obj.Name + "-" + strconv.Itoa(j), // tentative name pre-deploy
|
|
Name: obj.Name + "-" + strconv.Itoa(j), // tentative name pre-deploy
|
|
|
Namespace: obj.Namespace,
|
|
Namespace: obj.Namespace,
|
|
|
- RawYAML: template,
|
|
|
|
|
|
|
+ RawYAML: template.(map[string]interface{}),
|
|
|
Relations: Relations{
|
|
Relations: Relations{
|
|
|
ControlRels: []ControlRel{
|
|
ControlRels: []ControlRel{
|
|
|
crel,
|
|
crel,
|
|
@@ -291,7 +300,6 @@ func (parsed *ParsedObjs) findRBACTargets(parentID int, yaml map[string]interfac
|
|
|
if tr["namespace"] != nil && o.Kind == tr["kind"] && o.Name == tr["name"] &&
|
|
if tr["namespace"] != nil && o.Kind == tr["kind"] && o.Name == tr["name"] &&
|
|
|
(o.Namespace == tr["namespace"] || o.Namespace == "default") {
|
|
(o.Namespace == tr["namespace"] || o.Namespace == "default") {
|
|
|
|
|
|
|
|
- fmt.Println("subject", o.Name, tr["kind"])
|
|
|
|
|
// Add bidirectional link from children as well.
|
|
// Add bidirectional link from children as well.
|
|
|
parsed.Objects[i].Relations.SpecRels = append(parsed.Objects[i].Relations.SpecRels, newrel)
|
|
parsed.Objects[i].Relations.SpecRels = append(parsed.Objects[i].Relations.SpecRels, newrel)
|
|
|
targets = append(targets, o.ID)
|
|
targets = append(targets, o.ID)
|