Skip to content

Commit 31b8c0d

Browse files
authored
Merge pull request kubernetes#87656 from ereslibre/do-not-depend-on-cluster-status
kubeadm: deprecate the `ClusterStatus` dependency
2 parents b893aa7 + 3e59a06 commit 31b8c0d

File tree

20 files changed

+1172
-191
lines changed

20 files changed

+1172
-191
lines changed

cmd/kubeadm/app/apis/kubeadm/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ load(
99
go_library(
1010
name = "go_default_library",
1111
srcs = [
12+
"apiendpoint.go",
1213
"bootstraptokenhelpers.go",
1314
"bootstraptokenstring.go",
1415
"doc.go",
@@ -52,6 +53,7 @@ filegroup(
5253
go_test(
5354
name = "go_default_test",
5455
srcs = [
56+
"apiendpoint_test.go",
5557
"bootstraptokenhelpers_test.go",
5658
"bootstraptokenstring_test.go",
5759
],
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2020 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 kubeadm
18+
19+
import (
20+
"net"
21+
"strconv"
22+
23+
"github.com/pkg/errors"
24+
)
25+
26+
// APIEndpointFromString returns an APIEndpoint struct based on a "host:port" raw string.
27+
func APIEndpointFromString(apiEndpoint string) (APIEndpoint, error) {
28+
apiEndpointHost, apiEndpointPortStr, err := net.SplitHostPort(apiEndpoint)
29+
if err != nil {
30+
return APIEndpoint{}, errors.Wrapf(err, "invalid advertise address endpoint: %s", apiEndpoint)
31+
}
32+
apiEndpointPort, err := net.LookupPort("tcp", apiEndpointPortStr)
33+
if err != nil {
34+
return APIEndpoint{}, errors.Wrapf(err, "invalid advertise address endpoint port: %s", apiEndpointPortStr)
35+
}
36+
return APIEndpoint{
37+
AdvertiseAddress: apiEndpointHost,
38+
BindPort: int32(apiEndpointPort),
39+
}, nil
40+
}
41+
42+
func (endpoint *APIEndpoint) String() string {
43+
return net.JoinHostPort(endpoint.AdvertiseAddress, strconv.FormatInt(int64(endpoint.BindPort), 10))
44+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2020 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 kubeadm
18+
19+
import (
20+
"reflect"
21+
"testing"
22+
)
23+
24+
func TestAPIEndpointFromString(t *testing.T) {
25+
var tests = []struct {
26+
apiEndpoint string
27+
expectedEndpoint APIEndpoint
28+
expectedErr bool
29+
}{
30+
{apiEndpoint: "1.2.3.4:1234", expectedEndpoint: APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 1234}},
31+
{apiEndpoint: "1.2.3.4:-1", expectedErr: true},
32+
{apiEndpoint: "1.2.::1234", expectedErr: true},
33+
{apiEndpoint: "1.2.3.4:65536", expectedErr: true},
34+
{apiEndpoint: "[::1]:1234", expectedEndpoint: APIEndpoint{AdvertiseAddress: "::1", BindPort: 1234}},
35+
{apiEndpoint: "[::1]:-1", expectedErr: true},
36+
{apiEndpoint: "[::1]:65536", expectedErr: true},
37+
{apiEndpoint: "[::1:1234", expectedErr: true},
38+
}
39+
for _, rt := range tests {
40+
t.Run(rt.apiEndpoint, func(t *testing.T) {
41+
apiEndpoint, err := APIEndpointFromString(rt.apiEndpoint)
42+
if (err != nil) != rt.expectedErr {
43+
t.Errorf("expected error %v, got %v, error: %v", rt.expectedErr, err != nil, err)
44+
}
45+
if !reflect.DeepEqual(apiEndpoint, rt.expectedEndpoint) {
46+
t.Errorf("expected API endpoint: %v; got: %v", rt.expectedEndpoint, apiEndpoint)
47+
}
48+
})
49+
}
50+
}

cmd/kubeadm/app/constants/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ go_library(
1818
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
1919
"//staging/src/k8s.io/api/core/v1:go_default_library",
2020
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
21+
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
2122
"//staging/src/k8s.io/cluster-bootstrap/token/api:go_default_library",
2223
"//vendor/github.com/pkg/errors:go_default_library",
2324
"//vendor/k8s.io/utils/net:go_default_library",

cmd/kubeadm/app/constants/constants.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/pkg/errors"
3030
v1 "k8s.io/api/core/v1"
3131
"k8s.io/apimachinery/pkg/util/version"
32+
"k8s.io/apimachinery/pkg/util/wait"
3233
bootstrapapi "k8s.io/cluster-bootstrap/token/api"
3334
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
3435
utilnet "k8s.io/utils/net"
@@ -370,6 +371,16 @@ const (
370371
// May be overridden by a flag at startup.
371372
KubeControllerManagerPort = 10257
372373

374+
// EtcdAdvertiseClientUrlsAnnotationKey is the annotation key on every etcd pod, describing the
375+
// advertise client URLs
376+
EtcdAdvertiseClientUrlsAnnotationKey = "kubeadm.kubernetes.io/etcd.advertise-client-urls"
377+
// KubeAPIServerAdvertiseAddressEndpointAnnotationKey is the annotation key on every apiserver pod,
378+
// describing the API endpoint (advertise address and bind port of the api server)
379+
KubeAPIServerAdvertiseAddressEndpointAnnotationKey = "kubeadm.kubernetes.io/kube-apiserver.advertise-address.endpoint"
380+
381+
// ControlPlaneTier is the value used in the tier label to identify control plane components
382+
ControlPlaneTier = "control-plane"
383+
373384
// Mode* constants were copied from pkg/kubeapiserver/authorizer/modes
374385
// to avoid kubeadm dependency on the internal module
375386
// TODO: share Mode* constants in component config
@@ -433,6 +444,15 @@ var (
433444
// KubeadmCertsClusterRoleName sets the name for the ClusterRole that allows
434445
// the bootstrap tokens to access the kubeadm-certs Secret during the join of a new control-plane
435446
KubeadmCertsClusterRoleName = fmt.Sprintf("kubeadm:%s", KubeadmCertsSecret)
447+
448+
// StaticPodMirroringDefaultRetry is used a backoff strategy for
449+
// waiting for static pods to be mirrored to the apiserver.
450+
StaticPodMirroringDefaultRetry = wait.Backoff{
451+
Steps: 30,
452+
Duration: 1 * time.Second,
453+
Factor: 1.0,
454+
Jitter: 0.1,
455+
}
436456
)
437457

438458
// EtcdSupportedVersion returns officially supported version of etcd for a specific Kubernetes release

cmd/kubeadm/app/phases/controlplane/manifests.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func GetStaticPodSpecs(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmap
5959
LivenessProbe: staticpodutil.LivenessProbe(staticpodutil.GetAPIServerProbeAddress(endpoint), "/healthz", int(endpoint.BindPort), v1.URISchemeHTTPS),
6060
Resources: staticpodutil.ComponentResources("250m"),
6161
Env: kubeadmutil.GetProxyEnvVars(),
62-
}, mounts.GetVolumes(kubeadmconstants.KubeAPIServer)),
62+
}, mounts.GetVolumes(kubeadmconstants.KubeAPIServer),
63+
map[string]string{kubeadmconstants.KubeAPIServerAdvertiseAddressEndpointAnnotationKey: endpoint.String()}),
6364
kubeadmconstants.KubeControllerManager: staticpodutil.ComponentPod(v1.Container{
6465
Name: kubeadmconstants.KubeControllerManager,
6566
Image: images.GetKubernetesImage(kubeadmconstants.KubeControllerManager, cfg),
@@ -69,7 +70,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmap
6970
LivenessProbe: staticpodutil.LivenessProbe(staticpodutil.GetControllerManagerProbeAddress(cfg), "/healthz", kubeadmconstants.KubeControllerManagerPort, v1.URISchemeHTTPS),
7071
Resources: staticpodutil.ComponentResources("200m"),
7172
Env: kubeadmutil.GetProxyEnvVars(),
72-
}, mounts.GetVolumes(kubeadmconstants.KubeControllerManager)),
73+
}, mounts.GetVolumes(kubeadmconstants.KubeControllerManager), nil),
7374
kubeadmconstants.KubeScheduler: staticpodutil.ComponentPod(v1.Container{
7475
Name: kubeadmconstants.KubeScheduler,
7576
Image: images.GetKubernetesImage(kubeadmconstants.KubeScheduler, cfg),
@@ -79,7 +80,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmap
7980
LivenessProbe: staticpodutil.LivenessProbe(staticpodutil.GetSchedulerProbeAddress(cfg), "/healthz", kubeadmconstants.KubeSchedulerPort, v1.URISchemeHTTPS),
8081
Resources: staticpodutil.ComponentResources("100m"),
8182
Env: kubeadmutil.GetProxyEnvVars(),
82-
}, mounts.GetVolumes(kubeadmconstants.KubeScheduler)),
83+
}, mounts.GetVolumes(kubeadmconstants.KubeScheduler), nil),
8384
}
8485
return staticPodSpecs
8586
}

