Skip to content

Commit da53a24

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#29993 from mksalawa/remove_etcd_default_in_genericapiserver
Automatic merge from submit-queue Remove default etcd validation in generic apiserver Moving verification of `--etcd-servers` to the concrete apiserver instead of checking during defaulting in generic apiserver. The context for this change is that heapster (will be another apiserver) doesn't need to have etcd underneath. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.kubernetes.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.kubernetes.io/reviews/kubernetes/kubernetes/29993) <!-- Reviewable:end -->
2 parents ae40543 + a806351 commit da53a24

File tree

13 files changed

+179
-91
lines changed

13 files changed

+179
-91
lines changed

cmd/hyperkube/federation-apiserver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
// NewFederationAPIServer creates a new hyperkube Server object that includes the
2525
// description and flags.
2626
func NewFederationAPIServer() *Server {
27-
s := genericoptions.NewServerRunOptions()
27+
s := genericoptions.NewServerRunOptions().WithEtcdOptions()
2828

2929
hks := Server{
3030
SimpleUsage: "federation-apiserver",
@@ -33,6 +33,7 @@ func NewFederationAPIServer() *Server {
3333
return app.Run(s)
3434
},
3535
}
36-
s.AddFlags(hks.Flags())
36+
s.AddUniversalFlags(hks.Flags())
37+
s.AddEtcdStorageFlags(hks.Flags())
3738
return &hks
3839
}

