From e3e31ecd40e7d4d8e7a59b72e072cfa4d521fe9e Mon Sep 17 00:00:00 2001 From: Ryan Phillips Date: Thu, 18 Jan 2018 13:24:39 -0600 Subject: [PATCH 1/3] apiserver: change default reconciler to LeaseEndpoint Fixes #57617 --- cmd/kube-apiserver/app/options/options.go | 4 ++-- cmd/kube-apiserver/app/options/options_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/kube-apiserver/app/options/options.go b/cmd/kube-apiserver/app/options/options.go index 4a68bb78eba..080cbcd88f3 100644 --- a/cmd/kube-apiserver/app/options/options.go +++ b/cmd/kube-apiserver/app/options/options.go @@ -94,7 +94,7 @@ func NewServerRunOptions() *ServerRunOptions { EnableLogsHandler: true, EventTTL: 1 * time.Hour, MasterCount: 1, - EndpointReconcilerType: string(reconcilers.MasterCountReconcilerType), + EndpointReconcilerType: string(reconcilers.LeaseEndpointReconcilerType), KubeletConfig: kubeletclient.KubeletClientConfig{ Port: ports.KubeletPort, ReadOnlyPort: ports.KubeletReadOnlyPort, @@ -167,7 +167,7 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) { "Currently only applies to long-running requests.") fs.IntVar(&s.MasterCount, "apiserver-count", s.MasterCount, - "The number of apiservers running in the cluster, must be a positive number.") + "The number of apiservers running in the cluster, must be a positive number. (In use when --endpoint-reconciler-type=master-count is enabled.)") fs.StringVar(&s.EndpointReconcilerType, "endpoint-reconciler-type", string(s.EndpointReconcilerType), "Use an endpoint reconciler ("+strings.Join(reconcilers.AllTypes.Names(), ", ")+")") diff --git a/cmd/kube-apiserver/app/options/options_test.go b/cmd/kube-apiserver/app/options/options_test.go index 98629c30a60..3e931ca619c 100644 --- a/cmd/kube-apiserver/app/options/options_test.go +++ b/cmd/kube-apiserver/app/options/options_test.go @@ -96,7 +96,7 @@ func TestAddFlags(t *testing.T) { "--enable-aggregator-routing=true", "--enable-logs-handler=false", "--enable-swagger-ui=true", - "--endpoint-reconciler-type=" + string(reconcilers.MasterCountReconcilerType), + "--endpoint-reconciler-type=" + string(reconcilers.LeaseEndpointReconcilerType), "--etcd-quorum-read=false", "--etcd-keyfile=/var/run/kubernetes/etcd.key", "--etcd-certfile=/var/run/kubernetes/etcdce.crt", @@ -120,7 +120,7 @@ func TestAddFlags(t *testing.T) { ServiceNodePortRange: kubeoptions.DefaultServiceNodePortRange, ServiceClusterIPRange: kubeoptions.DefaultServiceIPCIDR, MasterCount: 5, - EndpointReconcilerType: string(reconcilers.MasterCountReconcilerType), + EndpointReconcilerType: string(reconcilers.LeaseEndpointReconcilerType), AllowPrivileged: false, GenericServerRunOptions: &apiserveroptions.ServerRunOptions{ AdvertiseAddress: net.ParseIP("192.168.10.10"), From a2ef4735cde4c900c97d26251fd573013fefb4eb Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Wed, 2 May 2018 22:44:28 -0400 Subject: [PATCH 2/3] Let the kubernetes service reconciler timeout on shutdown --- pkg/master/controller.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/master/controller.go b/pkg/master/controller.go index 78154d176ef..e83f0cacb3d 100644 --- a/pkg/master/controller.go +++ b/pkg/master/controller.go @@ -152,7 +152,22 @@ func (c *Controller) Stop() { c.runner.Stop() } endpointPorts := createEndpointPortSpec(c.PublicServicePort, "https", c.ExtraEndpointPorts) - c.EndpointReconciler.StopReconciling("kubernetes", c.PublicIP, endpointPorts) + finishedReconciling := make(chan struct{}) + go func() { + defer close(finishedReconciling) + glog.Infof("Shutting down kubernetes service endpoint reconciler") + if err := c.EndpointReconciler.StopReconciling("kubernetes", c.PublicIP, endpointPorts); err != nil { + glog.Error(err) + } + }() + + select { + case <-finishedReconciling: + // done + case <-time.After(2 * c.EndpointInterval): + // don't block server shutdown forever if we can't reach etcd to remove ourselves + glog.Warning("StopReconciling() timed out") + } } // RunKubernetesNamespaces periodically makes sure that all internal namespaces exist From 30f2962ede72a8e6a58efabed1dbd2241dcbcaa5 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Wed, 2 May 2018 22:44:48 -0400 Subject: [PATCH 3/3] Make openapi spec generation wait for the apiserver on shutdown --- hack/update-openapi-spec.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hack/update-openapi-spec.sh b/hack/update-openapi-spec.sh index b0016bc29b9..0155dbc3547 100755 --- a/hack/update-openapi-spec.sh +++ b/hack/update-openapi-spec.sh @@ -31,7 +31,11 @@ make -C "${KUBE_ROOT}" WHAT=cmd/kube-apiserver function cleanup() { - [[ -n ${APISERVER_PID-} ]] && kill ${APISERVER_PID} 1>&2 2>/dev/null + if [[ -n ${APISERVER_PID-} ]]; then + kill ${APISERVER_PID} 1>&2 2>/dev/null + wait ${APISERVER_PID} || true + fi + unset APISERVER_PID kube::etcd::cleanup