Skip to content

Commit

Permalink
Fix runtime error: invalid memory address or nil pointer dereference #4
Browse files Browse the repository at this point in the history
  • Loading branch information
steveteuber committed Aug 27, 2020
1 parent 7a60041 commit d724b14
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions pkg/graph/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,34 @@ func (g *CoreV1Graph) Endpoints(obj *v1.Endpoints) (*Node, error) {

for _, subset := range obj.Subsets {
for _, address := range subset.Addresses {
t := g.graph.Node(
address.TargetRef.GroupVersionKind(),
&metav1.ObjectMeta{
UID: address.TargetRef.UID,
Name: address.TargetRef.Name,
Namespace: address.TargetRef.Namespace,
},
)
g.graph.Relationship(n, address.TargetRef.Kind, t)
if address.TargetRef != nil {
t, err := g.ObjectReference(address.TargetRef)
if err != nil {
return nil, err
}

g.graph.Relationship(n, t.Kind, t)
}
}
}

return n, nil
}

// ObjectReference adds a v1.ObjectReference resource to the Graph.
func (g *CoreV1Graph) ObjectReference(obj *v1.ObjectReference) (*Node, error) {
n := g.graph.Node(
obj.GroupVersionKind(),
&metav1.ObjectMeta{
UID: obj.UID,
Name: obj.Name,
Namespace: obj.Namespace,
},
)

return n, nil
}

// Service adds a v1.Service resource to the Graph.
func (g *CoreV1Graph) Service(obj *v1.Service) (*Node, error) {
switch obj.Spec.Type {
Expand Down

0 comments on commit d724b14

Please sign in to comment.