cmd/kube-apiserver/app/options/options.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type APIServer struct {
4747
// NewAPIServer creates a new APIServer object with default parameters
4848
func NewAPIServer() *APIServer {
4949
s := APIServer{
50-
ServerRunOptions: genericoptions.NewServerRunOptions(),
50+
ServerRunOptions: genericoptions.NewServerRunOptions().WithEtcdOptions(),
5151
EventTTL: 1 * time.Hour,
5252
KubeletConfig: kubeletclient.KubeletClientConfig{
5353
Port: ports.KubeletPort,
@@ -62,7 +62,9 @@ func NewAPIServer() *APIServer {
6262
// AddFlags adds flags for a specific APIServer to the specified FlagSet
6363
func (s *APIServer) AddFlags(fs *pflag.FlagSet) {
6464
// Add the generic flags.
65-
s.ServerRunOptions.AddFlags(fs)
65+
s.ServerRunOptions.AddUniversalFlags(fs)
66+
//Add etcd specific flags.
67+
s.ServerRunOptions.AddEtcdStorageFlags(fs)
6668
// Note: the weird ""+ in below lines seems to be the only way to get gofmt to
6769
// arrange these text blocks sensibly. Grrr.
6870

cmd/kube-apiserver/app/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"k8s.io/kubernetes/pkg/controller/framework/informers"
4747
serviceaccountcontroller "k8s.io/kubernetes/pkg/controller/serviceaccount"
4848
"k8s.io/kubernetes/pkg/genericapiserver"
49+
genericvalidation "k8s.io/kubernetes/pkg/genericapiserver/validation"
4950
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
5051
"k8s.io/kubernetes/pkg/master"
5152
"k8s.io/kubernetes/pkg/registry/cachesize"
@@ -81,6 +82,7 @@ cluster's shared state through which all other components interact.`,
8182

8283
// Run runs the specified APIServer. This should never exit.
8384
func Run(s *options.APIServer) error {
85+
genericvalidation.VerifyEtcdServersList(s.ServerRunOptions)
8486
genericapiserver.DefaultAndValidateRunOptions(s.ServerRunOptions)
8587

8688
capabilities.Initialize(capabilities.Capabilities{

examples/apiserver/apiserver.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"k8s.io/kubernetes/pkg/apimachinery/registered"
2929
"k8s.io/kubernetes/pkg/genericapiserver"
3030
genericoptions "k8s.io/kubernetes/pkg/genericapiserver/options"
31+
genericvalidation "k8s.io/kubernetes/pkg/genericapiserver/validation"
3132
"k8s.io/kubernetes/pkg/storage/storagebackend"
3233

3334
// Install the testgroup API
@@ -51,7 +52,7 @@ func newStorageFactory() genericapiserver.StorageFactory {
5152
}
5253

5354
func NewServerRunOptions() *genericoptions.ServerRunOptions {
54-
serverOptions := genericoptions.NewServerRunOptions()
55+
serverOptions := genericoptions.NewServerRunOptions().WithEtcdOptions()
5556
serverOptions.InsecurePort = InsecurePort
5657
return serverOptions
5758
}
@@ -61,7 +62,8 @@ func Run(serverOptions *genericoptions.ServerRunOptions) error {
6162
_, serviceClusterIPRange, _ := net.ParseCIDR("10.0.0.0/24")
6263
serverOptions.ServiceClusterIPRange = *serviceClusterIPRange
6364
serverOptions.StorageConfig.ServerList = []string{"http://127.0.0.1:4001"}
64-
genericapiserver.ValidateRunOptions(serverOptions)
65+
genericvalidation.ValidateRunOptions(serverOptions)
66+
genericvalidation.VerifyEtcdServersList(serverOptions)
6567
config := genericapiserver.NewConfig(serverOptions)
6668
config.Serializer = api.Codecs
6769
s, err := genericapiserver.New(config)

examples/apiserver/server/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ func main() {
2828
serverRunOptions := apiserver.NewServerRunOptions()
2929

3030
// Parse command line flags.
31-
serverRunOptions.AddFlags(pflag.CommandLine)
31+
serverRunOptions.AddUniversalFlags(pflag.CommandLine)
32+
serverRunOptions.AddEtcdStorageFlags(pflag.CommandLine)
3233
flag.InitFlags()
3334

3435
if err := apiserver.Run(serverRunOptions); err != nil {

federation/cmd/federation-apiserver/apiserver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ import (
3636
func main() {
3737
rand.Seed(time.Now().UTC().UnixNano())
3838

39-
s := genericoptions.NewServerRunOptions()
40-
s.AddFlags(pflag.CommandLine)
39+
s := genericoptions.NewServerRunOptions().WithEtcdOptions()
40+
s.AddUniversalFlags(pflag.CommandLine)
41+
s.AddEtcdStorageFlags(pflag.CommandLine)
4142

4243
flag.InitFlags()
4344
util.InitLogs()

federation/cmd/federation-apiserver/app/server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ import (
3535
"k8s.io/kubernetes/pkg/controller/framework/informers"
3636
"k8s.io/kubernetes/pkg/genericapiserver"
3737
genericoptions "k8s.io/kubernetes/pkg/genericapiserver/options"
38+
genericvalidation "k8s.io/kubernetes/pkg/genericapiserver/validation"
3839
"k8s.io/kubernetes/pkg/registry/cachesize"
3940
"k8s.io/kubernetes/pkg/registry/generic"
4041
"k8s.io/kubernetes/pkg/util/wait"
4142
)
4243

4344
// NewAPIServerCommand creates a *cobra.Command object with default parameters
4445
func NewAPIServerCommand() *cobra.Command {
45-
s := genericoptions.NewServerRunOptions()
46-
s.AddFlags(pflag.CommandLine)
46+
s := genericoptions.NewServerRunOptions().WithEtcdOptions()
47+
s.AddUniversalFlags(pflag.CommandLine)
48+
s.AddEtcdStorageFlags(pflag.CommandLine)
4749
cmd := &cobra.Command{
4850
Use: "federation-apiserver",
4951
Long: `The Kubernetes federation API server validates and configures data
@@ -59,6 +61,7 @@ cluster's shared state through which all other components interact.`,
5961

6062
// Run runs the specified APIServer. This should never exit.
6163
func Run(s *genericoptions.ServerRunOptions) error {
64+
genericvalidation.VerifyEtcdServersList(s)
6265
genericapiserver.DefaultAndValidateRunOptions(s)
6366

6467
// TODO: register cluster federation resources here.

federation/cmd/federation-apiserver/app/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
)
3737

3838
func TestLongRunningRequestRegexp(t *testing.T) {
39-
regexp := regexp.MustCompile(options.NewServerRunOptions().LongRunningRequestRE)
39+
regexp := regexp.MustCompile(options.NewServerRunOptions().WithEtcdOptions().LongRunningRequestRE)
4040
dontMatch := []string{
4141
"/api/v1/watch-namespace/",
4242
"/api/v1/namespace-proxy/",
@@ -84,7 +84,7 @@ var groupVersions = []unversioned.GroupVersion{
8484
}
8585

8686
func TestRun(t *testing.T) {
87-
s := options.NewServerRunOptions()
87+
s := options.NewServerRunOptions().WithEtcdOptions()
8888
s.InsecurePort = insecurePort
8989
_, ipNet, _ := net.ParseCIDR("10.10.10.0/24")
9090
s.ServiceClusterIPRange = *ipNet

pkg/genericapiserver/genericapiserver.go

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"k8s.io/kubernetes/pkg/auth/handlers"
4343
"k8s.io/kubernetes/pkg/cloudprovider"
4444
"k8s.io/kubernetes/pkg/genericapiserver/options"
45+
genericvalidation "k8s.io/kubernetes/pkg/genericapiserver/validation"
4546
"k8s.io/kubernetes/pkg/registry/generic"
4647
"k8s.io/kubernetes/pkg/registry/generic/registry"
4748
ipallocator "k8s.io/kubernetes/pkg/registry/service/ipallocator"
@@ -536,17 +537,6 @@ func (s *GenericAPIServer) installGroupsDiscoveryHandler() {
536537
})
537538
}
538539

539-
// TODO: Longer term we should read this from some config store, rather than a flag.
540-
func verifyClusterIPFlags(options *options.ServerRunOptions) {
541-
if options.ServiceClusterIPRange.IP == nil {
542-
glog.Fatal("No --service-cluster-ip-range specified")
543-
}
544-
var ones, bits = options.ServiceClusterIPRange.Mask.Size()
545-
if bits-ones > 20 {
546-
glog.Fatal("Specified --service-cluster-ip-range is too large")
547-
}
548-
}
549-
550540
func NewConfig(options *options.ServerRunOptions) *Config {
551541
return &Config{
552542
APIGroupPrefix: options.APIGroupPrefix,
@@ -570,46 +560,8 @@ func NewConfig(options *options.ServerRunOptions) *Config {
570560
}
571561
}
572562

573-
func verifyServiceNodePort(options *options.ServerRunOptions) {
574-
if options.KubernetesServiceNodePort < 0 || options.KubernetesServiceNodePort > 65535 {
575-
glog.Fatalf("--kubernetes-service-node-port %v must be between 0 and 65535, inclusive. If 0, the Kubernetes master service will be of type ClusterIP.", options.KubernetesServiceNodePort)
576-
}
577-
578-
if options.KubernetesServiceNodePort > 0 && !options.ServiceNodePortRange.Contains(options.KubernetesServiceNodePort) {
579-
glog.Fatalf("Kubernetes service port range %v doesn't contain %v", options.ServiceNodePortRange, (options.KubernetesServiceNodePort))
580-
}
581-
}
582-
583-
func verifyEtcdServersList(options *options.ServerRunOptions) {
584-
if len(options.StorageConfig.ServerList) == 0 {
585-
glog.Fatalf("--etcd-servers must be specified")
586-
}
587-
}
588-
589-
func verifySecureAndInsecurePort(options *options.ServerRunOptions) {
590-
if options.SecurePort < 0 || options.SecurePort > 65535 {
591-
glog.Fatalf("--secure-port %v must be between 0 and 65535, inclusive. 0 for turning off secure port.", options.SecurePort)
592-
}
593-
594-
// TODO: Allow 0 to turn off insecure port.
595-
if options.InsecurePort < 1 || options.InsecurePort > 65535 {
596-
glog.Fatalf("--insecure-port %v must be between 1 and 65535, inclusive.", options.InsecurePort)
597-
}
598-
599-
if options.SecurePort == options.InsecurePort {
600-
glog.Fatalf("--secure-port and --insecure-port cannot use the same port.")
601-
}
602-
}
603-
604-
func ValidateRunOptions(options *options.ServerRunOptions) {
605-
verifyClusterIPFlags(options)
606-
verifyServiceNodePort(options)
607-
verifyEtcdServersList(options)
608-
verifySecureAndInsecurePort(options)
609-
}
610-
611563
func DefaultAndValidateRunOptions(options *options.ServerRunOptions) {
612-
ValidateRunOptions(options)
564+
genericvalidation.ValidateRunOptions(options)
613565

614566
// If advertise-address is not specified, use bind-address. If bind-address
615567
// is not usable (unset, 0.0.0.0, or loopback), we will use the host's default
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2016 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package options
18+
19+
import (
20+
"github.com/spf13/pflag"
21+
)
22+
23+
const (
24+
DefaultEtcdPathPrefix = "/registry"
25+
)
26+
27+
// AddEtcdFlags adds flags related to etcd storage for a specific APIServer to the specified FlagSet
28+
func (s *ServerRunOptions) AddEtcdStorageFlags(fs *pflag.FlagSet) {
29+
30+
fs.StringSliceVar(&s.EtcdServersOverrides, "etcd-servers-overrides", s.EtcdServersOverrides, ""+
31+
"Per-resource etcd servers overrides, comma separated. The individual override "+
32+
"format: group/resource#servers, where servers are http://ip:port, semicolon separated.")
33+
34+
fs.StringSliceVar(&s.StorageConfig.ServerList, "etcd-servers", s.StorageConfig.ServerList,
35+
"List of etcd servers to connect with (http://ip:port), comma separated.")
36+
37+
fs.StringVar(&s.StorageConfig.Prefix, "etcd-prefix", s.StorageConfig.Prefix,
38+
"The prefix for all resource paths in etcd.")
39+
40+
fs.StringVar(&s.StorageConfig.KeyFile, "etcd-keyfile", s.StorageConfig.KeyFile,
41+
"SSL key file used to secure etcd communication.")
42+
43+
fs.StringVar(&s.StorageConfig.CertFile, "etcd-certfile", s.StorageConfig.CertFile,
44+
"SSL certification file used to secure etcd communication.")
45+
46+
fs.StringVar(&s.StorageConfig.CAFile, "etcd-cafile", s.StorageConfig.CAFile,
47+
"SSL Certificate Authority file used to secure etcd communication.")
48+
49+
fs.BoolVar(&s.StorageConfig.Quorum, "etcd-quorum-read", s.StorageConfig.Quorum,
50+
"If true, enable quorum read.")
51+
}

0 commit comments

Comments
 (0)