From 7d3e00c6790caa31cfc13c59b5ffd1d9f5817454 Mon Sep 17 00:00:00 2001 From: Eric Tune Date: Fri, 21 Nov 2014 13:47:21 -0800 Subject: [PATCH] Remove never-needed return value. Make some types private. --- pkg/kubelet/config/etcd.go | 9 ++++----- pkg/kubelet/config/file.go | 11 +++++------ pkg/kubelet/config/file_test.go | 10 +++++----- pkg/kubelet/config/http.go | 11 +++++------ pkg/kubelet/config/http_test.go | 6 +++--- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/pkg/kubelet/config/etcd.go b/pkg/kubelet/config/etcd.go index 0ba08f70372..f9bc23cf668 100644 --- a/pkg/kubelet/config/etcd.go +++ b/pkg/kubelet/config/etcd.go @@ -37,30 +37,29 @@ func EtcdKeyForHost(hostname string) string { return path.Join("/", "registry", "nodes", hostname, "boundpods") } -type SourceEtcd struct { +type sourceEtcd struct { key string helper tools.EtcdHelper updates chan<- interface{} } // NewSourceEtcd creates a config source that watches and pulls from a key in etcd -func NewSourceEtcd(key string, client tools.EtcdClient, updates chan<- interface{}) *SourceEtcd { +func NewSourceEtcd(key string, client tools.EtcdClient, updates chan<- interface{}) { helper := tools.EtcdHelper{ client, latest.Codec, tools.RuntimeVersionAdapter{latest.ResourceVersioner}, } - source := &SourceEtcd{ + source := &sourceEtcd{ key: key, helper: helper, updates: updates, } glog.V(1).Infof("Watching etcd for %s", key) go util.Forever(source.run, time.Second) - return source } -func (s *SourceEtcd) run() { +func (s *sourceEtcd) run() { watching := s.helper.Watch(s.key, 0) for { select { diff --git a/pkg/kubelet/config/file.go b/pkg/kubelet/config/file.go index 89871095620..7728716b898 100644 --- a/pkg/kubelet/config/file.go +++ b/pkg/kubelet/config/file.go @@ -37,28 +37,27 @@ import ( "gopkg.in/v1/yaml" ) -type SourceFile struct { +type sourceFile struct { path string updates chan<- interface{} } -func NewSourceFile(path string, period time.Duration, updates chan<- interface{}) *SourceFile { - config := &SourceFile{ +func NewSourceFile(path string, period time.Duration, updates chan<- interface{}) { + config := &sourceFile{ path: path, updates: updates, } glog.V(1).Infof("Watching path %q", path) go util.Forever(config.run, period) - return config } -func (s *SourceFile) run() { +func (s *sourceFile) run() { if err := s.extractFromPath(); err != nil { glog.Errorf("Unable to read config path %q: %v", s.path, err) } } -func (s *SourceFile) extractFromPath() error { +func (s *sourceFile) extractFromPath() error { path := s.path statInfo, err := os.Stat(path) if err != nil { diff --git a/pkg/kubelet/config/file_test.go b/pkg/kubelet/config/file_test.go index bf6d6584955..91e6ab9c380 100644 --- a/pkg/kubelet/config/file_test.go +++ b/pkg/kubelet/config/file_test.go @@ -81,7 +81,7 @@ func ExampleManifestAndPod(id string) (api.ContainerManifest, api.BoundPod) { func TestExtractFromNonExistentFile(t *testing.T) { ch := make(chan interface{}, 1) - c := SourceFile{"/some/fake/file", ch} + c := sourceFile{"/some/fake/file", ch} err := c.extractFromPath() if err == nil { t.Errorf("Expected error") @@ -143,7 +143,7 @@ func TestExtractFromBadDataFile(t *testing.T) { defer os.Remove(file.Name()) ch := make(chan interface{}, 1) - c := SourceFile{file.Name(), ch} + c := sourceFile{file.Name(), ch} err := c.extractFromPath() if err == nil { t.Fatalf("Expected error") @@ -164,7 +164,7 @@ func TestExtractFromValidDataFile(t *testing.T) { expectedPod.Name = simpleSubdomainSafeHash(file.Name()) ch := make(chan interface{}, 1) - c := SourceFile{file.Name(), ch} + c := sourceFile{file.Name(), ch} err = c.extractFromPath() if err != nil { t.Fatalf("Unexpected error: %v", err) @@ -184,7 +184,7 @@ func TestExtractFromEmptyDir(t *testing.T) { defer os.RemoveAll(dirName) ch := make(chan interface{}, 1) - c := SourceFile{dirName, ch} + c := sourceFile{dirName, ch} err = c.extractFromPath() if err != nil { t.Fatalf("Unexpected error: %v", err) @@ -232,7 +232,7 @@ func TestExtractFromDir(t *testing.T) { } ch := make(chan interface{}, 1) - c := SourceFile{dirName, ch} + c := sourceFile{dirName, ch} err = c.extractFromPath() if err != nil { t.Fatalf("Unexpected error: %v", err) diff --git a/pkg/kubelet/config/http.go b/pkg/kubelet/config/http.go index 048f181c793..39dc9a46c2e 100644 --- a/pkg/kubelet/config/http.go +++ b/pkg/kubelet/config/http.go @@ -33,30 +33,29 @@ import ( "gopkg.in/v1/yaml" ) -type SourceURL struct { +type sourceURL struct { url string updates chan<- interface{} data []byte } -func NewSourceURL(url string, period time.Duration, updates chan<- interface{}) *SourceURL { - config := &SourceURL{ +func NewSourceURL(url string, period time.Duration, updates chan<- interface{}) { + config := &sourceURL{ url: url, updates: updates, data: nil, } glog.V(1).Infof("Watching URL %s", url) go util.Forever(config.run, period) - return config } -func (s *SourceURL) run() { +func (s *sourceURL) run() { if err := s.extractFromURL(); err != nil { glog.Errorf("Failed to read URL: %v", err) } } -func (s *SourceURL) extractFromURL() error { +func (s *sourceURL) extractFromURL() error { resp, err := http.Get(s.url) if err != nil { return err diff --git a/pkg/kubelet/config/http_test.go b/pkg/kubelet/config/http_test.go index 525d2020af9..c03e950e512 100644 --- a/pkg/kubelet/config/http_test.go +++ b/pkg/kubelet/config/http_test.go @@ -41,7 +41,7 @@ func TestURLErrorNotExistNoUpdate(t *testing.T) { func TestExtractFromHttpBadness(t *testing.T) { ch := make(chan interface{}, 1) - c := SourceURL{"http://localhost:49575/_not_found_", ch, nil} + c := sourceURL{"http://localhost:49575/_not_found_", ch, nil} if err := c.extractFromURL(); err == nil { t.Errorf("Expected error") } @@ -107,7 +107,7 @@ func TestExtractInvalidManifest(t *testing.T) { testServer := httptest.NewServer(&fakeHandler) defer testServer.Close() ch := make(chan interface{}, 1) - c := SourceURL{testServer.URL, ch, nil} + c := sourceURL{testServer.URL, ch, nil} if err := c.extractFromURL(); err == nil { t.Errorf("%s: Expected error", testCase.desc) } @@ -184,7 +184,7 @@ func TestExtractFromHTTP(t *testing.T) { testServer := httptest.NewServer(&fakeHandler) defer testServer.Close() ch := make(chan interface{}, 1) - c := SourceURL{testServer.URL, ch, nil} + c := sourceURL{testServer.URL, ch, nil} if err := c.extractFromURL(); err != nil { t.Errorf("%s: Unexpected error: %v", testCase.desc, err) continue