From 80076140854a8f52257b684214779cd5af8eae32 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Wed, 8 Oct 2014 14:23:25 -0700 Subject: [PATCH] Remove untested and unused code --- cmd/proxy/proxy.go | 7 -- docs/man/kube-proxy.1.md | 3 - docs/man/man1/kube-proxy.1 | 4 -- pkg/proxy/config/file.go | 131 ------------------------------------- 4 files changed, 145 deletions(-) delete mode 100644 pkg/proxy/config/file.go diff --git a/cmd/proxy/proxy.go b/cmd/proxy/proxy.go index 166d4388ce..4945cf5c08 100644 --- a/cmd/proxy/proxy.go +++ b/cmd/proxy/proxy.go @@ -31,7 +31,6 @@ import ( ) var ( - configFile = flag.String("configfile", "/tmp/proxy_config", "Configuration file for the proxy") etcdServerList util.StringList etcdConfigFile = flag.String("etcd_config", "", "The config file for the etcd client. Mutually exclusive with -etcd_servers") bindAddress = util.IP(net.ParseIP("0.0.0.0")) @@ -97,12 +96,6 @@ func main() { } } - // And create a configuration source that reads from a local file - config.NewConfigSourceFile(*configFile, - serviceConfig.Channel("file"), - endpointsConfig.Channel("file")) - glog.Infof("Using configuration file %s", *configFile) - loadBalancer := proxy.NewLoadBalancerRR() proxier := proxy.NewProxier(loadBalancer, net.IP(bindAddress)) // Wire proxier to handle changes to services diff --git a/docs/man/kube-proxy.1.md b/docs/man/kube-proxy.1.md index 84d97d6052..55a0b2f4d1 100644 --- a/docs/man/kube-proxy.1.md +++ b/docs/man/kube-proxy.1.md @@ -23,9 +23,6 @@ The kube-proxy takes several options. **-bindaddress**="0.0.0.0" The address for the proxy server to serve on (set to 0.0.0.0 or "" for all interfaces) -**-configfile**="/tmp/proxy_config" - Configuration file for the proxy - **-etcd_servers**=[] List of etcd servers to watch (http://ip:port), comma separated (optional) diff --git a/docs/man/man1/kube-proxy.1 b/docs/man/man1/kube-proxy.1 index 8d876db6e2..422b473210 100644 --- a/docs/man/man1/kube-proxy.1 +++ b/docs/man/man1/kube-proxy.1 @@ -28,10 +28,6 @@ The kube\-proxy takes several options. \fB\-bindaddress\fP="0.0.0.0" The address for the proxy server to serve on (set to 0.0.0.0 or "" for all interfaces) -.PP -\fB\-configfile\fP="/tmp/proxy\_config" - Configuration file for the proxy - .PP \fB\-etcd\_servers\fP=[] List of etcd servers to watch ( diff --git a/pkg/proxy/config/file.go b/pkg/proxy/config/file.go deleted file mode 100644 index 259bc3b46e..0000000000 --- a/pkg/proxy/config/file.go +++ /dev/null @@ -1,131 +0,0 @@ -/* -Copyright 2014 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Reads the configuration from the file. Example file for two services [nodejs & mysql] -//{"Services": [ -// { -// "Name":"nodejs", -// "Port":10000, -// "Endpoints":["10.240.180.168:8000", "10.240.254.199:8000", "10.240.62.150:8000"] -// }, -// { -// "Name":"mysql", -// "Port":10001, -// "Endpoints":["10.240.180.168:9000", "10.240.254.199:9000", "10.240.62.150:9000"] -// } -//] -//} - -package config - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "reflect" - "time" - - "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/golang/glog" -) - -// serviceConfig is a deserialized form of the config file format which ConfigSourceFile accepts. -// TODO: this is apparently untested; is it used? -type serviceConfig struct { - Services []struct { - Name string `json: "name"` - Port int `json: "port"` - Endpoints []string `json: "endpoints"` - } `json:"service"` -} - -// ConfigSourceFile periodically reads service configurations in JSON from a file, and sends the services and endpoints defined in the file to the specified channels. -type ConfigSourceFile struct { - serviceChannel chan ServiceUpdate - endpointsChannel chan EndpointsUpdate - filename string -} - -// NewConfigSourceFile creates a new ConfigSourceFile and let it immediately runs the created ConfigSourceFile in a goroutine. -func NewConfigSourceFile(filename string, serviceChannel chan ServiceUpdate, endpointsChannel chan EndpointsUpdate) ConfigSourceFile { - config := ConfigSourceFile{ - filename: filename, - serviceChannel: serviceChannel, - endpointsChannel: endpointsChannel, - } - go config.Run() - return config -} - -// Run begins watching the config file. -func (s ConfigSourceFile) Run() { - glog.V(1).Infof("Watching file %s", s.filename) - var lastData []byte - var lastServices []api.Service - var lastEndpoints []api.Endpoints - - sleep := 5 * time.Second - // Used to avoid spamming the error log file, makes error logging edge triggered. - hadSuccess := true - for { - data, err := ioutil.ReadFile(s.filename) - if err != nil { - msg := fmt.Sprintf("Couldn't read file: %s : %v", s.filename, err) - if hadSuccess { - glog.Error(msg) - } else { - glog.V(1).Info(msg) - } - hadSuccess = false - time.Sleep(sleep) - continue - } - hadSuccess = true - - if bytes.Equal(lastData, data) { - time.Sleep(sleep) - continue - } - lastData = data - - config := &serviceConfig{} - if err = json.Unmarshal(data, config); err != nil { - glog.Errorf("Couldn't unmarshal configuration from file : %s %v", data, err) - continue - } - // Ok, we have a valid configuration, send to channel for - // rejiggering. - newServices := make([]api.Service, len(config.Services)) - newEndpoints := make([]api.Endpoints, len(config.Services)) - for i, service := range config.Services { - newServices[i] = api.Service{TypeMeta: api.TypeMeta{ID: service.Name}, Port: service.Port} - newEndpoints[i] = api.Endpoints{TypeMeta: api.TypeMeta{ID: service.Name}, Endpoints: service.Endpoints} - } - if !reflect.DeepEqual(lastServices, newServices) { - serviceUpdate := ServiceUpdate{Op: SET, Services: newServices} - s.serviceChannel <- serviceUpdate - lastServices = newServices - } - if !reflect.DeepEqual(lastEndpoints, newEndpoints) { - endpointsUpdate := EndpointsUpdate{Op: SET, Endpoints: newEndpoints} - s.endpointsChannel <- endpointsUpdate - lastEndpoints = newEndpoints - } - - time.Sleep(sleep) - } -}