createCluster: fix loadblancer consideration

- issue #248: nil pointer dereference because we're trying to access
non-existent loadblancer node
pull/251/head
iwilltry42 4 years ago
parent 2a0b425f67
commit dabec2f091
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 12
      cmd/create/createCluster.go
  2. 2
      cmd/util/filter.go

@ -374,15 +374,17 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string, createClusterOpts
}
// append ports
lbCount := 1
if createClusterOpts.DisableLoadBalancer {
lbCount = 0
nodeCount := masterCount + workerCount
nodeList := cluster.Nodes
if !createClusterOpts.DisableLoadBalancer {
nodeCount++
nodeList = append(nodeList, cluster.MasterLoadBalancer)
}
for portmap, filters := range portFilterMap {
if len(filters) == 0 && (masterCount+workerCount+lbCount) > 1 {
if len(filters) == 0 && (nodeCount) > 1 {
log.Fatalf("Malformed portmapping '%s' lacks a node filter, but there is more than one node (including the loadbalancer, if there is any).", portmap)
}
nodes, err := cliutil.FilterNodes(append(cluster.Nodes, cluster.MasterLoadBalancer), filters)
nodes, err := cliutil.FilterNodes(nodeList, filters)
if err != nil {
log.Fatalln(err)
}

@ -67,7 +67,7 @@ func SplitFiltersFromFlag(flag string) (string, []string, error) {
func FilterNodes(nodes []*k3d.Node, filters []string) ([]*k3d.Node, error) {
if len(filters) == 0 || len(filters[0]) == 0 {
log.Warnln("No filter specified")
log.Warnln("No node filter specified")
return nodes, nil
}

Loading…
Cancel
Save