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{
|
||||
ClusterName: clusterName,
|
||||
GroupName: "nodes",
|
||||
Sets: []string{"spec.maxSize=10"},
|
||||
Sets: []string{"spec.maxSize=10", "spec.rollingUpdate.maxUnavailable=50%"},
|
||||
}
|
||||
err := RunEditInstanceGroup(ctx, factory, &stdout, editOptions)
|
||||
if err != nil {
|
||||
|
|
|
@ -10,6 +10,8 @@ spec:
|
|||
image: ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20220404
|
||||
maxSize: 10
|
||||
role: Node
|
||||
rollingUpdate:
|
||||
maxUnavailable: 50%
|
||||
subnets:
|
||||
- subnet-us-test-1a
|
||||
taints:
|
||||
|
|
|
@ -21,6 +21,8 @@ import (
|
|||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
if err := setPrimitive(v, newValue); err != nil {
|
||||
if err := setType(v, newValue); err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
func setPrimitive(v reflect.Value, newValue string) error {
|
||||
func setType(v reflect.Value, newValue string) error {
|
||||
if !v.CanSet() {
|
||||
return fmt.Errorf("cannot set value")
|
||||
}
|
||||
|
@ -103,7 +105,7 @@ func setPrimitive(v reflect.Value, newValue string) error {
|
|||
valueArray = reflect.AppendSlice(valueArray, v)
|
||||
for _, s := range tokens {
|
||||
valueItem := reflect.New(v.Type().Elem())
|
||||
if err := setPrimitive(valueItem.Elem(), s); err != nil {
|
||||
if err := setType(valueItem.Elem(), s); err != nil {
|
||||
return err
|
||||
}
|
||||
valueArray = reflect.Append(valueArray, valueItem.Elem())
|
||||
|
@ -119,7 +121,7 @@ func setPrimitive(v reflect.Value, newValue string) error {
|
|||
|
||||
if v.Type().Kind() == reflect.Ptr {
|
||||
val := reflect.New(v.Type().Elem())
|
||||
if err := setPrimitive(val.Elem(), newValue); err != nil {
|
||||
if err := setType(val.Elem(), newValue); err != nil {
|
||||
return err
|
||||
}
|
||||
v.Set(val)
|
||||
|
@ -159,6 +161,8 @@ func setPrimitive(v reflect.Value, newValue string) error {
|
|||
default:
|
||||
panic("missing case in switch")
|
||||
}
|
||||
case "intstr.IntOrString":
|
||||
newV = reflect.ValueOf(intstr.Parse(newValue))
|
||||
|
||||
default:
|
||||
// This handles enums and other simple conversions
|
||||
|
|
Loading…
Reference in New Issue