Răsfoiți Sursa

handle when controller replica num isn't specified

sunguroku 5 ani în urmă
părinte
comite
089c1f37d3
1 a modificat fișierele cu 35 adăugiri și 30 ștergeri
  1. 35 30
      internal/helm/grapher/relation.go

+ 35 - 30
internal/helm/grapher/relation.go

@@ -1,6 +1,7 @@
 package grapher
 
 import (
+	"fmt"
 	"strconv"
 )
 
@@ -70,45 +71,49 @@ func (parsed *ParsedObjs) GetControlRel() {
 			kind = ""
 		}
 
+		fmt.Println(kind.(string))
 		switch kind.(string) {
 		// Parse for all possible controller types
 		case "Deployment", "StatefulSet", "ReplicaSet", "DaemonSet", "Job":
 			rs := getField(yaml, "spec", "replicas")
 
-			if rs != nil && rs.(int) > 0 {
-				// Add Pods for controller objects
-				template := getField(yaml, "spec", "template")
-				if template == nil {
-					continue
-				}
+			// replica defaults to 1 if unspecified
+			if rs == nil {
+				rs = 1
+			}
 
-				for j := 0; j < rs.(int); j++ {
-					cid := len(parsed.Objects) + len(children)
-					crel := ControlRel{
-						Relation: Relation{
-							Source: obj.ID,
-							Target: cid,
-						},
-						Replicas: rs.(int),
-					}
+			// Add Pods for controller objects
+			template := getField(yaml, "spec", "template")
+			if template == nil {
+				continue
+			}
 
-					pod := Object{
-						ID:        cid,
-						Kind:      "Pod",
-						Name:      obj.Name + "-" + strconv.Itoa(j), // tentative name pre-deploy
-						Namespace: obj.Namespace,
-						RawYAML:   template.(map[string]interface{}),
-						Relations: Relations{
-							ControlRels: []ControlRel{
-								crel,
-							},
-						},
-					}
+			for j := 0; j < rs.(int); j++ {
+				cid := len(parsed.Objects) + len(children)
+				crel := ControlRel{
+					Relation: Relation{
+						Source: obj.ID,
+						Target: cid,
+					},
+					Replicas: rs.(int),
+				}
 
-					children = append(children, pod)
-					obj.Relations.ControlRels = append(obj.Relations.ControlRels, crel)
-					parsed.Objects[i] = obj
+				pod := Object{
+					ID:        cid,
+					Kind:      "Pod",
+					Name:      obj.Name + "-" + strconv.Itoa(j), // tentative name pre-deploy
+					Namespace: obj.Namespace,
+					RawYAML:   template.(map[string]interface{}),
+					Relations: Relations{
+						ControlRels: []ControlRel{
+							crel,
+						},
+					},
 				}
+
+				children = append(children, pod)
+				obj.Relations.ControlRels = append(obj.Relations.ControlRels, crel)
+				parsed.Objects[i] = obj
 			}
 		}
 	}