Merge pull request #2527 from erictune/cleanup2

Remove unused return value.  Make stuff private.
This commit is contained in:
Dawn Chen 2014-11-21 17:16:50 -08:00
commit 162e4983b9
5 changed files with 22 additions and 25 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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)

View File

@ -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

View File

@ -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