Skip to content

Commit

Permalink
Merge pull request kubernetes#126945 from liangyuanpeng/kubeadm_split…
Browse files Browse the repository at this point in the history
…_healthz_scheduler

kubeadm: scheduler using livez and readyz instead of healthz.
  • Loading branch information
k8s-ci-robot authored Sep 3, 2024
2 parents 7de63a8 + db8f3a4 commit 85384fe
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 19 deletions.
4 changes: 1 addition & 3 deletions cmd/kubeadm/app/apis/kubeadm/v1beta3/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const (
DefaultClusterDNSIP = "10.96.0.10"
// DefaultKubernetesVersion defines default kubernetes version
DefaultKubernetesVersion = "stable-1"
// DefaultAPIBindPort defines default API port
DefaultAPIBindPort = 6443
// DefaultCertificatesDir defines default certificate directory
DefaultCertificatesDir = "/etc/kubernetes/pki"
// DefaultImageRepository defines default image registry
Expand Down Expand Up @@ -189,7 +187,7 @@ func SetDefaults_BootstrapTokens(obj *InitConfiguration) {
// SetDefaults_APIEndpoint sets the defaults for the API server instance deployed on a node.
func SetDefaults_APIEndpoint(obj *APIEndpoint) {
if obj.BindPort == 0 {
obj.BindPort = DefaultAPIBindPort
obj.BindPort = constants.KubeAPIServerPort
}
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/kubeadm/app/apis/kubeadm/v1beta4/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const (
DefaultClusterDNSIP = "10.96.0.10"
// DefaultKubernetesVersion defines default kubernetes version
DefaultKubernetesVersion = "stable-1"
// DefaultAPIBindPort defines default API port
DefaultAPIBindPort = 6443
// DefaultCertificatesDir defines default certificate directory
DefaultCertificatesDir = "/etc/kubernetes/pki"
// DefaultImageRepository defines default image registry
Expand Down Expand Up @@ -197,7 +195,7 @@ func SetDefaults_BootstrapTokens(obj *InitConfiguration) {
// SetDefaults_APIEndpoint sets the defaults for the API server instance deployed on a node.
func SetDefaults_APIEndpoint(obj *APIEndpoint) {
if obj.BindPort == 0 {
obj.BindPort = DefaultAPIBindPort
obj.BindPort = constants.KubeAPIServerPort
}
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/kubeadm/app/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ const (
// KubeControllerManagerPort is the default port for the controller manager status server.
// May be overridden by a flag at startup.
KubeControllerManagerPort = 10257
// KubeAPIServerPort is the default port for the apiserver.
// May be overridden by a flag at startup.
KubeAPIServerPort = 6443

// EtcdAdvertiseClientUrlsAnnotationKey is the annotation key on every etcd pod, describing the
// advertise client URLs
Expand Down
5 changes: 3 additions & 2 deletions cmd/kubeadm/app/phases/controlplane/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func GetStaticPodSpecs(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmap
ImagePullPolicy: v1.PullIfNotPresent,
Command: getSchedulerCommand(cfg),
VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeScheduler)),
LivenessProbe: staticpodutil.LivenessProbe(staticpodutil.GetSchedulerProbeAddress(cfg), "/healthz", kubeadmconstants.KubeSchedulerPort, v1.URISchemeHTTPS),
StartupProbe: staticpodutil.StartupProbe(staticpodutil.GetSchedulerProbeAddress(cfg), "/healthz", kubeadmconstants.KubeSchedulerPort, v1.URISchemeHTTPS, componentHealthCheckTimeout),
LivenessProbe: staticpodutil.LivenessProbe(staticpodutil.GetSchedulerProbeAddress(cfg), "/livez", kubeadmconstants.KubeSchedulerPort, v1.URISchemeHTTPS),
ReadinessProbe: staticpodutil.ReadinessProbe(staticpodutil.GetSchedulerProbeAddress(cfg), "/readyz", kubeadmconstants.KubeSchedulerPort, v1.URISchemeHTTPS),
StartupProbe: staticpodutil.StartupProbe(staticpodutil.GetSchedulerProbeAddress(cfg), "/livez", kubeadmconstants.KubeSchedulerPort, v1.URISchemeHTTPS, componentHealthCheckTimeout),
Resources: staticpodutil.ComponentResources("100m"),
Env: kubeadmutil.MergeKubeadmEnvVars(proxyEnvs, cfg.Scheduler.ExtraEnvs),
}, mounts.GetVolumes(kubeadmconstants.KubeScheduler), nil),
Expand Down
62 changes: 51 additions & 11 deletions cmd/kubeadm/app/phases/controlplane/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"

"k8s.io/apimachinery/pkg/util/intstr"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
Expand Down Expand Up @@ -60,25 +61,43 @@ func TestGetStaticPodSpecs(t *testing.T) {
}

// Executes GetStaticPodSpecs
specs := GetStaticPodSpecs(cfg, &kubeadmapi.APIEndpoint{}, []kubeadmapi.EnvVar{})
specs := GetStaticPodSpecs(cfg, &kubeadmapi.APIEndpoint{
BindPort: kubeadmconstants.KubeAPIServerPort,
}, []kubeadmapi.EnvVar{})

var tests = []struct {
name string
staticPodName string
env []v1.EnvVar
name string
staticPodName string
expectLivenessProbe bool
expectReadinessProbe bool
expectStartupProbe bool
probePort int32
env []v1.EnvVar
}{
{
name: "KubeAPIServer",
staticPodName: kubeadmconstants.KubeAPIServer,
name: "KubeAPIServer",
staticPodName: kubeadmconstants.KubeAPIServer,
expectLivenessProbe: true,
expectReadinessProbe: true,
expectStartupProbe: true,
probePort: kubeadmconstants.KubeAPIServerPort,
},
{
name: "KubeControllerManager",
staticPodName: kubeadmconstants.KubeControllerManager,
name: "KubeControllerManager",
staticPodName: kubeadmconstants.KubeControllerManager,
expectLivenessProbe: true,
expectReadinessProbe: false,
expectStartupProbe: true,
probePort: kubeadmconstants.KubeControllerManagerPort,
},
{
name: "KubeScheduler",
staticPodName: kubeadmconstants.KubeScheduler,
env: []v1.EnvVar{{Name: "Foo", Value: "Bar"}},
name: "KubeScheduler",
staticPodName: kubeadmconstants.KubeScheduler,
expectLivenessProbe: true,
expectReadinessProbe: true,
expectStartupProbe: true,
probePort: kubeadmconstants.KubeSchedulerPort,
env: []v1.EnvVar{{Name: "Foo", Value: "Bar"}},
},
}

Expand All @@ -95,6 +114,27 @@ func TestGetStaticPodSpecs(t *testing.T) {
t.Errorf("expected env: %v, got: %v", tc.env, spec.Spec.Containers[0].Env)
}
}

if tc.expectLivenessProbe != (spec.Spec.Containers[0].LivenessProbe != nil) {
t.Errorf("expected livenessProbe: %v, got: %v", tc.expectLivenessProbe, (spec.Spec.Containers[0].LivenessProbe != nil))
}
if tc.expectReadinessProbe != (spec.Spec.Containers[0].ReadinessProbe != nil) {
t.Errorf("expected readinessProbe: %v, got: %v", tc.expectReadinessProbe, (spec.Spec.Containers[0].ReadinessProbe != nil))
}
if tc.expectStartupProbe != (spec.Spec.Containers[0].StartupProbe != nil) {
t.Errorf("expected startupProbe: %v, got: %v", tc.expectStartupProbe, (spec.Spec.Containers[0].StartupProbe != nil))
}

if spec.Spec.Containers[0].LivenessProbe != nil && tc.probePort > 0 && !reflect.DeepEqual(intstr.FromInt32(tc.probePort), spec.Spec.Containers[0].LivenessProbe.HTTPGet.Port) {
t.Errorf("expected livenessProbe port: %v, got: %v", intstr.FromInt32(tc.probePort), spec.Spec.Containers[0].LivenessProbe.HTTPGet.Port)
}
if spec.Spec.Containers[0].ReadinessProbe != nil && tc.probePort > 0 && !reflect.DeepEqual(intstr.FromInt32(tc.probePort), spec.Spec.Containers[0].ReadinessProbe.HTTPGet.Port) {
t.Errorf("expected readinessProbe port: %v, got: %v", intstr.FromInt32(tc.probePort), spec.Spec.Containers[0].ReadinessProbe.HTTPGet.Port)
}
if spec.Spec.Containers[0].StartupProbe != nil && tc.probePort > 0 && !reflect.DeepEqual(intstr.FromInt32(tc.probePort), spec.Spec.Containers[0].StartupProbe.HTTPGet.Port) {
t.Errorf("expected startupProbe port: %v, got: %v", intstr.FromInt32(tc.probePort), spec.Spec.Containers[0].StartupProbe.HTTPGet.Port)
}

} else {
t.Errorf("getStaticPodSpecs didn't create spec for %s ", tc.staticPodName)
}
Expand Down

0 comments on commit 85384fe

Please sign in to comment.