Skip to content

Commit

Permalink
Merge pull request kubernetes#75303 from obitech/fix_golint_failures_…
Browse files Browse the repository at this point in the history
…pkg_kubelet

Fix golint failures in some pkg/kubelet packages
  • Loading branch information
k8s-ci-robot authored Aug 5, 2019
2 parents 74c0cc2 + 17d2ba0 commit cea34cc
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 31 deletions.
1 change: 0 additions & 1 deletion hack/.golint_failures
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pkg/kubelet/dockershim/network/kubenet
pkg/kubelet/dockershim/network/testing
pkg/kubelet/events
pkg/kubelet/lifecycle
pkg/kubelet/metrics
pkg/kubelet/pluginmanager/pluginwatcher
pkg/kubelet/pod/testing
pkg/kubelet/preemption
Expand Down
1 change: 0 additions & 1 deletion pkg/kubelet/config/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Reads the pod configuration from the Kubernetes apiserver.
package config

import (
Expand Down
3 changes: 2 additions & 1 deletion pkg/kubelet/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Common logic used by both http and file channels.
package config

import (
Expand All @@ -30,6 +29,7 @@ import (
utilyaml "k8s.io/apimachinery/pkg/util/yaml"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/core/helper"

// TODO: remove this import if
// api.Registry.GroupOrDie(v1.GroupName).GroupVersion.String() is changed
// to "v1"?
Expand Down Expand Up @@ -110,6 +110,7 @@ func getSelfLink(name, namespace string) string {

type defaultFunc func(pod *api.Pod) error

// tryDecodeSinglePod takes data and tries to extract valid Pod config information from it.
func tryDecodeSinglePod(data []byte, defaultFn defaultFunc) (parsed bool, pod *v1.Pod, err error) {
// JSON is valid YAML, so this should work for everything.
json, err := utilyaml.ToJSON(data)
Expand Down
1 change: 1 addition & 0 deletions pkg/kubelet/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

package config

// Defines sane defaults for the kubelet config.
const (
DefaultKubeletPodsDirName = "pods"
DefaultKubeletVolumesDirName = "volumes"
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubelet/config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Reads the pod configuration from file or a directory of files.
package config

import (
Expand Down Expand Up @@ -60,6 +59,7 @@ type sourceFile struct {
watchEvents chan *watchEvent
}

// NewSourceFile watches a config file for changes.
func NewSourceFile(path string, nodeName types.NodeName, period time.Duration, updates chan<- interface{}) {
// "github.com/sigma/go-inotify" requires a path without trailing "/"
path = strings.TrimRight(path, string(os.PathSeparator))
Expand Down Expand Up @@ -196,6 +196,7 @@ func (s *sourceFile) extractFromDir(name string) ([]*v1.Pod, error) {
return pods, nil
}

// extractFromFile parses a file for Pod configuration information.
func (s *sourceFile) extractFromFile(filename string) (pod *v1.Pod, err error) {
klog.V(3).Infof("Reading config file %q", filename)
defer func() {
Expand Down Expand Up @@ -232,7 +233,7 @@ func (s *sourceFile) extractFromFile(filename string) (pod *v1.Pod, err error) {
return pod, nil
}

return pod, fmt.Errorf("%v: couldn't parse as pod(%v), please check config file.\n", filename, podErr)
return pod, fmt.Errorf("%v: couldn't parse as pod(%v), please check config file", filename, podErr)
}

func (s *sourceFile) replaceStore(pods ...*v1.Pod) (err error) {
Expand Down
16 changes: 7 additions & 9 deletions pkg/kubelet/config/file_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Reads the pod configuration from file or a directory of files.
package config

import (
Expand Down Expand Up @@ -50,17 +49,17 @@ func (e *retryableError) Error() string {

func (s *sourceFile) startWatch() {
backOff := flowcontrol.NewBackOff(retryPeriod, maxRetryPeriod)
backOffId := "watch"
backOffID := "watch"

go wait.Forever(func() {
if backOff.IsInBackOffSinceUpdate(backOffId, time.Now()) {
if backOff.IsInBackOffSinceUpdate(backOffID, time.Now()) {
return
}

if err := s.doWatch(); err != nil {
klog.Errorf("Unable to read config path %q: %v", s.path, err)
if _, retryable := err.(*retryableError); !retryable {
backOff.Next(backOffId, time.Now())
backOff.Next(backOffID, time.Now())
}
}
}, retryPeriod)
Expand Down Expand Up @@ -130,11 +129,11 @@ func (s *sourceFile) produceWatchEvent(e *fsnotify.Event) error {
func (s *sourceFile) consumeWatchEvent(e *watchEvent) error {
switch e.eventType {
case podAdd, podModify:
if pod, err := s.extractFromFile(e.fileName); err != nil {
pod, err := s.extractFromFile(e.fileName)
if err != nil {
return fmt.Errorf("can't process config file %q: %v", e.fileName, err)
} else {
return s.store.Add(pod)
}
return s.store.Add(pod)
case podDelete:
if objKey, keyExist := s.fileKeyMapping[e.fileName]; keyExist {
pod, podExist, err := s.store.GetByKey(objKey)
Expand All @@ -145,9 +144,8 @@ func (s *sourceFile) consumeWatchEvent(e *watchEvent) error {
} else {
if err = s.store.Delete(pod); err != nil {
return fmt.Errorf("failed to remove deleted pod from cache: %v", err)
} else {
delete(s.fileKeyMapping, e.fileName)
}
delete(s.fileKeyMapping, e.fileName)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion pkg/kubelet/config/file_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Reads the pod configuration from file or a directory of files.
package config

import (
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubelet/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ContainerRuntimeOptions defines options for the container runtime.
type ContainerRuntimeOptions struct {

// General options.
// General Options.

// ContainerRuntime is the container runtime to use.
ContainerRuntime string
Expand Down Expand Up @@ -78,6 +78,7 @@ type ContainerRuntimeOptions struct {
CNICacheDir string
}

// AddFlags adds flags to the container runtime, according to ContainerRuntimeOptions.
func (s *ContainerRuntimeOptions) AddFlags(fs *pflag.FlagSet) {
dockerOnlyWarning := "This docker-specific flag only works when container-runtime is set to docker."

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/config/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Reads the pod configuration from an HTTP GET response.
package config

import (
Expand Down Expand Up @@ -43,6 +42,7 @@ type sourceURL struct {
client *http.Client
}

// NewSourceURL specifies the URL where to read the Pod configuration from, then watches it for changes.
func NewSourceURL(url string, header http.Header, nodeName types.NodeName, period time.Duration, updates chan<- interface{}) {
config := &sourceURL{
url: url,
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/configmap/configmap_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"time"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
clientset "k8s.io/client-go/kubernetes"
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
corev1 "k8s.io/kubernetes/pkg/apis/core/v1"
Expand Down
4 changes: 1 addition & 3 deletions pkg/kubelet/configmap/fake_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ limitations under the License.

package configmap

import (
"k8s.io/api/core/v1"
)
import v1 "k8s.io/api/core/v1"

// fakeManager implements Manager interface for testing purposes.
// simple operations to apiserver.
Expand Down
Loading

0 comments on commit cea34cc

Please sign in to comment.