Skip to content

Commit

Permalink
use byte quantity flag instead of int MiBs for memory args
Browse files Browse the repository at this point in the history
  • Loading branch information
bwagner5 committed Jul 31, 2020
1 parent 82c6499 commit 443ed67
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
13 changes: 6 additions & 7 deletions cmd/kops/toolbox_instance_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ func NewCmdToolboxInstanceSelector(f *util.Factory, out io.Writer) *cobra.Comman
// Raw Filters

commandline.IntMinMaxRangeFlags(vcpus, nil, nil, "Number of vcpus available to the instance type.")
commandline.IntMinMaxRangeFlags(memory, nil, nil, "Amount of memory available in MiB (Example: 4096)")
commandline.ByteQuantityMinMaxRangeFlags(memory, nil, nil, "Amount of memory available (Example: 4 GiB)")
commandline.RatioFlag(vcpusToMemoryRatio, nil, nil, "The ratio of vcpus to memory in MiB. (Example: 1:2)")
commandline.StringOptionsFlag(cpuArchitecture, nil, &cpuArchDefault, fmt.Sprintf("CPU architecture [%s]", strings.Join(cpuArchs, ", ")), append(cpuArchs, cpuArchitectureX8664))
commandline.IntMinMaxRangeFlags(gpus, nil, nil, "Total number of GPUs (Example: 4)")
commandline.IntMinMaxRangeFlags(gpuMemoryTotal, nil, nil, "Number of GPUs' total memory in MiB (Example: 4096)")
commandline.ByteQuantityMinMaxRangeFlags(gpuMemoryTotal, nil, nil, "Number of GPUs' total memory (Example: 4 GiB)")
commandline.StringOptionsFlag(placementGroupStrategy, nil, nil, fmt.Sprintf("Placement group strategy: [%s]", strings.Join(placementGroupStrategies, ", ")), placementGroupStrategies)
commandline.StringOptionsFlag(usageClass, nil, &usageClassDefault, fmt.Sprintf("Usage class: [%s]", strings.Join(usageClasses, ", ")), usageClasses)
commandline.BoolFlag(enaSupport, nil, nil, "Instance types where ENA is supported or required")
Expand Down Expand Up @@ -275,7 +275,7 @@ func RunToolboxInstanceSelector(ctx context.Context, f *util.Factory, args []str
return err
}
if instanceSelectorOpts.ClusterAutoscaler {
ig = decorateWithClusterAutoscalerLabels(ig)
ig = decorateWithClusterAutoscalerLabels(ig, cluster.ClusterName)
}
ig, err = cloudup.PopulateInstanceGroupSpec(cluster, ig, channel)
if err != nil {
Expand Down Expand Up @@ -369,11 +369,11 @@ func getFilters(commandline *cli.CommandLineInterface, region string, zones []st
flags := commandline.Flags
return selector.Filters{
VCpusRange: commandline.IntRangeMe(flags[vcpus]),
MemoryRange: commandline.IntRangeMe(flags[memory]),
MemoryRange: commandline.ByteQuantityRangeMe(flags[memory]),
VCpusToMemoryRatio: commandline.Float64Me(flags[vcpusToMemoryRatio]),
CPUArchitecture: commandline.StringMe(flags[cpuArchitecture]),
GpusRange: commandline.IntRangeMe(flags[gpus]),
GpuMemoryRange: commandline.IntRangeMe(flags[gpuMemoryTotal]),
GpuMemoryRange: commandline.ByteQuantityRangeMe(flags[gpuMemoryTotal]),
PlacementGroupStrategy: commandline.StringMe(flags[placementGroupStrategy]),
UsageClass: commandline.StringMe(flags[usageClass]),
EnaSupport: commandline.BoolMe(flags[enaSupport]),
Expand Down Expand Up @@ -509,9 +509,8 @@ func decorateWithMixedInstancesPolicy(instanceGroup *kops.InstanceGroup, usageCl
}

// decorateWithClusterAutoscalerLabels adds cluster-autoscaler discovery tags to the cloudlabels slice
func decorateWithClusterAutoscalerLabels(instanceGroup *kops.InstanceGroup) *kops.InstanceGroup {
func decorateWithClusterAutoscalerLabels(instanceGroup *kops.InstanceGroup, clusterName string) *kops.InstanceGroup {
ig := instanceGroup
clusterName := instanceGroup.ObjectMeta.Name
if ig.Spec.CloudLabels == nil {
ig.Spec.CloudLabels = make(map[string]string)
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/kops/toolbox_instance_selector_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,13 @@ func TestDecorateWithMixedInstancesPolicy(t *testing.T) {

func TestDecorateWithClusterAutoscalerLabels(t *testing.T) {
initialIG := kops.InstanceGroup{}
initialIG.ObjectMeta.Name = "testInstanceGroup"
clusterName := "testClusterName"

actualIG := decorateWithClusterAutoscalerLabels(&initialIG)
actualIG := decorateWithClusterAutoscalerLabels(&initialIG, clusterName)
if _, ok := actualIG.Spec.CloudLabels["k8s.io/cluster-autoscaler/enabled"]; !ok {
t.Fatalf("cloudLabels for cluster autoscaler should have been added to the instance group spec")
t.Fatalf("enabled cloudLabel for cluster autoscaler should have been added to the instance group spec")
}
if _, ok := actualIG.Spec.CloudLabels["k8s.io/cluster-autoscaler/"+clusterName]; !ok {
t.Fatalf("cluster cloudLabel for cluster autoscaler should have been added to the instance group spec")
}
}
12 changes: 6 additions & 6 deletions docs/cli/kops_toolbox_instance-selector.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ kops toolbox instance-selector [flags]
--dry-run If true, only print the object that would be sent, without sending it. This flag can be used to create a cluster YAML or JSON manifest.
--ena-support Instance types where ENA is supported or required
--flexible Retrieves a group of instance types spanning multiple generations based on opinionated defaults and user overridden resource filters
--gpu-memory-total int Number of GPUs' total memory in MiB (Example: 4096) (sets --gpu-memory-total-min and -max to the same value)
--gpu-memory-total-max int Maximum Number of GPUs' total memory in MiB (Example: 4096) If --gpu-memory-total-min is not specified, the lower bound will be 0
--gpu-memory-total-min int Minimum Number of GPUs' total memory in MiB (Example: 4096) If --gpu-memory-total-max is not specified, the upper bound will be infinity
--gpu-memory-total string Number of GPUs' total memory (Example: 4 GiB) (sets --gpu-memory-total-min and -max to the same value)
--gpu-memory-total-max string Maximum Number of GPUs' total memory (Example: 4 GiB) If --gpu-memory-total-min is not specified, the lower bound will be 0
--gpu-memory-total-min string Minimum Number of GPUs' total memory (Example: 4 GiB) If --gpu-memory-total-max is not specified, the upper bound will be infinity
--gpus int Total number of GPUs (Example: 4) (sets --gpus-min and -max to the same value)
--gpus-max int Maximum Total number of GPUs (Example: 4) If --gpus-min is not specified, the lower bound will be 0
--gpus-min int Minimum Total number of GPUs (Example: 4) If --gpus-max is not specified, the upper bound will be infinity
-h, --help help for instance-selector
--ig-count int Number of instance groups to create w/ different vcpus-to-memory-ratios starting at 1:2 and doubling.
--max-results int Maximum number of instance types to return back (default 20)
--memory int Amount of memory available in MiB (Example: 4096) (sets --memory-min and -max to the same value)
--memory-max int Maximum Amount of memory available in MiB (Example: 4096) If --memory-min is not specified, the lower bound will be 0
--memory-min int Minimum Amount of memory available in MiB (Example: 4096) If --memory-max is not specified, the upper bound will be infinity
--memory string Amount of memory available (Example: 4 GiB) (sets --memory-min and -max to the same value)
--memory-max string Maximum Amount of memory available (Example: 4 GiB) If --memory-min is not specified, the lower bound will be 0
--memory-min string Minimum Amount of memory available (Example: 4 GiB) If --memory-max is not specified, the upper bound will be infinity
--network-interfaces int Number of network interfaces (ENIs) that can be attached to the instance (sets --network-interfaces-min and -max to the same value)
--network-interfaces-max int Maximum Number of network interfaces (ENIs) that can be attached to the instance If --network-interfaces-min is not specified, the lower bound will be 0
--network-interfaces-min int Minimum Number of network interfaces (ENIs) that can be attached to the instance If --network-interfaces-max is not specified, the upper bound will be infinity
Expand Down

0 comments on commit 443ed67

Please sign in to comment.