From 487b02269fd037ee39f70a19bef460bc0805a0fa Mon Sep 17 00:00:00 2001 From: Daisy Guo Date: Wed, 14 Oct 2020 17:14:29 +0800 Subject: [PATCH] refactor code base --- .../service/configuration_edit_flags.go | 72 ------------------- pkg/util/corev1_helper.go | 2 +- 2 files changed, 1 insertion(+), 73 deletions(-) diff --git a/pkg/kn/commands/service/configuration_edit_flags.go b/pkg/kn/commands/service/configuration_edit_flags.go index 647a5040c8..82f4a8578a 100644 --- a/pkg/kn/commands/service/configuration_edit_flags.go +++ b/pkg/kn/commands/service/configuration_edit_flags.go @@ -21,8 +21,6 @@ import ( "github.com/spf13/cobra" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" knflags "knative.dev/client/pkg/kn/flags" @@ -245,50 +243,6 @@ func (p *ConfigurationEditFlags) Apply( fmt.Fprintf(cmd.OutOrStdout(), "\nWARNING: flags --requests-cpu / --requests-memory are deprecated and going to be removed in future release, please use --request instead.\n\n") } - limitsResources, err := p.computeResources(p.PodSpecFlags.LimitsFlags) - if err != nil { - return err - } - requestsResources, err := p.computeResources(p.PodSpecFlags.RequestsFlags) - if err != nil { - return err - } - err = servinglib.UpdateResourcesDeprecated(template, requestsResources, limitsResources) - if err != nil { - return err - } - - requestsToRemove, limitsToRemove, err := p.PodSpecFlags.Resources.Validate() - if err != nil { - return err - } - - err = servinglib.UpdateResources(template, p.PodSpecFlags.Resources.ResourceRequirements, requestsToRemove, limitsToRemove) - if err != nil { - return err - } - - if cmd.Flags().Changed("cmd") { - err = servinglib.UpdateContainerCommand(template, p.PodSpecFlags.Command) - if err != nil { - return err - } - } - - if cmd.Flags().Changed("arg") { - err = servinglib.UpdateContainerArg(template, p.PodSpecFlags.Arg) - if err != nil { - return err - } - } - - if cmd.Flags().Changed("port") { - err = servinglib.UpdateContainerPort(template, p.PodSpecFlags.Port) - if err != nil { - return err - } - } - // Deprecated "min-scale" in 0.19, updated to "scale-min" if cmd.Flags().Changed("scale-min") || cmd.Flags().Changed("min-scale") { err = servinglib.UpdateMinScale(template, p.MinScale) @@ -462,32 +416,6 @@ func (p *ConfigurationEditFlags) updateLabels(obj *metav1.ObjectMeta, flagLabels return nil } -func (p *ConfigurationEditFlags) computeResources(resourceFlags knflags.ResourceFlags) (corev1.ResourceList, error) { - resourceList := corev1.ResourceList{} - - if resourceFlags.CPU != "" { - cpuQuantity, err := resource.ParseQuantity(resourceFlags.CPU) - if err != nil { - return corev1.ResourceList{}, - fmt.Errorf("Error parsing %q: %w", resourceFlags.CPU, err) - } - - resourceList[corev1.ResourceCPU] = cpuQuantity - } - - if resourceFlags.Memory != "" { - memoryQuantity, err := resource.ParseQuantity(resourceFlags.Memory) - if err != nil { - return corev1.ResourceList{}, - fmt.Errorf("Error parsing %q: %w", resourceFlags.Memory, err) - } - - resourceList[corev1.ResourceMemory] = memoryQuantity - } - - return resourceList, nil -} - // AnyMutation returns true if there are any revision template mutations in the // command. func (p *ConfigurationEditFlags) AnyMutation(cmd *cobra.Command) bool { diff --git a/pkg/util/corev1_helper.go b/pkg/util/corev1_helper.go index 9c4cca36d7..22f23f2df2 100644 --- a/pkg/util/corev1_helper.go +++ b/pkg/util/corev1_helper.go @@ -68,7 +68,7 @@ func GenerateVolumeName(path string) string { // the name must start with an alphanumeric character if !unicode.IsLetter(rune(vname[0])) && !unicode.IsNumber(rune(vname[0])) { - vname = fmt.Sprintf("k-%s", vname) + vname = "k-" + vname } // contain at most 63 characters