From 7ebe011ec84769a186181ef03fc8957ef8ef45d2 Mon Sep 17 00:00:00 2001 From: Mike Petersen Date: Thu, 20 Aug 2020 11:45:33 -0700 Subject: [PATCH 1/2] Added range options to --scale Fixed issues related to reviews and cleaned up some of the logic Removed error checking - will add back after more updates Ran build to update docs/created a helper script Updated helper function/cleaned it up and resolved failing tests Added checks for non ".." values and added more tests Updated wording and scaleconversion Added range options to --scale Fixed issues related to reviews and cleaned up some of the logic Removed error checking - will add back after more updates Ran build to update docs/created a helper script Updated helper function/cleaned it up and resolved failing tests Added checks for non ".." values and added more tests Updated wording and scaleconversion Added range options to --scale Fixed issues related to reviews and cleaned up some of the logic Ran build to update docs/created a helper script Updated helper function/cleaned it up and resolved failing tests Updated wording and scaleconversion Added range options to --scale Fixed issues related to reviews and cleaned up some of the logic Removed error checking - will add back after more updates Ran build to update docs/created a helper script Updated helper function/cleaned it up and resolved failing tests Added checks for non ".." values and added more tests Updated wording and scaleconversion Added comment about the helper function --- docs/cmd/kn_service_create.md | 33 ++++ docs/cmd/kn_service_update.md | 33 ++++ .../service/configuration_edit_flags.go | 162 +++++++++++++++++- pkg/kn/commands/service/create_test.go | 110 ++++++++++++ pkg/kn/commands/service/update_test.go | 142 +++++++++++++++ 5 files changed, 476 insertions(+), 4 deletions(-) diff --git a/docs/cmd/kn_service_create.md b/docs/cmd/kn_service_create.md index 0ffb240b2e..9bf2312426 100644 --- a/docs/cmd/kn_service_create.md +++ b/docs/cmd/kn_service_create.md @@ -86,8 +86,41 @@ kn service create NAME --image IMAGE --requests-cpu string DEPRECATED: please use --request instead. The requested CPU (e.g., 250m). --requests-memory string DEPRECATED: please use --request instead. The requested memory (e.g., 64Mi). --revision-name string The revision name to set. Must start with the service name and a dash as a prefix. Empty revision name will result in the server generating a name for the revision. Accepts golang templates, allowing {{.Service}} for the service name, {{.Generation}} for the generation, and {{.Random [n]}} for n random consonants. (default "{{.Service}}-{{.Random 5}}-{{.Generation}}") +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD + --scale string Minimum and maximum number of replicas. (default "1") +======= +======= +>>>>>>> 94a12104... Fixed issues related to reviews and cleaned up some of the logic +<<<<<<< HEAD --scale int Minimum and maximum number of replicas. --scale-init int Initial number of replicas with which a service starts. Can be 0 or a positive integer. +======= + --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. +>>>>>>> Added range options to --scale +<<<<<<< HEAD +>>>>>>> 5fe3da0e... Added range options to --scale +======= +======= + --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. +>>>>>>> Fixed issues related to reviews and cleaned up some of the logic +>>>>>>> 94a12104... Fixed issues related to reviews and cleaned up some of the logic +======= + --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. +>>>>>>> 2d7c206c... Ran build to update docs/created a helper script +======= + --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. +>>>>>>> 29dc3a98... Added range options to --scale +======= + --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. +>>>>>>> 49c7a26a... Fixed issues related to reviews and cleaned up some of the logic +======= + --scale string Minimum and maximum number of replicas. (default "1") +>>>>>>> 7f05b8c4... Ran build to update docs/created a helper script --scale-max int Maximum number of replicas. --scale-min int Minimum number of replicas. --service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace. diff --git a/docs/cmd/kn_service_update.md b/docs/cmd/kn_service_update.md index 007a029233..3bd077ce9b 100644 --- a/docs/cmd/kn_service_update.md +++ b/docs/cmd/kn_service_update.md @@ -69,8 +69,41 @@ kn service update NAME --requests-cpu string DEPRECATED: please use --request instead. The requested CPU (e.g., 250m). --requests-memory string DEPRECATED: please use --request instead. The requested memory (e.g., 64Mi). --revision-name string The revision name to set. Must start with the service name and a dash as a prefix. Empty revision name will result in the server generating a name for the revision. Accepts golang templates, allowing {{.Service}} for the service name, {{.Generation}} for the generation, and {{.Random [n]}} for n random consonants. (default "{{.Service}}-{{.Random 5}}-{{.Generation}}") +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD + --scale string Minimum and maximum number of replicas. (default "1") +======= +======= +>>>>>>> 94a12104... Fixed issues related to reviews and cleaned up some of the logic +<<<<<<< HEAD --scale int Minimum and maximum number of replicas. --scale-init int Initial number of replicas with which a service starts. Can be 0 or a positive integer. +======= + --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. +>>>>>>> Added range options to --scale +<<<<<<< HEAD +>>>>>>> 5fe3da0e... Added range options to --scale +======= +======= + --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. +>>>>>>> Fixed issues related to reviews and cleaned up some of the logic +>>>>>>> 94a12104... Fixed issues related to reviews and cleaned up some of the logic +======= + --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. +>>>>>>> 2d7c206c... Ran build to update docs/created a helper script +======= + --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. +>>>>>>> 29dc3a98... Added range options to --scale +======= + --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. +>>>>>>> 49c7a26a... Fixed issues related to reviews and cleaned up some of the logic +======= + --scale string Minimum and maximum number of replicas. (default "1") +>>>>>>> 7f05b8c4... Ran build to update docs/created a helper script --scale-max int Maximum number of replicas. --scale-min int Minimum number of replicas. --service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace. diff --git a/pkg/kn/commands/service/configuration_edit_flags.go b/pkg/kn/commands/service/configuration_edit_flags.go index d76d2381f4..fe08b77c18 100644 --- a/pkg/kn/commands/service/configuration_edit_flags.go +++ b/pkg/kn/commands/service/configuration_edit_flags.go @@ -15,6 +15,7 @@ package service import ( + "errors" "fmt" "strconv" "strings" @@ -38,7 +39,7 @@ type ConfigurationEditFlags struct { PodSpecFlags knflags.PodSpecFlags // Direct field manipulation - Scale int + Scale string MinScale int MaxScale int ConcurrencyTarget int @@ -85,7 +86,19 @@ func (p *ConfigurationEditFlags) addSharedFlags(command *cobra.Command) { command.Flags().MarkHidden("max-scale") p.markFlagMakesRevision("max-scale") - command.Flags().IntVar(&p.Scale, "scale", 0, "Minimum and maximum number of replicas.") +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD + command.Flags().StringVar(&p.Scale, "scale", "1", "Minimum and maximum number of replicas. (e.g., 1..5)") +======= + command.Flags().StringVar(&p.Scale, "scale", "", "Minimum and maximum number of replicas.") +>>>>>>> 29dc3a98... Added range options to --scale +======= + command.Flags().StringVar(&p.Scale, "scale", "1", "Minimum and maximum number of replicas.") +>>>>>>> 49c7a26a... Fixed issues related to reviews and cleaned up some of the logic +======= + command.Flags().StringVar(&p.Scale, "scale", "1", "Minimum and maximum number of replicas. (e.g., 1..5)") +>>>>>>> 3050e558... Updated wording and scaleconversion p.markFlagMakesRevision("scale") command.Flags().IntVar(&p.MinScale, "scale-min", 0, "Minimum number of replicas.") @@ -339,14 +352,71 @@ func (p *ConfigurationEditFlags) Apply( } else if cmd.Flags().Changed("scale-min") { return fmt.Errorf("only --scale or --scale-min can be specified") } else { - err = servinglib.UpdateMaxScale(template, p.Scale) +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD + scaleMin, scaleMax, err := p.scaleConversion(p.Scale) if err != nil { return err } - err = servinglib.UpdateMinScale(template, p.Scale) +======= + scaleMin, scaleMax, err := p.ScaleConversion(p.Scale) +<<<<<<< HEAD +>>>>>>> f9e53d51... Updated helper function/cleaned it up and resolved failing tests +======= +======= + scaleMin, scaleMax, err := p.scaleConversion(p.Scale) +>>>>>>> 3050e558... Updated wording and scaleconversion if err != nil { return err } +>>>>>>> 29514e26... Added checks for non ".." values and added more tests + err = servinglib.UpdateMaxScale(template, scaleMax) + if err != nil { + return err + } + err = servinglib.UpdateMinScale(template, scaleMin) + if err != nil { + return err +<<<<<<< HEAD +======= + if !strings.Contains(p.Scale, "..") { + scaleMin, _ := strconv.Atoi(p.Scale) + scaleMax := scaleMin + err = servinglib.UpdateMaxScale(template, scaleMax) + if err != nil { + return err + } + err = servinglib.UpdateMinScale(template, scaleMin) + if err != nil { + return err + } + } else { + scaleParts := strings.Split(p.Scale, "..") + scaleMin, _ := strconv.Atoi(scaleParts[0]) + scaleMax, _ := strconv.Atoi(scaleParts[1]) + if scaleMax > 0 { + err = servinglib.UpdateMaxScale(template, scaleMax) + if err != nil { + return err + } + } + if scaleMin > 0 { + err = servinglib.UpdateMinScale(template, scaleMin) + if err != nil { + return err + } + } +>>>>>>> 49c7a26a... Fixed issues related to reviews and cleaned up some of the logic + } + +======= + p.ScaleConversion(template, p.Scale) +>>>>>>> 7f05b8c4... Ran build to update docs/created a helper script +======= + } +>>>>>>> f9e53d51... Updated helper function/cleaned it up and resolved failing tests } } @@ -509,3 +579,87 @@ func (p *ConfigurationEditFlags) AnyMutation(cmd *cobra.Command) bool { } return false } + +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD +func (p *ConfigurationEditFlags) scaleConversion(scale string) (scaleMin int, scaleMax int, err error) { + if len(scale) <= 2 { + if !strings.Contains(scale, "..") { + scaleMin, err = strconv.Atoi(scale) + if err != nil { + return 0, 0, err + } + scaleMax = scaleMin + } + } else if strings.Contains(scale, "..") { + scaleParts := strings.Split(scale, "..") + if scaleParts[0] != "" { + scaleMin, err = strconv.Atoi(scaleParts[0]) + if err != nil { + return 0, 0, err + } + } + if scaleParts[1] != "" { + scaleMax, err = strconv.Atoi(scaleParts[1]) + if err != nil { + return 0, 0, err + } + } + } else { + return 0, 0, errors.New("Scale must be of the format x..y or x") + } + return scaleMin, scaleMax, err +======= +func (p *ConfigurationEditFlags) ScaleConversion(template *servingv1.RevisionTemplateSpec, scale string) { + var scaleMin, scaleMax int + var err error + +======= +func (p *ConfigurationEditFlags) ScaleConversion(scale string) (scaleMin int, scaleMax int, err error) { +<<<<<<< HEAD +>>>>>>> f9e53d51... Updated helper function/cleaned it up and resolved failing tests + if !strings.Contains(scale, "..") { + scaleMin, err = strconv.Atoi(scale) + if err != nil { + return 0, 0, err +======= +======= +======= +// Helper function for figuring out scale +>>>>>>> a8d3ddf8... Added comment about the helper function +func (p *ConfigurationEditFlags) scaleConversion(scale string) (scaleMin int, scaleMax int, err error) { +>>>>>>> 3050e558... Updated wording and scaleconversion + if len(scale) <= 2 { + if !strings.Contains(scale, "..") { + scaleMin, err = strconv.Atoi(scale) + if err != nil { + return 0, 0, err + } + scaleMax = scaleMin +>>>>>>> 29514e26... Added checks for non ".." values and added more tests + } + } else if strings.Contains(scale, "..") { + scaleParts := strings.Split(scale, "..") + if scaleParts[0] != "" { + scaleMin, err = strconv.Atoi(scaleParts[0]) + if err != nil { + return 0, 0, err + } + } + if scaleParts[1] != "" { + scaleMax, err = strconv.Atoi(scaleParts[1]) + if err != nil { + return 0, 0, err + } + } + } else { + return 0, 0, errors.New("Scale must be of the format x..y or x") + } +<<<<<<< HEAD +>>>>>>> 7f05b8c4... Ran build to update docs/created a helper script +======= + return scaleMin, scaleMax, err +>>>>>>> f9e53d51... Updated helper function/cleaned it up and resolved failing tests +} diff --git a/pkg/kn/commands/service/create_test.go b/pkg/kn/commands/service/create_test.go index aa03b2b5ab..94a92867a6 100644 --- a/pkg/kn/commands/service/create_test.go +++ b/pkg/kn/commands/service/create_test.go @@ -617,6 +617,116 @@ func TestServiceCreateScaleWithMinScaleSet(t *testing.T) { } +func TestServiceCreateScaleRange(t *testing.T) { + action, created, _, err := fakeServiceCreate([]string{ + "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", + "--scale", "1..5", "--no-wait"}, false) + + if err != nil { + t.Fatal(err) + } else if !action.Matches("create", "services") { + t.Fatalf("Bad action %v", action) + } + + template := &created.Spec.Template + + actualAnnos := template.Annotations + expectedAnnos := []string{ + "autoscaling.knative.dev/minScale", "1", + "autoscaling.knative.dev/maxScale", "5", + } + + for i := 0; i < len(expectedAnnos); i += 2 { + anno := expectedAnnos[i] + if actualAnnos[anno] != expectedAnnos[i+1] { + t.Fatalf("Unexpected annotation value for %s : %s (actual) != %s (expected)", + anno, actualAnnos[anno], expectedAnnos[i+1]) + } + } +} + +func TestServiceCreateScaleRangeOnlyMin(t *testing.T) { + action, created, _, err := fakeServiceCreate([]string{ + "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", + "--scale", "1..", "--no-wait"}, false) + + if err != nil { + t.Fatal(err) + } else if !action.Matches("create", "services") { + t.Fatalf("Bad action %v", action) + } + + template := &created.Spec.Template + + actualAnnos := template.Annotations + expectedAnnos := []string{ + "autoscaling.knative.dev/minScale", "1", + } + + for i := 0; i < len(expectedAnnos); i += 2 { + anno := expectedAnnos[i] + if actualAnnos[anno] != expectedAnnos[i+1] { + t.Fatalf("Unexpected annotation value for %s : %s (actual) != %s (expected)", + anno, actualAnnos[anno], expectedAnnos[i+1]) + } + } +} + +func TestServiceCreateScaleRangeOnlyMax(t *testing.T) { + action, created, _, err := fakeServiceCreate([]string{ + "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", + "--scale", "..5", "--no-wait"}, false) + + if err != nil { + t.Fatal(err) + } else if !action.Matches("create", "services") { + t.Fatalf("Bad action %v", action) + } + + template := &created.Spec.Template + + actualAnnos := template.Annotations + expectedAnnos := []string{ + "autoscaling.knative.dev/maxScale", "5", + } + + for i := 0; i < len(expectedAnnos); i += 2 { + anno := expectedAnnos[i] + if actualAnnos[anno] != expectedAnnos[i+1] { + t.Fatalf("Unexpected annotation value for %s : %s (actual) != %s (expected)", + anno, actualAnnos[anno], expectedAnnos[i+1]) + } + } +} + +func TestServiceCreateScaleRangeOnlyMinWrongSeparator(t *testing.T) { + _, _, _, err := fakeServiceCreate([]string{ + "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", + "--scale", "1--", "--no-wait"}, true) + if err == nil { + t.Fatal(err) + } + expectedErrMsg := "Scale must be of the format x..y or x" + if !strings.Contains(err.Error(), expectedErrMsg) { + t.Errorf("Invalid error output, expected: %s, got : '%s'", expectedErrMsg, err) + } + +} + +func TestServiceCreateScaleRangeOnlyMaxWrongSeparator(t *testing.T) { + _, _, _, err := fakeServiceCreate([]string{ + "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", + "--scale", "--1", "--no-wait"}, true) + if err == nil { + t.Fatal(err) + } + expectedErrMsg := "Scale must be of the format x..y or x" + if !strings.Contains(err.Error(), expectedErrMsg) { + t.Errorf("Invalid error output, expected: %s, got : '%s'", expectedErrMsg, err) + } + +} + func TestServiceCreateRequestsLimitsCPUMemory(t *testing.T) { action, created, _, err := fakeServiceCreate([]string{ "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", diff --git a/pkg/kn/commands/service/update_test.go b/pkg/kn/commands/service/update_test.go index a696824153..f2abf33ad2 100644 --- a/pkg/kn/commands/service/update_test.go +++ b/pkg/kn/commands/service/update_test.go @@ -446,6 +446,148 @@ func TestServiceUpdateScaleWithMinScaleSet(t *testing.T) { } } + +func TestServiceUpdateScaleWithRange(t *testing.T) { + original := newEmptyService() + + action, updated, _, err := fakeServiceUpdate(original, []string{ + "service", "update", "foo", + "--scale", "1..5", "--no-wait"}) + + if err != nil { + t.Fatal(err) + } else if !action.Matches("update", "services") { + t.Fatalf("Bad action %v", action) + } + + template := updated.Spec.Template + if err != nil { + t.Fatal(err) + } + + actualAnnos := template.Annotations + expectedAnnos := []string{ + "autoscaling.knative.dev/minScale", "1", + "autoscaling.knative.dev/maxScale", "5", + } + + for i := 0; i < len(expectedAnnos); i += 2 { + anno := expectedAnnos[i] + if actualAnnos[anno] != expectedAnnos[i+1] { + t.Fatalf("Unexpected annotation value for %s : %s (actual) != %s (expected)", + anno, actualAnnos[anno], expectedAnnos[i+1]) + } + } + +} + +func TestServiceUpdateScaleMinWithRange(t *testing.T) { + original := newEmptyService() + + action, updated, _, err := fakeServiceUpdate(original, []string{ + "service", "update", "foo", + "--scale", "1..", "--no-wait"}) + + if err != nil { + t.Fatal(err) + } else if !action.Matches("update", "services") { + t.Fatalf("Bad action %v", action) + } + + template := updated.Spec.Template + if err != nil { + t.Fatal(err) + } + + actualAnnos := template.Annotations + expectedAnnos := []string{ + "autoscaling.knative.dev/minScale", "1", + } + + for i := 0; i < len(expectedAnnos); i += 2 { + anno := expectedAnnos[i] + if actualAnnos[anno] != expectedAnnos[i+1] { + t.Fatalf("Unexpected annotation value for %s : %s (actual) != %s (expected)", + anno, actualAnnos[anno], expectedAnnos[i+1]) + } + } + +} + +func TestServiceUpdateScaleMaxWithRange(t *testing.T) { + original := newEmptyService() + + action, updated, _, err := fakeServiceUpdate(original, []string{ + "service", "update", "foo", + "--scale", "..5", "--no-wait"}) + + if err != nil { + t.Fatal(err) + } else if !action.Matches("update", "services") { + t.Fatalf("Bad action %v", action) + } + + template := updated.Spec.Template + if err != nil { + t.Fatal(err) + } + + actualAnnos := template.Annotations + expectedAnnos := []string{ + "autoscaling.knative.dev/maxScale", "5", + } + + for i := 0; i < len(expectedAnnos); i += 2 { + anno := expectedAnnos[i] + if actualAnnos[anno] != expectedAnnos[i+1] { + t.Fatalf("Unexpected annotation value for %s : %s (actual) != %s (expected)", + anno, actualAnnos[anno], expectedAnnos[i+1]) + } + } + +} + +func TestServiceUpdateScaleRangeOnlyMinWrongSeparator(t *testing.T) { + original := newEmptyService() + + _, _, _, err := fakeServiceUpdate(original, []string{ + "service", "update", "foo", + "--scale", "1--", "--no-wait"}) + + if err == nil { + t.Fatal("Expected error, got nil") + } + + expectedErrMsg := "Scale must be of the format x..y or x" + + if !strings.Contains(err.Error(), expectedErrMsg) { + t.Errorf("Invalid error output, expected: %s, got : '%s'", expectedErrMsg, err) + } + +} + +func TestServiceUpdateScaleRangeOnlyMaxWrongSeparator(t *testing.T) { + original := newEmptyService() + + _, _, _, err := fakeServiceUpdate(original, []string{ + "service", "update", "foo", + "--scale", "--1", "--no-wait"}) + + if err == nil { + t.Fatal("Expected error, got nil") + } + + expectedErrMsg := "Scale must be of the format x..y or x" + + if !strings.Contains(err.Error(), expectedErrMsg) { + t.Errorf("Invalid error output, expected: %s, got : '%s'", expectedErrMsg, err) + } +<<<<<<< HEAD +======= + +>>>>>>> 29514e26... Added checks for non ".." values and added more tests +} + func TestServiceUpdateEnv(t *testing.T) { orig := newEmptyService() From 0bc3b807ca8969b1683fcd1433ec7853e89c711e Mon Sep 17 00:00:00 2001 From: Mike Petersen Date: Wed, 7 Oct 2020 07:14:21 -0700 Subject: [PATCH 2/2] cleaned up after rebase --- docs/cmd/kn_service_create.md | 35 +---- docs/cmd/kn_service_update.md | 35 +---- .../service/configuration_edit_flags.go | 120 ------------------ pkg/kn/commands/service/update_test.go | 4 - 4 files changed, 2 insertions(+), 192 deletions(-) diff --git a/docs/cmd/kn_service_create.md b/docs/cmd/kn_service_create.md index 9bf2312426..580517bdf1 100644 --- a/docs/cmd/kn_service_create.md +++ b/docs/cmd/kn_service_create.md @@ -86,41 +86,8 @@ kn service create NAME --image IMAGE --requests-cpu string DEPRECATED: please use --request instead. The requested CPU (e.g., 250m). --requests-memory string DEPRECATED: please use --request instead. The requested memory (e.g., 64Mi). --revision-name string The revision name to set. Must start with the service name and a dash as a prefix. Empty revision name will result in the server generating a name for the revision. Accepts golang templates, allowing {{.Service}} for the service name, {{.Generation}} for the generation, and {{.Random [n]}} for n random consonants. (default "{{.Service}}-{{.Random 5}}-{{.Generation}}") -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - --scale string Minimum and maximum number of replicas. (default "1") -======= -======= ->>>>>>> 94a12104... Fixed issues related to reviews and cleaned up some of the logic -<<<<<<< HEAD - --scale int Minimum and maximum number of replicas. --scale-init int Initial number of replicas with which a service starts. Can be 0 or a positive integer. -======= - --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. ->>>>>>> Added range options to --scale -<<<<<<< HEAD ->>>>>>> 5fe3da0e... Added range options to --scale -======= -======= - --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. ->>>>>>> Fixed issues related to reviews and cleaned up some of the logic ->>>>>>> 94a12104... Fixed issues related to reviews and cleaned up some of the logic -======= - --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. ->>>>>>> 2d7c206c... Ran build to update docs/created a helper script -======= - --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. ->>>>>>> 29dc3a98... Added range options to --scale -======= - --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. ->>>>>>> 49c7a26a... Fixed issues related to reviews and cleaned up some of the logic -======= - --scale string Minimum and maximum number of replicas. (default "1") ->>>>>>> 7f05b8c4... Ran build to update docs/created a helper script + --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale-max int Maximum number of replicas. --scale-min int Minimum number of replicas. --service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace. diff --git a/docs/cmd/kn_service_update.md b/docs/cmd/kn_service_update.md index 3bd077ce9b..f047a5315c 100644 --- a/docs/cmd/kn_service_update.md +++ b/docs/cmd/kn_service_update.md @@ -69,41 +69,8 @@ kn service update NAME --requests-cpu string DEPRECATED: please use --request instead. The requested CPU (e.g., 250m). --requests-memory string DEPRECATED: please use --request instead. The requested memory (e.g., 64Mi). --revision-name string The revision name to set. Must start with the service name and a dash as a prefix. Empty revision name will result in the server generating a name for the revision. Accepts golang templates, allowing {{.Service}} for the service name, {{.Generation}} for the generation, and {{.Random [n]}} for n random consonants. (default "{{.Service}}-{{.Random 5}}-{{.Generation}}") -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - --scale string Minimum and maximum number of replicas. (default "1") -======= -======= ->>>>>>> 94a12104... Fixed issues related to reviews and cleaned up some of the logic -<<<<<<< HEAD - --scale int Minimum and maximum number of replicas. --scale-init int Initial number of replicas with which a service starts. Can be 0 or a positive integer. -======= - --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. ->>>>>>> Added range options to --scale -<<<<<<< HEAD ->>>>>>> 5fe3da0e... Added range options to --scale -======= -======= - --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. ->>>>>>> Fixed issues related to reviews and cleaned up some of the logic ->>>>>>> 94a12104... Fixed issues related to reviews and cleaned up some of the logic -======= - --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. ->>>>>>> 2d7c206c... Ran build to update docs/created a helper script -======= - --scale string Minimum and maximum number of replicas. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. ->>>>>>> 29dc3a98... Added range options to --scale -======= - --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. ->>>>>>> 49c7a26a... Fixed issues related to reviews and cleaned up some of the logic -======= - --scale string Minimum and maximum number of replicas. (default "1") ->>>>>>> 7f05b8c4... Ran build to update docs/created a helper script + --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale-max int Maximum number of replicas. --scale-min int Minimum number of replicas. --service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace. diff --git a/pkg/kn/commands/service/configuration_edit_flags.go b/pkg/kn/commands/service/configuration_edit_flags.go index fe08b77c18..7ddb3f2257 100644 --- a/pkg/kn/commands/service/configuration_edit_flags.go +++ b/pkg/kn/commands/service/configuration_edit_flags.go @@ -86,19 +86,7 @@ func (p *ConfigurationEditFlags) addSharedFlags(command *cobra.Command) { command.Flags().MarkHidden("max-scale") p.markFlagMakesRevision("max-scale") -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD command.Flags().StringVar(&p.Scale, "scale", "1", "Minimum and maximum number of replicas. (e.g., 1..5)") -======= - command.Flags().StringVar(&p.Scale, "scale", "", "Minimum and maximum number of replicas.") ->>>>>>> 29dc3a98... Added range options to --scale -======= - command.Flags().StringVar(&p.Scale, "scale", "1", "Minimum and maximum number of replicas.") ->>>>>>> 49c7a26a... Fixed issues related to reviews and cleaned up some of the logic -======= - command.Flags().StringVar(&p.Scale, "scale", "1", "Minimum and maximum number of replicas. (e.g., 1..5)") ->>>>>>> 3050e558... Updated wording and scaleconversion p.markFlagMakesRevision("scale") command.Flags().IntVar(&p.MinScale, "scale-min", 0, "Minimum number of replicas.") @@ -352,26 +340,10 @@ func (p *ConfigurationEditFlags) Apply( } else if cmd.Flags().Changed("scale-min") { return fmt.Errorf("only --scale or --scale-min can be specified") } else { -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - scaleMin, scaleMax, err := p.scaleConversion(p.Scale) - if err != nil { - return err - } -======= - scaleMin, scaleMax, err := p.ScaleConversion(p.Scale) -<<<<<<< HEAD ->>>>>>> f9e53d51... Updated helper function/cleaned it up and resolved failing tests -======= -======= scaleMin, scaleMax, err := p.scaleConversion(p.Scale) ->>>>>>> 3050e558... Updated wording and scaleconversion if err != nil { return err } ->>>>>>> 29514e26... Added checks for non ".." values and added more tests err = servinglib.UpdateMaxScale(template, scaleMax) if err != nil { return err @@ -379,44 +351,7 @@ func (p *ConfigurationEditFlags) Apply( err = servinglib.UpdateMinScale(template, scaleMin) if err != nil { return err -<<<<<<< HEAD -======= - if !strings.Contains(p.Scale, "..") { - scaleMin, _ := strconv.Atoi(p.Scale) - scaleMax := scaleMin - err = servinglib.UpdateMaxScale(template, scaleMax) - if err != nil { - return err - } - err = servinglib.UpdateMinScale(template, scaleMin) - if err != nil { - return err - } - } else { - scaleParts := strings.Split(p.Scale, "..") - scaleMin, _ := strconv.Atoi(scaleParts[0]) - scaleMax, _ := strconv.Atoi(scaleParts[1]) - if scaleMax > 0 { - err = servinglib.UpdateMaxScale(template, scaleMax) - if err != nil { - return err - } - } - if scaleMin > 0 { - err = servinglib.UpdateMinScale(template, scaleMin) - if err != nil { - return err - } - } ->>>>>>> 49c7a26a... Fixed issues related to reviews and cleaned up some of the logic } - -======= - p.ScaleConversion(template, p.Scale) ->>>>>>> 7f05b8c4... Ran build to update docs/created a helper script -======= - } ->>>>>>> f9e53d51... Updated helper function/cleaned it up and resolved failing tests } } @@ -580,57 +515,7 @@ func (p *ConfigurationEditFlags) AnyMutation(cmd *cobra.Command) bool { return false } -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -func (p *ConfigurationEditFlags) scaleConversion(scale string) (scaleMin int, scaleMax int, err error) { - if len(scale) <= 2 { - if !strings.Contains(scale, "..") { - scaleMin, err = strconv.Atoi(scale) - if err != nil { - return 0, 0, err - } - scaleMax = scaleMin - } - } else if strings.Contains(scale, "..") { - scaleParts := strings.Split(scale, "..") - if scaleParts[0] != "" { - scaleMin, err = strconv.Atoi(scaleParts[0]) - if err != nil { - return 0, 0, err - } - } - if scaleParts[1] != "" { - scaleMax, err = strconv.Atoi(scaleParts[1]) - if err != nil { - return 0, 0, err - } - } - } else { - return 0, 0, errors.New("Scale must be of the format x..y or x") - } - return scaleMin, scaleMax, err -======= -func (p *ConfigurationEditFlags) ScaleConversion(template *servingv1.RevisionTemplateSpec, scale string) { - var scaleMin, scaleMax int - var err error - -======= -func (p *ConfigurationEditFlags) ScaleConversion(scale string) (scaleMin int, scaleMax int, err error) { -<<<<<<< HEAD ->>>>>>> f9e53d51... Updated helper function/cleaned it up and resolved failing tests - if !strings.Contains(scale, "..") { - scaleMin, err = strconv.Atoi(scale) - if err != nil { - return 0, 0, err -======= -======= -======= -// Helper function for figuring out scale ->>>>>>> a8d3ddf8... Added comment about the helper function func (p *ConfigurationEditFlags) scaleConversion(scale string) (scaleMin int, scaleMax int, err error) { ->>>>>>> 3050e558... Updated wording and scaleconversion if len(scale) <= 2 { if !strings.Contains(scale, "..") { scaleMin, err = strconv.Atoi(scale) @@ -638,7 +523,6 @@ func (p *ConfigurationEditFlags) scaleConversion(scale string) (scaleMin int, sc return 0, 0, err } scaleMax = scaleMin ->>>>>>> 29514e26... Added checks for non ".." values and added more tests } } else if strings.Contains(scale, "..") { scaleParts := strings.Split(scale, "..") @@ -657,9 +541,5 @@ func (p *ConfigurationEditFlags) scaleConversion(scale string) (scaleMin int, sc } else { return 0, 0, errors.New("Scale must be of the format x..y or x") } -<<<<<<< HEAD ->>>>>>> 7f05b8c4... Ran build to update docs/created a helper script -======= return scaleMin, scaleMax, err ->>>>>>> f9e53d51... Updated helper function/cleaned it up and resolved failing tests } diff --git a/pkg/kn/commands/service/update_test.go b/pkg/kn/commands/service/update_test.go index f2abf33ad2..a1a114bfe0 100644 --- a/pkg/kn/commands/service/update_test.go +++ b/pkg/kn/commands/service/update_test.go @@ -582,10 +582,6 @@ func TestServiceUpdateScaleRangeOnlyMaxWrongSeparator(t *testing.T) { if !strings.Contains(err.Error(), expectedErrMsg) { t.Errorf("Invalid error output, expected: %s, got : '%s'", expectedErrMsg, err) } -<<<<<<< HEAD -======= - ->>>>>>> 29514e26... Added checks for non ".." values and added more tests } func TestServiceUpdateEnv(t *testing.T) {