mirror of https://github.com/kubernetes/kops.git
Merge pull request #15458 from peaaceChoi/master
Support intstr.IntOrString type in cmd
This commit is contained in:
commit
9cbb48c4a2
|
@ -66,7 +66,7 @@ func TestEditInstanceGroup(t *testing.T) {
|
||||||
editOptions := &EditInstanceGroupOptions{
|
editOptions := &EditInstanceGroupOptions{
|
||||||
ClusterName: clusterName,
|
ClusterName: clusterName,
|
||||||
GroupName: "nodes",
|
GroupName: "nodes",
|
||||||
Sets: []string{"spec.maxSize=10"},
|
Sets: []string{"spec.maxSize=10", "spec.rollingUpdate.maxUnavailable=50%"},
|
||||||
}
|
}
|
||||||
err := RunEditInstanceGroup(ctx, factory, &stdout, editOptions)
|
err := RunEditInstanceGroup(ctx, factory, &stdout, editOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,6 +10,8 @@ spec:
|
||||||
image: ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20220404
|
image: ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20220404
|
||||||
maxSize: 10
|
maxSize: 10
|
||||||
role: Node
|
role: Node
|
||||||
|
rollingUpdate:
|
||||||
|
maxUnavailable: 50%
|
||||||
subnets:
|
subnets:
|
||||||
- subnet-us-test-1a
|
- subnet-us-test-1a
|
||||||
taints:
|
taints:
|
||||||
|
|
|
@ -21,6 +21,8 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetString(target interface{}, targetPath string, newValue string) error {
|
func SetString(target interface{}, targetPath string, newValue string) error {
|
||||||
|
@ -43,7 +45,7 @@ func SetString(target interface{}, targetPath string, newValue string) error {
|
||||||
return fmt.Errorf("cannot set field %q (marked immutable)", path)
|
return fmt.Errorf("cannot set field %q (marked immutable)", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setPrimitive(v, newValue); err != nil {
|
if err := setType(v, newValue); err != nil {
|
||||||
return fmt.Errorf("cannot set field %q: %v", path, err)
|
return fmt.Errorf("cannot set field %q: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +91,7 @@ func SetString(target interface{}, targetPath string, newValue string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setPrimitive(v reflect.Value, newValue string) error {
|
func setType(v reflect.Value, newValue string) error {
|
||||||
if !v.CanSet() {
|
if !v.CanSet() {
|
||||||
return fmt.Errorf("cannot set value")
|
return fmt.Errorf("cannot set value")
|
||||||
}
|
}
|
||||||
|
@ -103,7 +105,7 @@ func setPrimitive(v reflect.Value, newValue string) error {
|
||||||
valueArray = reflect.AppendSlice(valueArray, v)
|
valueArray = reflect.AppendSlice(valueArray, v)
|
||||||
for _, s := range tokens {
|
for _, s := range tokens {
|
||||||
valueItem := reflect.New(v.Type().Elem())
|
valueItem := reflect.New(v.Type().Elem())
|
||||||
if err := setPrimitive(valueItem.Elem(), s); err != nil {
|
if err := setType(valueItem.Elem(), s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
valueArray = reflect.Append(valueArray, valueItem.Elem())
|
valueArray = reflect.Append(valueArray, valueItem.Elem())
|
||||||
|
@ -119,7 +121,7 @@ func setPrimitive(v reflect.Value, newValue string) error {
|
||||||
|
|
||||||
if v.Type().Kind() == reflect.Ptr {
|
if v.Type().Kind() == reflect.Ptr {
|
||||||
val := reflect.New(v.Type().Elem())
|
val := reflect.New(v.Type().Elem())
|
||||||
if err := setPrimitive(val.Elem(), newValue); err != nil {
|
if err := setType(val.Elem(), newValue); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
v.Set(val)
|
v.Set(val)
|
||||||
|
@ -159,6 +161,8 @@ func setPrimitive(v reflect.Value, newValue string) error {
|
||||||
default:
|
default:
|
||||||
panic("missing case in switch")
|
panic("missing case in switch")
|
||||||
}
|
}
|
||||||
|
case "intstr.IntOrString":
|
||||||
|
newV = reflect.ValueOf(intstr.Parse(newValue))
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// This handles enums and other simple conversions
|
// This handles enums and other simple conversions
|
||||||
|
|
Loading…
Reference in New Issue