diff --git a/hack/.golint_failures b/hack/.golint_failures index bee5a5a403..ff8095da6e 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -141,7 +141,6 @@ pkg/kubeapiserver/authorizer/modes pkg/kubeapiserver/options pkg/kubectl pkg/kubectl/apps -pkg/kubectl/cmd pkg/kubectl/cmd/annotate pkg/kubectl/cmd/apiresources pkg/kubectl/cmd/apply @@ -189,8 +188,6 @@ pkg/kubectl/cmd/wait pkg/kubectl/generate pkg/kubectl/generate/versioned pkg/kubectl/metricsutil -pkg/kubectl/util -pkg/kubectl/util/slice pkg/kubectl/util/templates pkg/kubelet pkg/kubelet/apis diff --git a/pkg/kubectl/apply.go b/pkg/kubectl/apply.go index 3c82aee808..78447d498c 100644 --- a/pkg/kubectl/apply.go +++ b/pkg/kubectl/apply.go @@ -135,7 +135,8 @@ func CreateApplyAnnotation(obj runtime.Object, codec runtime.Encoder) error { return setOriginalConfiguration(obj, modified) } -// Create the annotation used by kubectl apply only when createAnnotation is true +// CreateOrUpdateAnnotation creates the annotation used by +// kubectl apply only when createAnnotation is true // Otherwise, only update the annotation when it already exists func CreateOrUpdateAnnotation(createAnnotation bool, obj runtime.Object, codec runtime.Encoder) error { if createAnnotation { diff --git a/pkg/kubectl/apps/kind_visitor_test.go b/pkg/kubectl/apps/kind_visitor_test.go index 10704b65e9..3d96920c6d 100644 --- a/pkg/kubectl/apps/kind_visitor_test.go +++ b/pkg/kubectl/apps/kind_visitor_test.go @@ -173,7 +173,7 @@ type TestKindVisitor struct { var _ apps.KindVisitor = &TestKindVisitor{} -func (t *TestKindVisitor) Visit(kind apps.GroupKindElement) { t.visits[kind.Kind] += 1 } +func (t *TestKindVisitor) Visit(kind apps.GroupKindElement) { t.visits[kind.Kind]++ } func (t *TestKindVisitor) VisitDaemonSet(kind apps.GroupKindElement) { t.Visit(kind) } func (t *TestKindVisitor) VisitDeployment(kind apps.GroupKindElement) { t.Visit(kind) } diff --git a/pkg/kubectl/cmd/apiresources/apiresources.go b/pkg/kubectl/cmd/apiresources/apiresources.go index b3f84bae97..c44b2537eb 100644 --- a/pkg/kubectl/cmd/apiresources/apiresources.go +++ b/pkg/kubectl/cmd/apiresources/apiresources.go @@ -77,7 +77,8 @@ func NewAPIResourceOptions(ioStreams genericclioptions.IOStreams) *ApiResourcesO } } -func NewCmdApiResources(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { +// NewCmdAPIResources creates the `api-resources` command +func NewCmdAPIResources(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { o := NewAPIResourceOptions(ioStreams) cmd := &cobra.Command{ diff --git a/pkg/kubectl/cmd/apiresources/apiversions.go b/pkg/kubectl/cmd/apiresources/apiversions.go index 5776086075..7f7b3ecaac 100644 --- a/pkg/kubectl/cmd/apiresources/apiversions.go +++ b/pkg/kubectl/cmd/apiresources/apiversions.go @@ -48,7 +48,8 @@ func NewApiVersionsOptions(ioStreams genericclioptions.IOStreams) *ApiVersionsOp } } -func NewCmdApiVersions(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { +// NewCmdAPIVersions creates the `api-versions` command +func NewCmdAPIVersions(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { o := NewApiVersionsOptions(ioStreams) cmd := &cobra.Command{ Use: "api-versions", diff --git a/pkg/kubectl/cmd/autoscale/autoscale.go b/pkg/kubectl/cmd/autoscale/autoscale.go index f51c93be5f..78b641a509 100644 --- a/pkg/kubectl/cmd/autoscale/autoscale.go +++ b/pkg/kubectl/cmd/autoscale/autoscale.go @@ -159,7 +159,7 @@ func (o *AutoscaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args CPUPercent: o.CpuPercent, ScaleRefName: name, ScaleRefKind: mapping.GroupVersionKind.Kind, - ScaleRefApiVersion: mapping.GroupVersionKind.GroupVersion().String(), + ScaleRefAPIVersion: mapping.GroupVersionKind.GroupVersion().String(), }, nil default: return nil, cmdutil.UsageErrorf(cmd, "Generator %s not supported. ", o.Generator) diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 43a541ecc9..c10116a17f 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -284,7 +284,7 @@ __custom_func() { ) var ( - bash_completion_flags = map[string]string{ + bashCompletionFlags = map[string]string{ "namespace": "__kubectl_get_resource_namespace", "context": "__kubectl_config_get_contexts", "cluster": "__kubectl_config_get_clusters", @@ -292,10 +292,12 @@ var ( } ) +// NewDefaultKubectlCommand creates the `kubectl` command with default arguments func NewDefaultKubectlCommand() *cobra.Command { return NewDefaultKubectlCommandWithArgs(&defaultPluginHandler{}, os.Args, os.Stdin, os.Stdout, os.Stderr) } +// NewDefaultKubectlCommandWithArgs creates the `kubectl` command with arguments func NewDefaultKubectlCommandWithArgs(pluginHandler PluginHandler, args []string, in io.Reader, out, errout io.Writer) *cobra.Command { cmd := NewKubectlCommand(in, out, errout) @@ -528,7 +530,7 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command { templates.ActsAsRootCommand(cmds, filters, groups...) - for name, completion := range bash_completion_flags { + for name, completion := range bashCompletionFlags { if cmds.Flag(name) != nil { if cmds.Flag(name).Annotations == nil { cmds.Flag(name).Annotations = map[string][]string{} @@ -544,8 +546,8 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command { cmds.AddCommand(cmdconfig.NewCmdConfig(f, clientcmd.NewDefaultPathOptions(), ioStreams)) cmds.AddCommand(plugin.NewCmdPlugin(f, ioStreams)) cmds.AddCommand(version.NewCmdVersion(f, ioStreams)) - cmds.AddCommand(apiresources.NewCmdApiVersions(f, ioStreams)) - cmds.AddCommand(apiresources.NewCmdApiResources(f, ioStreams)) + cmds.AddCommand(apiresources.NewCmdAPIVersions(f, ioStreams)) + cmds.AddCommand(apiresources.NewCmdAPIResources(f, ioStreams)) cmds.AddCommand(options.NewCmdOptions(ioStreams.Out)) return cmds diff --git a/pkg/kubectl/generate/generate.go b/pkg/kubectl/generate/generate.go index 65abaafd82..1915be8cb9 100644 --- a/pkg/kubectl/generate/generate.go +++ b/pkg/kubectl/generate/generate.go @@ -102,7 +102,7 @@ func AnnotateFlags(cmd *cobra.Command, generators map[string]Generator) { } } -// EnsureFlagsValid ensures that no invalid flags are being used against a +// EnsureFlagsValid ensures that no invalid flags are being used against a func EnsureFlagsValid(cmd *cobra.Command, generators map[string]Generator, generatorInUse string) error { AnnotateFlags(cmd, generators) diff --git a/pkg/kubectl/generate/versioned/autoscale.go b/pkg/kubectl/generate/versioned/autoscale.go index 790b07e581..7cb8dbbc50 100644 --- a/pkg/kubectl/generate/versioned/autoscale.go +++ b/pkg/kubectl/generate/versioned/autoscale.go @@ -25,12 +25,12 @@ import ( "k8s.io/kubernetes/pkg/kubectl/generate" ) -// HorizontalPodAutoscalerV1Generator supports stable generation of a horizontal pod autoscaler. +// HorizontalPodAutoscalerGeneratorV1 supports stable generation of a horizontal pod autoscaler. type HorizontalPodAutoscalerGeneratorV1 struct { Name string ScaleRefKind string ScaleRefName string - ScaleRefApiVersion string + ScaleRefAPIVersion string MinReplicas int32 MaxReplicas int32 CPUPercent int32 @@ -53,7 +53,7 @@ func (s *HorizontalPodAutoscalerGeneratorV1) StructuredGenerate() (runtime.Objec ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{ Kind: s.ScaleRefKind, Name: s.ScaleRefName, - APIVersion: s.ScaleRefApiVersion, + APIVersion: s.ScaleRefAPIVersion, }, MaxReplicas: s.MaxReplicas, }, diff --git a/pkg/kubectl/generate/versioned/autoscale_test.go b/pkg/kubectl/generate/versioned/autoscale_test.go index 49b76b5b36..c5f8ae74d4 100644 --- a/pkg/kubectl/generate/versioned/autoscale_test.go +++ b/pkg/kubectl/generate/versioned/autoscale_test.go @@ -31,7 +31,7 @@ func TestHPAGenerate(t *testing.T) { HPAName string scaleRefKind string scaleRefName string - scaleRefApiVersion string + scaleRefAPIVersion string minReplicas int32 maxReplicas int32 CPUPercent int32 @@ -46,7 +46,7 @@ func TestHPAGenerate(t *testing.T) { CPUPercent: 80, scaleRefKind: "kind", scaleRefName: "name", - scaleRefApiVersion: "apiVersion", + scaleRefAPIVersion: "apiVersion", expected: &autoscalingv1.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", @@ -68,7 +68,7 @@ func TestHPAGenerate(t *testing.T) { name: "'name' is a required parameter", scaleRefKind: "kind", scaleRefName: "name", - scaleRefApiVersion: "apiVersion", + scaleRefAPIVersion: "apiVersion", expectErr: true, }, { @@ -76,7 +76,7 @@ func TestHPAGenerate(t *testing.T) { HPAName: "foo", scaleRefKind: "kind", scaleRefName: "name", - scaleRefApiVersion: "apiVersion", + scaleRefAPIVersion: "apiVersion", expectErr: true, }, { @@ -86,7 +86,7 @@ func TestHPAGenerate(t *testing.T) { maxReplicas: 1, scaleRefKind: "kind", scaleRefName: "name", - scaleRefApiVersion: "apiVersion", + scaleRefAPIVersion: "apiVersion", expectErr: true, }, { @@ -96,7 +96,7 @@ func TestHPAGenerate(t *testing.T) { maxReplicas: -10, scaleRefKind: "kind", scaleRefName: "name", - scaleRefApiVersion: "apiVersion", + scaleRefAPIVersion: "apiVersion", expectErr: true, }, } @@ -107,7 +107,7 @@ func TestHPAGenerate(t *testing.T) { Name: tt.HPAName, ScaleRefKind: tt.scaleRefKind, ScaleRefName: tt.scaleRefName, - ScaleRefApiVersion: tt.scaleRefApiVersion, + ScaleRefAPIVersion: tt.scaleRefAPIVersion, MinReplicas: tt.minReplicas, MaxReplicas: tt.maxReplicas, CPUPercent: tt.CPUPercent, diff --git a/pkg/kubectl/generate/versioned/deployment.go b/pkg/kubectl/generate/versioned/deployment.go index d5b23eba8d..4b2b24d575 100644 --- a/pkg/kubectl/generate/versioned/deployment.go +++ b/pkg/kubectl/generate/versioned/deployment.go @@ -29,7 +29,7 @@ import ( "k8s.io/kubernetes/pkg/kubectl/generate" ) -// BaseDeploymentGenerator: implement the common functionality of +// BaseDeploymentGenerator implements the common functionality of // DeploymentBasicGeneratorV1, DeploymentBasicAppsGeneratorV1Beta1 and DeploymentBasicAppsGeneratorV1. To reduce // confusion, it's best to keep this struct in the same file as those // generators. diff --git a/pkg/kubectl/generate/versioned/secret.go b/pkg/kubectl/generate/versioned/secret.go index bca194139f..02b27519f4 100644 --- a/pkg/kubectl/generate/versioned/secret.go +++ b/pkg/kubectl/generate/versioned/secret.go @@ -205,7 +205,7 @@ func handleFromFileSources(secret *v1.Secret, fileSources []string) error { } if info.IsDir() { if strings.Contains(fileSource, "=") { - return fmt.Errorf("cannot give a key name for a directory path.") + return fmt.Errorf("cannot give a key name for a directory path") } fileList, err := ioutil.ReadDir(filePath) if err != nil { @@ -265,7 +265,7 @@ func addKeyFromLiteralToSecret(secret *v1.Secret, keyName string, data []byte) e } if _, entryExists := secret.Data[keyName]; entryExists { - return fmt.Errorf("cannot add key %s, another key by that name already exists: %v.", keyName, secret.Data) + return fmt.Errorf("cannot add key %s, another key by that name already exists: %v", keyName, secret.Data) } secret.Data[keyName] = data return nil diff --git a/pkg/kubectl/generate/versioned/secret_for_docker_registry.go b/pkg/kubectl/generate/versioned/secret_for_docker_registry.go index e8996b8f2c..db9d38448c 100644 --- a/pkg/kubectl/generate/versioned/secret_for_docker_registry.go +++ b/pkg/kubectl/generate/versioned/secret_for_docker_registry.go @@ -97,11 +97,11 @@ func (s SecretForDockerRegistryGeneratorV1) StructuredGenerate() (runtime.Object } } if len(s.FileSources) == 0 { - dockercfgJsonContent, err := handleDockerCfgJsonContent(s.Username, s.Password, s.Email, s.Server) + dockercfgJSONContent, err := handleDockerCfgJSONContent(s.Username, s.Password, s.Email, s.Server) if err != nil { return nil, err } - secret.Data[v1.DockerConfigJsonKey] = dockercfgJsonContent + secret.Data[v1.DockerConfigJsonKey] = dockercfgJSONContent } if s.AppendHash { h, err := hash.SecretHash(secret) @@ -146,24 +146,24 @@ func (s SecretForDockerRegistryGeneratorV1) validate() error { return nil } -// handleDockerCfgJsonContent serializes a ~/.docker/config.json file -func handleDockerCfgJsonContent(username, password, email, server string) ([]byte, error) { +// handleDockerCfgJSONContent serializes a ~/.docker/config.json file +func handleDockerCfgJSONContent(username, password, email, server string) ([]byte, error) { dockercfgAuth := DockerConfigEntry{ Username: username, Password: password, Email: email, } - dockerCfgJson := DockerConfigJson{ + dockerCfgJSON := DockerConfigJSON{ Auths: map[string]DockerConfigEntry{server: dockercfgAuth}, } - return json.Marshal(dockerCfgJson) + return json.Marshal(dockerCfgJSON) } -// DockerConfigJson represents a local docker auth config file +// DockerConfigJSON represents a local docker auth config file // for pulling images. -type DockerConfigJson struct { +type DockerConfigJSON struct { Auths DockerConfig `json:"auths"` // +optional HttpHeaders map[string]string `json:"HttpHeaders,omitempty"` diff --git a/pkg/kubectl/generate/versioned/secret_for_docker_registry_test.go b/pkg/kubectl/generate/versioned/secret_for_docker_registry_test.go index 3cb73f68f4..2b90e186ef 100644 --- a/pkg/kubectl/generate/versioned/secret_for_docker_registry_test.go +++ b/pkg/kubectl/generate/versioned/secret_for_docker_registry_test.go @@ -26,11 +26,11 @@ import ( func TestSecretForDockerRegistryGenerate(t *testing.T) { username, password, email, server := "test-user", "test-password", "test-user@example.org", "https://index.docker.io/v1/" - secretData, err := handleDockerCfgJsonContent(username, password, email, server) + secretData, err := handleDockerCfgJSONContent(username, password, email, server) if err != nil { t.Errorf("unexpected error: %v", err) } - secretDataNoEmail, err := handleDockerCfgJsonContent(username, password, "", server) + secretDataNoEmail, err := handleDockerCfgJSONContent(username, password, "", server) if err != nil { t.Errorf("unexpected error: %v", err) } diff --git a/pkg/kubectl/generate/versioned/service.go b/pkg/kubectl/generate/versioned/service.go index bea484098e..39d084bf9f 100644 --- a/pkg/kubectl/generate/versioned/service.go +++ b/pkg/kubectl/generate/versioned/service.go @@ -88,7 +88,7 @@ func generateService(genericParams map[string]interface{}) (runtime.Object, erro } selectorString, found := params["selector"] if !found || len(selectorString) == 0 { - return nil, fmt.Errorf("'selector' is a required parameter.") + return nil, fmt.Errorf("'selector' is a required parameter") } selector, err := generate.ParseLabels(selectorString) if err != nil { @@ -108,7 +108,7 @@ func generateService(genericParams map[string]interface{}) (runtime.Object, erro if !found || len(name) == 0 { name, found = params["default-name"] if !found || len(name) == 0 { - return nil, fmt.Errorf("'name' is a required parameter.") + return nil, fmt.Errorf("'name' is a required parameter") } } @@ -136,7 +136,7 @@ func generateService(genericParams map[string]interface{}) (runtime.Object, erro if portString, found = params["ports"]; !found { portString, found = params["port"] if !found && !isHeadlessService { - return nil, fmt.Errorf("'ports' or 'port' is a required parameter.") + return nil, fmt.Errorf("'ports' or 'port' is a required parameter") } } diff --git a/pkg/kubectl/metricsutil/metrics_client.go b/pkg/kubectl/metricsutil/metrics_client.go index 7b7c13d0b8..73399b233b 100644 --- a/pkg/kubectl/metricsutil/metrics_client.go +++ b/pkg/kubectl/metricsutil/metrics_client.go @@ -64,7 +64,7 @@ func NewHeapsterMetricsClient(svcClient corev1client.ServicesGetter, namespace, } } -func podMetricsUrl(namespace string, name string) (string, error) { +func podMetricsURL(namespace string, name string) (string, error) { if namespace == metav1.NamespaceAll { return fmt.Sprintf("%s/pods", metricsRoot), nil } @@ -83,7 +83,7 @@ func podMetricsUrl(namespace string, name string) (string, error) { return fmt.Sprintf("%s/namespaces/%s/pods/%s", metricsRoot, namespace, name), nil } -func nodeMetricsUrl(name string) (string, error) { +func nodeMetricsURL(name string) (string, error) { if len(name) > 0 { errs := validation.NameIsDNSSubdomain(name, false) if len(errs) > 0 { @@ -96,7 +96,7 @@ func nodeMetricsUrl(name string) (string, error) { func (cli *HeapsterMetricsClient) GetNodeMetrics(nodeName string, selector string) (*metricsapi.NodeMetricsList, error) { params := map[string]string{"labelSelector": selector} - path, err := nodeMetricsUrl(nodeName) + path, err := nodeMetricsURL(nodeName) if err != nil { return nil, err } @@ -130,7 +130,7 @@ func (cli *HeapsterMetricsClient) GetPodMetrics(namespace string, podName string if allNamespaces { namespace = metav1.NamespaceAll } - path, err := podMetricsUrl(namespace, podName) + path, err := podMetricsURL(namespace, podName) if err != nil { return nil, err } diff --git a/pkg/kubectl/rolling_updater.go b/pkg/kubectl/rolling_updater.go index 5874148380..b6df08c412 100644 --- a/pkg/kubectl/rolling_updater.go +++ b/pkg/kubectl/rolling_updater.go @@ -54,7 +54,7 @@ func valOrZero(val *int32) int32 { const ( kubectlAnnotationPrefix = "kubectl.kubernetes.io/" - sourceIdAnnotation = kubectlAnnotationPrefix + "update-source-id" + sourceIDAnnotation = kubectlAnnotationPrefix + "update-source-id" desiredReplicasAnnotation = kubectlAnnotationPrefix + "desired-replicas" originalReplicasAnnotation = kubectlAnnotationPrefix + "original-replicas" nextControllerAnnotation = kubectlAnnotationPrefix + "next-controller-id" @@ -135,7 +135,7 @@ type RollingUpdater struct { scaleAndWait func(rc *corev1.ReplicationController, retry *RetryParams, wait *RetryParams) (*corev1.ReplicationController, error) //getOrCreateTargetController gets and validates an existing controller or //makes a new one. - getOrCreateTargetController func(controller *corev1.ReplicationController, sourceId string) (*corev1.ReplicationController, bool, error) + getOrCreateTargetController func(controller *corev1.ReplicationController, sourceID string) (*corev1.ReplicationController, bool, error) // cleanup performs post deployment cleanup tasks for newRc and oldRc. cleanup func(oldRc, newRc *corev1.ReplicationController, config *RollingUpdaterConfig) error // getReadyPods returns the amount of old and new ready pods. @@ -188,8 +188,8 @@ func (r *RollingUpdater) Update(config *RollingUpdaterConfig) error { // Find an existing controller (for continuing an interrupted update) or // create a new one if necessary. - sourceId := fmt.Sprintf("%s:%s", oldRc.Name, oldRc.UID) - newRc, existed, err := r.getOrCreateTargetController(config.NewRc, sourceId) + sourceID := fmt.Sprintf("%s:%s", oldRc.Name, oldRc.UID) + newRc, existed, err := r.getOrCreateTargetController(config.NewRc, sourceID) if err != nil { return err } @@ -458,14 +458,14 @@ func (r *RollingUpdater) readyPods(oldRc, newRc *corev1.ReplicationController, m } // getOrCreateTargetControllerWithClient looks for an existing controller with -// sourceId. If found, the existing controller is returned with true +// sourceID. If found, the existing controller is returned with true // indicating that the controller already exists. If the controller isn't // found, a new one is created and returned along with false indicating the // controller was created. // -// Existing controllers are validated to ensure their sourceIdAnnotation -// matches sourceId; if there's a mismatch, an error is returned. -func (r *RollingUpdater) getOrCreateTargetControllerWithClient(controller *corev1.ReplicationController, sourceId string) (*corev1.ReplicationController, bool, error) { +// Existing controllers are validated to ensure their sourceIDAnnotation +// matches sourceID; if there's a mismatch, an error is returned. +func (r *RollingUpdater) getOrCreateTargetControllerWithClient(controller *corev1.ReplicationController, sourceID string) (*corev1.ReplicationController, bool, error) { existingRc, err := r.existingController(controller) if err != nil { if !errors.IsNotFound(err) { @@ -474,24 +474,24 @@ func (r *RollingUpdater) getOrCreateTargetControllerWithClient(controller *corev return nil, false, err } if valOrZero(controller.Spec.Replicas) <= 0 { - return nil, false, fmt.Errorf("Invalid controller spec for %s; required: > 0 replicas, actual: %d\n", controller.Name, valOrZero(controller.Spec.Replicas)) + return nil, false, fmt.Errorf("Invalid controller spec for %s; required: > 0 replicas, actual: %d", controller.Name, valOrZero(controller.Spec.Replicas)) } // The controller wasn't found, so create it. if controller.Annotations == nil { controller.Annotations = map[string]string{} } controller.Annotations[desiredReplicasAnnotation] = fmt.Sprintf("%d", valOrZero(controller.Spec.Replicas)) - controller.Annotations[sourceIdAnnotation] = sourceId + controller.Annotations[sourceIDAnnotation] = sourceID controller.Spec.Replicas = newInt32Ptr(0) newRc, err := r.rcClient.ReplicationControllers(r.ns).Create(controller) return newRc, false, err } // Validate and use the existing controller. annotations := existingRc.Annotations - source := annotations[sourceIdAnnotation] + source := annotations[sourceIDAnnotation] _, ok := annotations[desiredReplicasAnnotation] - if source != sourceId || !ok { - return nil, false, fmt.Errorf("Missing/unexpected annotations for controller %s, expected %s : %s", controller.Name, sourceId, annotations) + if source != sourceID || !ok { + return nil, false, fmt.Errorf("Missing/unexpected annotations for controller %s, expected %s : %s", controller.Name, sourceID, annotations) } return existingRc, true, nil } @@ -517,7 +517,7 @@ func (r *RollingUpdater) cleanupWithClients(oldRc, newRc *corev1.ReplicationCont return err } applyUpdate := func(rc *corev1.ReplicationController) { - delete(rc.Annotations, sourceIdAnnotation) + delete(rc.Annotations, sourceIDAnnotation) delete(rc.Annotations, desiredReplicasAnnotation) } if newRc, err = updateRcWithRetries(r.rcClient, r.ns, newRc, applyUpdate); err != nil { @@ -662,7 +662,7 @@ func AbortRollingUpdate(c *RollingUpdaterConfig) error { if c.NewRc.Annotations == nil { c.NewRc.Annotations = map[string]string{} } - c.NewRc.Annotations[sourceIdAnnotation] = fmt.Sprintf("%s:%s", c.OldRc.Name, c.OldRc.UID) + c.NewRc.Annotations[sourceIDAnnotation] = fmt.Sprintf("%s:%s", c.OldRc.Name, c.OldRc.UID) // Use the original value since the replica count change from old to new // could be asymmetric. If we don't know the original count, we can't safely @@ -841,7 +841,7 @@ func FindSourceController(r corev1client.ReplicationControllersGetter, namespace } for ix := range list.Items { rc := &list.Items[ix] - if rc.Annotations != nil && strings.HasPrefix(rc.Annotations[sourceIdAnnotation], name) { + if rc.Annotations != nil && strings.HasPrefix(rc.Annotations[sourceIDAnnotation], name) { return rc, nil } } diff --git a/pkg/kubectl/rolling_updater_test.go b/pkg/kubectl/rolling_updater_test.go index be61b20bd0..824f2ac82c 100644 --- a/pkg/kubectl/rolling_updater_test.go +++ b/pkg/kubectl/rolling_updater_test.go @@ -86,7 +86,7 @@ func newRc(replicas int, desired int) *corev1.ReplicationController { Name: "foo-v2", Annotations: map[string]string{ desiredReplicasAnnotation: fmt.Sprintf("%d", desired), - sourceIdAnnotation: "foo-v1:7764ae47-9092-11e4-8393-42010af018ff", + sourceIDAnnotation: "foo-v1:7764ae47-9092-11e4-8393-42010af018ff", }, } return rc @@ -812,7 +812,7 @@ Scaling foo-v2 up to 2 rc.Status.Replicas = *rc.Spec.Replicas return rc, nil }, - getOrCreateTargetController: func(controller *corev1.ReplicationController, sourceId string) (*corev1.ReplicationController, bool, error) { + getOrCreateTargetController: func(controller *corev1.ReplicationController, sourceID string) (*corev1.ReplicationController, bool, error) { // Simulate a create vs. update of an existing controller. return tt.newRc, tt.newRcExists, nil }, @@ -865,7 +865,7 @@ func TestUpdate_progressTimeout(t *testing.T) { // Do nothing. return rc, nil }, - getOrCreateTargetController: func(controller *corev1.ReplicationController, sourceId string) (*corev1.ReplicationController, bool, error) { + getOrCreateTargetController: func(controller *corev1.ReplicationController, sourceID string) (*corev1.ReplicationController, bool, error) { return newRc, false, nil }, cleanup: func(oldRc, newRc *corev1.ReplicationController, config *RollingUpdaterConfig) error { @@ -909,7 +909,7 @@ func TestUpdate_assignOriginalAnnotation(t *testing.T) { scaleAndWait: func(rc *corev1.ReplicationController, retry *RetryParams, wait *RetryParams) (*corev1.ReplicationController, error) { return rc, nil }, - getOrCreateTargetController: func(controller *corev1.ReplicationController, sourceId string) (*corev1.ReplicationController, bool, error) { + getOrCreateTargetController: func(controller *corev1.ReplicationController, sourceID string) (*corev1.ReplicationController, bool, error) { return newRc, false, nil }, cleanup: func(oldRc, newRc *corev1.ReplicationController, config *RollingUpdaterConfig) error { @@ -1244,7 +1244,7 @@ func TestFindSourceController(t *testing.T) { Namespace: metav1.NamespaceDefault, Name: "foo", Annotations: map[string]string{ - sourceIdAnnotation: "bar:1234", + sourceIDAnnotation: "bar:1234", }, }, } @@ -1253,7 +1253,7 @@ func TestFindSourceController(t *testing.T) { Namespace: metav1.NamespaceDefault, Name: "bar", Annotations: map[string]string{ - sourceIdAnnotation: "foo:12345", + sourceIDAnnotation: "foo:12345", }, }, } @@ -1262,7 +1262,7 @@ func TestFindSourceController(t *testing.T) { Namespace: metav1.NamespaceDefault, Name: "baz", Annotations: map[string]string{ - sourceIdAnnotation: "baz:45667", + sourceIDAnnotation: "baz:45667", }, }, } diff --git a/pkg/kubectl/scale.go b/pkg/kubectl/scale.go index f1d46b7a11..54f96fd2c3 100644 --- a/pkg/kubectl/scale.go +++ b/pkg/kubectl/scale.go @@ -175,7 +175,7 @@ func scaleHasDesiredReplicas(sClient scaleclient.ScalesGetter, gr schema.GroupRe // or returns error when timeout happens func WaitForScaleHasDesiredReplicas(sClient scaleclient.ScalesGetter, gr schema.GroupResource, resourceName string, namespace string, newSize uint, waitForReplicas *RetryParams) error { if waitForReplicas == nil { - return fmt.Errorf("waitForReplicas parameter cannot be nil!") + return fmt.Errorf("waitForReplicas parameter cannot be nil") } err := wait.PollImmediate( waitForReplicas.Interval, diff --git a/pkg/kubectl/sorter.go b/pkg/kubectl/sorter.go index b7c339dfb2..8d76add22d 100644 --- a/pkg/kubectl/sorter.go +++ b/pkg/kubectl/sorter.go @@ -37,7 +37,7 @@ import ( "vbom.ml/util/sortorder" ) -// Sorting printer sorts list types before delegating to another printer. +// SortingPrinter sorts list types before delegating to another printer. // Non-list types are simply passed through type SortingPrinter struct { SortField string @@ -296,7 +296,8 @@ func (r *RuntimeSort) Less(i, j int) bool { return less } -// Returns the starting (original) position of a particular index. e.g. If OriginalPosition(0) returns 5 than the +// OriginalPosition returns the starting (original) position of a particular index. +// e.g. If OriginalPosition(0) returns 5 than the // the item currently at position 0 was at position 5 in the original unsorted array. func (r *RuntimeSort) OriginalPosition(ix int) int { if ix < 0 || ix > len(r.origPosition) { diff --git a/pkg/kubectl/util/service_port.go b/pkg/kubectl/util/service_port.go index 18960b1486..bc56ab7d6a 100644 --- a/pkg/kubectl/util/service_port.go +++ b/pkg/kubectl/util/service_port.go @@ -23,8 +23,8 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) -// Lookup containerPort number from Service port number -// It implements the handling of resolving container named port, as well as ignoring targetPort when clusterIP=None +// LookupContainerPortNumberByServicePort implements +// the handling of resolving container named port, as well as ignoring targetPort when clusterIP=None // It returns an error when a named port can't find a match (with -1 returned), or when the service does not // declare such port (with the input port number returned). func LookupContainerPortNumberByServicePort(svc v1.Service, pod v1.Pod, port int32) (int32, error) { @@ -39,12 +39,10 @@ func LookupContainerPortNumberByServicePort(svc v1.Service, pod v1.Pod, port int if svcportspec.TargetPort.IntValue() == 0 { // targetPort is omitted, and the IntValue() would be zero return svcportspec.Port, nil - } else { - return int32(svcportspec.TargetPort.IntValue()), nil } - } else { - return LookupContainerPortNumberByName(pod, svcportspec.TargetPort.String()) + return int32(svcportspec.TargetPort.IntValue()), nil } + return LookupContainerPortNumberByName(pod, svcportspec.TargetPort.String()) } return port, fmt.Errorf("Service %s does not have a service port %d", svc.Name, port) } diff --git a/pkg/kubectl/util/slice/slice.go b/pkg/kubectl/util/slice/slice.go index 8130753c30..0eef7db1a3 100644 --- a/pkg/kubectl/util/slice/slice.go +++ b/pkg/kubectl/util/slice/slice.go @@ -20,5 +20,5 @@ import ( "sort" ) -// Sorts []int64 in increasing order +// SortInts64 sorts []int64 in increasing order func SortInts64(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) } diff --git a/pkg/kubectl/util/umask.go b/pkg/kubectl/util/umask.go index 93e14473c2..67add4e914 100644 --- a/pkg/kubectl/util/umask.go +++ b/pkg/kubectl/util/umask.go @@ -22,6 +22,7 @@ import ( "golang.org/x/sys/unix" ) +// Umask is a wrapper for `unix.Umask()` on non-Windows platforms func Umask(mask int) (old int, err error) { return unix.Umask(mask), nil } diff --git a/pkg/kubectl/util/umask_windows.go b/pkg/kubectl/util/umask_windows.go index 7a1ba15386..5b4f54bb79 100644 --- a/pkg/kubectl/util/umask_windows.go +++ b/pkg/kubectl/util/umask_windows.go @@ -22,6 +22,7 @@ import ( "errors" ) +// Umask returns an error on Windows func Umask(mask int) (int, error) { return 0, errors.New("platform and architecture is not supported") } diff --git a/pkg/kubectl/util/util.go b/pkg/kubectl/util/util.go index 41427780c7..0c1973dfb8 100644 --- a/pkg/kubectl/util/util.go +++ b/pkg/kubectl/util/util.go @@ -41,6 +41,7 @@ func ParseRFC3339(s string, nowFn func() metav1.Time) (metav1.Time, error) { return metav1.Time{Time: t}, nil } +// HashObject returns the hash of a Object hash by a Codec func HashObject(obj runtime.Object, codec runtime.Codec) (string, error) { data, err := runtime.Encode(codec, obj) if err != nil { @@ -63,11 +64,11 @@ func ParseFileSource(source string) (keyName, filePath string, err error) { case numSeparators == 0: return path.Base(filepath.ToSlash(source)), source, nil case numSeparators == 1 && strings.HasPrefix(source, "="): - return "", "", fmt.Errorf("key name for file path %v missing.", strings.TrimPrefix(source, "=")) + return "", "", fmt.Errorf("key name for file path %v missing", strings.TrimPrefix(source, "=")) case numSeparators == 1 && strings.HasSuffix(source, "="): - return "", "", fmt.Errorf("file path for key name %v missing.", strings.TrimSuffix(source, "=")) + return "", "", fmt.Errorf("file path for key name %v missing", strings.TrimSuffix(source, "=")) case numSeparators > 1: - return "", "", errors.New("Key names or file paths cannot contain '='.") + return "", "", errors.New("Key names or file paths cannot contain '='") default: components := strings.Split(source, "=") return components[0], components[1], nil