cmd/kubeadm/app/phases/etcd/local.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,23 @@ func GetEtcdPodSpec(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmapi.A
181181
}
182182
// probeHostname returns the correct localhost IP address family based on the endpoint AdvertiseAddress
183183
probeHostname, probePort, probeScheme := staticpodutil.GetEtcdProbeEndpoint(&cfg.Etcd, utilsnet.IsIPv6String(endpoint.AdvertiseAddress))
184-
return staticpodutil.ComponentPod(v1.Container{
185-
Name: kubeadmconstants.Etcd,
186-
Command: getEtcdCommand(cfg, endpoint, nodeName, initialCluster),
187-
Image: images.GetEtcdImage(cfg),
188-
ImagePullPolicy: v1.PullIfNotPresent,
189-
// Mount the etcd datadir path read-write so etcd can store data in a more persistent manner
190-
VolumeMounts: []v1.VolumeMount{
191-
staticpodutil.NewVolumeMount(etcdVolumeName, cfg.Etcd.Local.DataDir, false),
192-
staticpodutil.NewVolumeMount(certsVolumeName, cfg.CertificatesDir+"/etcd", false),
184+
return staticpodutil.ComponentPod(
185+
v1.Container{
186+
Name: kubeadmconstants.Etcd,
187+
Command: getEtcdCommand(cfg, endpoint, nodeName, initialCluster),
188+
Image: images.GetEtcdImage(cfg),
189+
ImagePullPolicy: v1.PullIfNotPresent,
190+
// Mount the etcd datadir path read-write so etcd can store data in a more persistent manner
191+
VolumeMounts: []v1.VolumeMount{
192+
staticpodutil.NewVolumeMount(etcdVolumeName, cfg.Etcd.Local.DataDir, false),
193+
staticpodutil.NewVolumeMount(certsVolumeName, cfg.CertificatesDir+"/etcd", false),
194+
},
195+
LivenessProbe: staticpodutil.LivenessProbe(probeHostname, "/health", probePort, probeScheme),
193196
},
194-
LivenessProbe: staticpodutil.LivenessProbe(probeHostname, "/health", probePort, probeScheme),
195-
}, etcdMounts)
197+
etcdMounts,
198+
// etcd will listen on the advertise address of the API server, in a different port (2379)
199+
map[string]string{kubeadmconstants.EtcdAdvertiseClientUrlsAnnotationKey: etcdutil.GetClientURL(endpoint)},
200+
)
196201
}
197202

