remove debug prints and add some comments
This commit is contained in:
parent
b99ee41558
commit
f87c7cd9fa
@ -130,14 +130,18 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string) (runtimes.Runtime,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// volumeFilterMap will map volume mounts to applied node filters
|
||||||
volumeFilterMap := make(map[string]string, 1)
|
volumeFilterMap := make(map[string]string, 1)
|
||||||
for _, volumeFlag := range volumeFlags {
|
for _, volumeFlag := range volumeFlags {
|
||||||
log.Debugf("Parsing vol flag %+v", volumeFlag)
|
|
||||||
|
// split node filter from the specified volume
|
||||||
volume, filter, err := cliutil.SplitFilterFromFlag(volumeFlag)
|
volume, filter, err := cliutil.SplitFilterFromFlag(volumeFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
log.Debugf("Parsed vol flag %+v + filter %+v", volume, filter)
|
|
||||||
|
// validate the specified volume mount and return it in SRC:DEST format
|
||||||
volume, err = cliutil.ValidateVolumeMount(volume)
|
volume, err = cliutil.ValidateVolumeMount(volume)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
@ -149,9 +153,7 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string) (runtimes.Runtime,
|
|||||||
} else {
|
} else {
|
||||||
volumeFilterMap[volume] = filter
|
volumeFilterMap[volume] = filter
|
||||||
}
|
}
|
||||||
log.Debugf("volFilterMap %+v", volumeFilterMap)
|
|
||||||
}
|
}
|
||||||
log.Debugf("volumeFIlterMap: %+v", volumeFilterMap)
|
|
||||||
|
|
||||||
/* generate cluster */
|
/* generate cluster */
|
||||||
cluster := &k3d.Cluster{
|
cluster := &k3d.Cluster{
|
||||||
@ -191,7 +193,6 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string) (runtimes.Runtime,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// append volumes
|
// append volumes
|
||||||
// TODO:
|
|
||||||
for volume, filter := range volumeFilterMap {
|
for volume, filter := range volumeFilterMap {
|
||||||
nodes, err := cliutil.FilterNodes(cluster.Nodes, filter)
|
nodes, err := cliutil.FilterNodes(cluster.Nodes, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -102,8 +102,7 @@ func FilterNodes(nodes []*k3d.Node, filterString string) ([]*k3d.Node, error) {
|
|||||||
// range over all instances of group[subset] specs
|
// range over all instances of group[subset] specs
|
||||||
for _, filter := range filters {
|
for _, filter := range filters {
|
||||||
|
|
||||||
/* Step 1: match regular expression */
|
// match regex with capturing groups
|
||||||
|
|
||||||
match := filterRegexp.FindStringSubmatch(filter)
|
match := filterRegexp.FindStringSubmatch(filter)
|
||||||
|
|
||||||
if len(match) == 0 {
|
if len(match) == 0 {
|
||||||
@ -113,10 +112,6 @@ func FilterNodes(nodes []*k3d.Node, filterString string) ([]*k3d.Node, error) {
|
|||||||
// map capturing group names to submatches
|
// map capturing group names to submatches
|
||||||
submatches := mapSubexpNames(filterRegexp.SubexpNames(), match)
|
submatches := mapSubexpNames(filterRegexp.SubexpNames(), match)
|
||||||
|
|
||||||
log.Debugf("Matches: %+v", submatches)
|
|
||||||
|
|
||||||
/* Step 2 - Evaluate */
|
|
||||||
|
|
||||||
// if one of the filters is 'all', we only return this and drop all others
|
// if one of the filters is 'all', we only return this and drop all others
|
||||||
if submatches["group"] == "all" {
|
if submatches["group"] == "all" {
|
||||||
// TODO: only log if really more than one is specified
|
// TODO: only log if really more than one is specified
|
||||||
@ -124,7 +119,7 @@ func FilterNodes(nodes []*k3d.Node, filterString string) ([]*k3d.Node, error) {
|
|||||||
return nodes, nil
|
return nodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Choose the group of nodes to operate on */
|
// Choose the group of nodes to operate on
|
||||||
groupNodes := []*k3d.Node{}
|
groupNodes := []*k3d.Node{}
|
||||||
if submatches["group"] == string(k3d.MasterRole) {
|
if submatches["group"] == string(k3d.MasterRole) {
|
||||||
groupNodes = masterNodes
|
groupNodes = masterNodes
|
||||||
@ -132,7 +127,7 @@ func FilterNodes(nodes []*k3d.Node, filterString string) ([]*k3d.Node, error) {
|
|||||||
groupNodes = workerNodes
|
groupNodes = workerNodes
|
||||||
}
|
}
|
||||||
|
|
||||||
/* subset defined by list */
|
/* Option 1) subset defined by list */
|
||||||
if submatches["subsetList"] != "" {
|
if submatches["subsetList"] != "" {
|
||||||
for _, index := range strings.Split(submatches["subsetList"], ",") {
|
for _, index := range strings.Split(submatches["subsetList"], ",") {
|
||||||
if index != "" {
|
if index != "" {
|
||||||
@ -150,7 +145,7 @@ func FilterNodes(nodes []*k3d.Node, filterString string) ([]*k3d.Node, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* subset defined by range */
|
/* Option 2) subset defined by range */
|
||||||
} else if submatches["subsetRange"] != "" {
|
} else if submatches["subsetRange"] != "" {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -195,7 +190,7 @@ func FilterNodes(nodes []*k3d.Node, filterString string) ([]*k3d.Node, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* subset defined by wildcard */
|
/* Option 3) subset defined by wildcard */
|
||||||
} else if submatches["subsetWildcard"] == "*" {
|
} else if submatches["subsetWildcard"] == "*" {
|
||||||
/*
|
/*
|
||||||
* '*' = all nodes
|
* '*' = all nodes
|
||||||
@ -207,14 +202,12 @@ func FilterNodes(nodes []*k3d.Node, filterString string) ([]*k3d.Node, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* invalid/unknown subset */
|
/* Option X) invalid/unknown subset */
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("Failed to parse node specifiers: unknown subset in '%s'", filter)
|
return nil, fmt.Errorf("Failed to parse node specifiers: unknown subset in '%s'", filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Filtered nodes: %+v", filteredNodes)
|
|
||||||
|
|
||||||
return filteredNodes, nil
|
return filteredNodes, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user