cmd/kgctl: fix possible nil pointer dereference

This commit is contained in:
Lucas Servén Marín 2019-04-02 18:23:51 +02:00
parent 614f2e1c5d
commit a8467f779e
No known key found for this signature in database
GPG Key ID: 586FEAF680DA74AD

View File

@ -36,15 +36,16 @@ func runGraph(_ *cobra.Command, _ []string) error {
return fmt.Errorf("failed to list nodes: %v", err)
}
var hostname string
if len(ns) != 0 {
hostname = ns[0].Name
}
nodes := make(map[string]*mesh.Node)
for _, n := range ns {
if n.Ready() {
nodes[n.Name] = n
hostname = n.Name
}
}
if len(nodes) == 0 {
return fmt.Errorf("did not find any valid Kilo nodes in the cluster")
}
t, err := mesh.NewTopology(nodes, opts.granularity, hostname, 0, []byte{}, opts.subnet)
if err != nil {
return fmt.Errorf("failed to create topology: %v", err)