mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	Merge pull request #2527 from erictune/cleanup2
Remove unused return value. Make stuff private.
This commit is contained in:
		@@ -37,30 +37,29 @@ func EtcdKeyForHost(hostname string) string {
 | 
				
			|||||||
	return path.Join("/", "registry", "nodes", hostname, "boundpods")
 | 
						return path.Join("/", "registry", "nodes", hostname, "boundpods")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SourceEtcd struct {
 | 
					type sourceEtcd struct {
 | 
				
			||||||
	key     string
 | 
						key     string
 | 
				
			||||||
	helper  tools.EtcdHelper
 | 
						helper  tools.EtcdHelper
 | 
				
			||||||
	updates chan<- interface{}
 | 
						updates chan<- interface{}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewSourceEtcd creates a config source that watches and pulls from a key in etcd
 | 
					// 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{
 | 
						helper := tools.EtcdHelper{
 | 
				
			||||||
		client,
 | 
							client,
 | 
				
			||||||
		latest.Codec,
 | 
							latest.Codec,
 | 
				
			||||||
		tools.RuntimeVersionAdapter{latest.ResourceVersioner},
 | 
							tools.RuntimeVersionAdapter{latest.ResourceVersioner},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	source := &SourceEtcd{
 | 
						source := &sourceEtcd{
 | 
				
			||||||
		key:     key,
 | 
							key:     key,
 | 
				
			||||||
		helper:  helper,
 | 
							helper:  helper,
 | 
				
			||||||
		updates: updates,
 | 
							updates: updates,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	glog.V(1).Infof("Watching etcd for %s", key)
 | 
						glog.V(1).Infof("Watching etcd for %s", key)
 | 
				
			||||||
	go util.Forever(source.run, time.Second)
 | 
						go util.Forever(source.run, time.Second)
 | 
				
			||||||
	return source
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *SourceEtcd) run() {
 | 
					func (s *sourceEtcd) run() {
 | 
				
			||||||
	watching := s.helper.Watch(s.key, 0)
 | 
						watching := s.helper.Watch(s.key, 0)
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,28 +37,27 @@ import (
 | 
				
			|||||||
	"gopkg.in/v1/yaml"
 | 
						"gopkg.in/v1/yaml"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SourceFile struct {
 | 
					type sourceFile struct {
 | 
				
			||||||
	path    string
 | 
						path    string
 | 
				
			||||||
	updates chan<- interface{}
 | 
						updates chan<- interface{}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewSourceFile(path string, period time.Duration, updates chan<- interface{}) *SourceFile {
 | 
					func NewSourceFile(path string, period time.Duration, updates chan<- interface{}) {
 | 
				
			||||||
	config := &SourceFile{
 | 
						config := &sourceFile{
 | 
				
			||||||
		path:    path,
 | 
							path:    path,
 | 
				
			||||||
		updates: updates,
 | 
							updates: updates,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	glog.V(1).Infof("Watching path %q", path)
 | 
						glog.V(1).Infof("Watching path %q", path)
 | 
				
			||||||
	go util.Forever(config.run, period)
 | 
						go util.Forever(config.run, period)
 | 
				
			||||||
	return config
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *SourceFile) run() {
 | 
					func (s *sourceFile) run() {
 | 
				
			||||||
	if err := s.extractFromPath(); err != nil {
 | 
						if err := s.extractFromPath(); err != nil {
 | 
				
			||||||
		glog.Errorf("Unable to read config path %q: %v", s.path, err)
 | 
							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
 | 
						path := s.path
 | 
				
			||||||
	statInfo, err := os.Stat(path)
 | 
						statInfo, err := os.Stat(path)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -81,7 +81,7 @@ func ExampleManifestAndPod(id string) (api.ContainerManifest, api.BoundPod) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestExtractFromNonExistentFile(t *testing.T) {
 | 
					func TestExtractFromNonExistentFile(t *testing.T) {
 | 
				
			||||||
	ch := make(chan interface{}, 1)
 | 
						ch := make(chan interface{}, 1)
 | 
				
			||||||
	c := SourceFile{"/some/fake/file", ch}
 | 
						c := sourceFile{"/some/fake/file", ch}
 | 
				
			||||||
	err := c.extractFromPath()
 | 
						err := c.extractFromPath()
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		t.Errorf("Expected error")
 | 
							t.Errorf("Expected error")
 | 
				
			||||||
@@ -143,7 +143,7 @@ func TestExtractFromBadDataFile(t *testing.T) {
 | 
				
			|||||||
	defer os.Remove(file.Name())
 | 
						defer os.Remove(file.Name())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ch := make(chan interface{}, 1)
 | 
						ch := make(chan interface{}, 1)
 | 
				
			||||||
	c := SourceFile{file.Name(), ch}
 | 
						c := sourceFile{file.Name(), ch}
 | 
				
			||||||
	err := c.extractFromPath()
 | 
						err := c.extractFromPath()
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		t.Fatalf("Expected error")
 | 
							t.Fatalf("Expected error")
 | 
				
			||||||
@@ -164,7 +164,7 @@ func TestExtractFromValidDataFile(t *testing.T) {
 | 
				
			|||||||
	expectedPod.Name = simpleSubdomainSafeHash(file.Name())
 | 
						expectedPod.Name = simpleSubdomainSafeHash(file.Name())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ch := make(chan interface{}, 1)
 | 
						ch := make(chan interface{}, 1)
 | 
				
			||||||
	c := SourceFile{file.Name(), ch}
 | 
						c := sourceFile{file.Name(), ch}
 | 
				
			||||||
	err = c.extractFromPath()
 | 
						err = c.extractFromPath()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("Unexpected error: %v", err)
 | 
							t.Fatalf("Unexpected error: %v", err)
 | 
				
			||||||
@@ -184,7 +184,7 @@ func TestExtractFromEmptyDir(t *testing.T) {
 | 
				
			|||||||
	defer os.RemoveAll(dirName)
 | 
						defer os.RemoveAll(dirName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ch := make(chan interface{}, 1)
 | 
						ch := make(chan interface{}, 1)
 | 
				
			||||||
	c := SourceFile{dirName, ch}
 | 
						c := sourceFile{dirName, ch}
 | 
				
			||||||
	err = c.extractFromPath()
 | 
						err = c.extractFromPath()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("Unexpected error: %v", err)
 | 
							t.Fatalf("Unexpected error: %v", err)
 | 
				
			||||||
@@ -232,7 +232,7 @@ func TestExtractFromDir(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ch := make(chan interface{}, 1)
 | 
						ch := make(chan interface{}, 1)
 | 
				
			||||||
	c := SourceFile{dirName, ch}
 | 
						c := sourceFile{dirName, ch}
 | 
				
			||||||
	err = c.extractFromPath()
 | 
						err = c.extractFromPath()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("Unexpected error: %v", err)
 | 
							t.Fatalf("Unexpected error: %v", err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,30 +33,29 @@ import (
 | 
				
			|||||||
	"gopkg.in/v1/yaml"
 | 
						"gopkg.in/v1/yaml"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SourceURL struct {
 | 
					type sourceURL struct {
 | 
				
			||||||
	url     string
 | 
						url     string
 | 
				
			||||||
	updates chan<- interface{}
 | 
						updates chan<- interface{}
 | 
				
			||||||
	data    []byte
 | 
						data    []byte
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewSourceURL(url string, period time.Duration, updates chan<- interface{}) *SourceURL {
 | 
					func NewSourceURL(url string, period time.Duration, updates chan<- interface{}) {
 | 
				
			||||||
	config := &SourceURL{
 | 
						config := &sourceURL{
 | 
				
			||||||
		url:     url,
 | 
							url:     url,
 | 
				
			||||||
		updates: updates,
 | 
							updates: updates,
 | 
				
			||||||
		data:    nil,
 | 
							data:    nil,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	glog.V(1).Infof("Watching URL %s", url)
 | 
						glog.V(1).Infof("Watching URL %s", url)
 | 
				
			||||||
	go util.Forever(config.run, period)
 | 
						go util.Forever(config.run, period)
 | 
				
			||||||
	return config
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *SourceURL) run() {
 | 
					func (s *sourceURL) run() {
 | 
				
			||||||
	if err := s.extractFromURL(); err != nil {
 | 
						if err := s.extractFromURL(); err != nil {
 | 
				
			||||||
		glog.Errorf("Failed to read URL: %v", err)
 | 
							glog.Errorf("Failed to read URL: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *SourceURL) extractFromURL() error {
 | 
					func (s *sourceURL) extractFromURL() error {
 | 
				
			||||||
	resp, err := http.Get(s.url)
 | 
						resp, err := http.Get(s.url)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,7 +41,7 @@ func TestURLErrorNotExistNoUpdate(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestExtractFromHttpBadness(t *testing.T) {
 | 
					func TestExtractFromHttpBadness(t *testing.T) {
 | 
				
			||||||
	ch := make(chan interface{}, 1)
 | 
						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 {
 | 
						if err := c.extractFromURL(); err == nil {
 | 
				
			||||||
		t.Errorf("Expected error")
 | 
							t.Errorf("Expected error")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -107,7 +107,7 @@ func TestExtractInvalidManifest(t *testing.T) {
 | 
				
			|||||||
		testServer := httptest.NewServer(&fakeHandler)
 | 
							testServer := httptest.NewServer(&fakeHandler)
 | 
				
			||||||
		defer testServer.Close()
 | 
							defer testServer.Close()
 | 
				
			||||||
		ch := make(chan interface{}, 1)
 | 
							ch := make(chan interface{}, 1)
 | 
				
			||||||
		c := SourceURL{testServer.URL, ch, nil}
 | 
							c := sourceURL{testServer.URL, ch, nil}
 | 
				
			||||||
		if err := c.extractFromURL(); err == nil {
 | 
							if err := c.extractFromURL(); err == nil {
 | 
				
			||||||
			t.Errorf("%s: Expected error", testCase.desc)
 | 
								t.Errorf("%s: Expected error", testCase.desc)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -184,7 +184,7 @@ func TestExtractFromHTTP(t *testing.T) {
 | 
				
			|||||||
		testServer := httptest.NewServer(&fakeHandler)
 | 
							testServer := httptest.NewServer(&fakeHandler)
 | 
				
			||||||
		defer testServer.Close()
 | 
							defer testServer.Close()
 | 
				
			||||||
		ch := make(chan interface{}, 1)
 | 
							ch := make(chan interface{}, 1)
 | 
				
			||||||
		c := SourceURL{testServer.URL, ch, nil}
 | 
							c := sourceURL{testServer.URL, ch, nil}
 | 
				
			||||||
		if err := c.extractFromURL(); err != nil {
 | 
							if err := c.extractFromURL(); err != nil {
 | 
				
			||||||
			t.Errorf("%s: Unexpected error: %v", testCase.desc, err)
 | 
								t.Errorf("%s: Unexpected error: %v", testCase.desc, err)
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user