Skip to content

Commit

Permalink
fix clusters not being filtered correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Apr 18, 2019
1 parent 7d5964c commit 92039ed
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ func getClusters() (map[string]cluster, error) {
return nil, fmt.Errorf("ERROR: couldn't create docker client\n%+v", err)
}

// Prepare docker label filters
filters := filters.NewArgs()
filters.Add("label", "app=k3d")
filters.Add("label", "component=server")

// get all servers created by k3d
k3dServers, err := docker.ContainerList(ctx, types.ContainerListOptions{
All: true,
Filters: filters,
Expand All @@ -135,17 +137,25 @@ func getClusters() (map[string]cluster, error) {
}

clusters := make(map[string]cluster)

// don't filter for servers but for workers now
filters.Del("label", "component=server")
filters.Add("label", "component=worker")

// for all servers created by k3d, get workers and cluster information
for _, server := range k3dServers {
filters.Add("label", fmt.Sprintf("cluster=%s", server.Labels["cluster"]))
filters.Del("label", "component=server")
filters.Add("label", "component=worker")

// get workers
workers, err := docker.ContainerList(ctx, types.ContainerListOptions{
All: true,
Filters: filters,
})
if err != nil {
return nil, fmt.Errorf("WARNING: couldn't list worker containers for cluster %s\n%+v", server.Labels["cluster"], err)
log.Printf("WARNING: couldn't get worker containers for cluster %s\n%+v", server.Labels["cluster"], err)
}

// save cluster information
serverPorts := []string{}
for _, port := range server.Ports {
serverPorts = append(serverPorts, strconv.Itoa(int(port.PublicPort)))
Expand All @@ -158,6 +168,8 @@ func getClusters() (map[string]cluster, error) {
server: server,
workers: workers,
}
// clear label filters before searching for next cluster
filters.Del("label", fmt.Sprintf("cluster=%s", server.Labels["cluster"]))
}
return clusters, nil
}
Expand Down

0 comments on commit 92039ed

Please sign in to comment.