Remove untested and unused code

pull/6/head
Daniel Smith 2014-10-08 14:23:25 -07:00
parent a4a87d9916
commit 8007614085
4 changed files with 0 additions and 145 deletions

View File

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

View File

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

View File

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

View File

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