From a7623ca6cc9e4a0566f182b1dfe2a4ae5bd1d548 Mon Sep 17 00:00:00 2001 From: Karl Beecher Date: Wed, 11 Mar 2015 18:10:09 +0100 Subject: [PATCH] Adds ability to define a prefix for etcd paths The API server can be supplied (via a command line flag) with a custom prefix that is prepended to etcd resources paths. Refs: #3476 --- cmd/integration/integration.go | 3 +- cmd/kube-apiserver/app/server.go | 9 +- cmd/kubernetes/kubernetes.go | 2 +- hack/test-go.sh | 8 +- pkg/api/rest/resttest/resttest.go | 1 - pkg/master/master.go | 10 +- pkg/master/master_test.go | 3 +- pkg/registry/controller/etcd/etcd.go | 2 +- pkg/registry/controller/etcd/etcd_test.go | 34 +++++- pkg/registry/endpoint/etcd/etcd.go | 2 +- pkg/registry/endpoint/etcd/etcd_test.go | 10 +- pkg/registry/etcd/etcd.go | 4 +- pkg/registry/etcd/etcd_test.go | 74 ++++++++---- pkg/registry/event/registry.go | 5 +- pkg/registry/event/registry_test.go | 10 +- pkg/registry/generic/etcd/etcd_test.go | 30 ++--- pkg/registry/limitrange/registry.go | 5 +- pkg/registry/limitrange/registry_test.go | 7 +- pkg/registry/minion/etcd/etcd.go | 2 +- pkg/registry/minion/etcd/etcd_test.go | 12 +- pkg/registry/namespace/etcd/etcd.go | 6 +- pkg/registry/namespace/etcd/etcd_test.go | 45 +++++--- pkg/registry/persistentvolume/etcd/etcd.go | 6 +- .../persistentvolume/etcd/etcd_test.go | 12 +- .../persistentvolumeclaim/etcd/etcd.go | 2 +- .../persistentvolumeclaim/etcd/etcd_test.go | 12 +- pkg/registry/pod/etcd/etcd.go | 2 +- pkg/registry/pod/etcd/etcd_test.go | 94 +++++++++++---- pkg/registry/podtemplate/etcd/etcd.go | 2 +- pkg/registry/podtemplate/etcd/etcd_test.go | 6 +- pkg/registry/resourcequota/etcd/etcd.go | 2 +- pkg/registry/resourcequota/etcd/etcd_test.go | 54 ++++++--- pkg/registry/secret/registry.go | 5 +- pkg/registry/secret/registry_test.go | 8 +- pkg/tools/etcd_helper.go | 31 ++++- pkg/tools/etcd_helper_test.go | 107 ++++++++++++------ pkg/tools/etcd_helper_watch.go | 3 + pkg/tools/etcd_helper_watch_test.go | 73 +++++++----- pkg/tools/etcdtest/doc.go | 17 +++ pkg/tools/etcdtest/etcdtest.go | 32 ++++++ test/integration/auth_test.go | 24 ++-- test/integration/etcd_tools_test.go | 4 +- test/integration/scheduler_test.go | 3 +- test/integration/secret_test.go | 3 +- test/integration/utils.go | 3 +- 45 files changed, 562 insertions(+), 227 deletions(-) create mode 100644 pkg/tools/etcdtest/doc.go create mode 100644 pkg/tools/etcdtest/etcdtest.go diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index 27c5b6c0c68..c36cd60af91 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -51,6 +51,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/master" "github.com/GoogleCloudPlatform/kubernetes/pkg/probe" "github.com/GoogleCloudPlatform/kubernetes/pkg/service" + "github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume/empty_dir" @@ -160,7 +161,7 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st cl := client.NewOrDie(&client.Config{Host: apiServer.URL, Version: apiVersion}) - helper, err := master.NewEtcdHelper(etcdClient, "") + helper, err := master.NewEtcdHelper(etcdClient, "", etcdtest.PathPrefix()) if err != nil { glog.Fatalf("Unable to get etcd helper: %v", err) } diff --git a/cmd/kube-apiserver/app/server.go b/cmd/kube-apiserver/app/server.go index afdd53fe1cf..7565987097f 100644 --- a/cmd/kube-apiserver/app/server.go +++ b/cmd/kube-apiserver/app/server.go @@ -71,6 +71,7 @@ type APIServer struct { AdmissionControlConfigFile string EtcdServerList util.StringList EtcdConfigFile string + EtcdPathPrefix string CorsAllowedOriginList util.StringList AllowPrivileged bool PortalNet util.IPNet // TODO: make this a list @@ -98,6 +99,7 @@ func NewAPIServer() *APIServer { EventTTL: 1 * time.Hour, AuthorizationMode: "AlwaysAllow", AdmissionControl: "AlwaysAdmit", + EtcdPathPrefix: master.DefaultEtcdPathPrefix, EnableLogsSupport: true, MasterServiceNamespace: api.NamespaceDefault, ClusterName: "kubernetes", @@ -161,6 +163,7 @@ func (s *APIServer) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&s.AdmissionControlConfigFile, "admission_control_config_file", s.AdmissionControlConfigFile, "File with admission control configuration.") fs.Var(&s.EtcdServerList, "etcd_servers", "List of etcd servers to watch (http://ip:port), comma separated. Mutually exclusive with -etcd_config") fs.StringVar(&s.EtcdConfigFile, "etcd_config", s.EtcdConfigFile, "The config file for the etcd client. Mutually exclusive with -etcd_servers.") + fs.StringVar(&s.EtcdPathPrefix, "etcd_prefix", s.EtcdPathPrefix, "The prefix for all resource paths in etcd.") fs.Var(&s.CorsAllowedOriginList, "cors_allowed_origins", "List of allowed origins for CORS, comma separated. An allowed origin can be a regular expression to support subdomain matching. If this list is empty CORS will not be enabled.") fs.BoolVar(&s.AllowPrivileged, "allow_privileged", s.AllowPrivileged, "If true, allow privileged containers.") fs.Var(&s.PortalNet, "portal_net", "A CIDR notation IP range from which to assign portal IPs. This must not overlap with any IP ranges assigned to nodes for pods.") @@ -181,7 +184,7 @@ func (s *APIServer) verifyPortalFlags() { } } -func newEtcd(etcdConfigFile string, etcdServerList util.StringList, storageVersion string) (helper tools.EtcdHelper, err error) { +func newEtcd(etcdConfigFile string, etcdServerList util.StringList, storageVersion string, pathPrefix string) (helper tools.EtcdHelper, err error) { var client tools.EtcdGetSet if etcdConfigFile != "" { client, err = etcd.NewClientFromFile(etcdConfigFile) @@ -192,7 +195,7 @@ func newEtcd(etcdConfigFile string, etcdServerList util.StringList, storageVersi client = etcd.NewClient(etcdServerList) } - return master.NewEtcdHelper(client, storageVersion) + return master.NewEtcdHelper(client, storageVersion, pathPrefix) } // Run runs the specified APIServer. This should never exit. @@ -232,7 +235,7 @@ func (s *APIServer) Run(_ []string) error { glog.Fatalf("Invalid server address: %v", err) } - helper, err := newEtcd(s.EtcdConfigFile, s.EtcdServerList, s.StorageVersion) + helper, err := newEtcd(s.EtcdConfigFile, s.EtcdServerList, s.StorageVersion, s.EtcdPathPrefix) if err != nil { glog.Fatalf("Invalid storage version or misconfigured etcd: %v", err) } diff --git a/cmd/kubernetes/kubernetes.go b/cmd/kubernetes/kubernetes.go index 65cd939b8c2..267638316e3 100644 --- a/cmd/kubernetes/kubernetes.go +++ b/cmd/kubernetes/kubernetes.go @@ -81,7 +81,7 @@ func (h *delegateHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { func runApiServer(etcdClient tools.EtcdClient, addr net.IP, port int, masterServiceNamespace string) { handler := delegateHandler{} - helper, err := master.NewEtcdHelper(etcdClient, "") + helper, err := master.NewEtcdHelper(etcdClient, "", master.DefaultEtcdPathPrefix) if err != nil { glog.Fatalf("Unable to get etcd helper: %v", err) } diff --git a/hack/test-go.sh b/hack/test-go.sh index f2d787950ab..ddac88fe34c 100755 --- a/hack/test-go.sh +++ b/hack/test-go.sh @@ -53,6 +53,9 @@ KUBE_RACE=${KUBE_RACE:-} # use KUBE_RACE="-race" to enable race testing KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-} # Comma separated list of API Versions that should be tested. KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1beta1,v1beta3"} +# Prefixes for etcd paths (standard and customized) +ETCD_STANDARD_PREFIX="registry" +ETCD_CUSTOM_PREFIX="kubernetes.io/registry" kube::test::usage() { kube::log::usage_from_stdin <