198203
// getEtcdCommand builds the right etcd command from the given config object

cmd/kubeadm/app/util/config/BUILD

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ go_library(
3131
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
3232
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
3333
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
34+
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
3435
"//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library",
3536
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
37+
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
3638
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
3739
"//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library",
3840
"//staging/src/k8s.io/client-go/util/cert:go_default_library",
@@ -60,14 +62,18 @@ go_test(
6062
"//cmd/kubeadm/app/componentconfigs:go_default_library",
6163
"//cmd/kubeadm/app/constants:go_default_library",
6264
"//cmd/kubeadm/app/util:go_default_library",
63-
"//cmd/kubeadm/app/util/apiclient:go_default_library",
65+
"//cmd/kubeadm/test/resources:go_default_library",
6466
"//staging/src/k8s.io/api/core/v1:go_default_library",
67+
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
6568
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
69+
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
6670
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
6771
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
68-
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
72+
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
6973
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
74+
"//staging/src/k8s.io/client-go/testing:go_default_library",
7075
"//vendor/github.com/lithammer/dedent:go_default_library",
76+
"//vendor/github.com/pkg/errors:go_default_library",
7177
"//vendor/github.com/pmezard/go-difflib/difflib:go_default_library",
7278
"//vendor/sigs.k8s.io/yaml:go_default_library",
7379
],

0 commit comments

Comments
 (0)