Skip to content

Commit 9dec51e

Browse files
authored
Merge pull request kubernetes#93670 from wojtek-t/fix_readyz_sync_informer
Fix /readyz to contain informer-sync
2 parents 56c7602 + 5b4ab8f commit 9dec51e

File tree

3 files changed

+140
-5
lines changed

3 files changed

+140
-5
lines changed

staging/src/k8s.io/apiserver/pkg/server/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,11 +614,11 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
614614
if err != nil {
615615
return nil, err
616616
}
617-
// TODO: Once we get rid of /healthz consider changing this to post-start-hook.
618-
err = s.addReadyzChecks(healthz.NewInformerSyncHealthz(c.SharedInformerFactory))
619-
if err != nil {
620-
return nil, err
621-
}
617+
}
618+
// TODO: Once we get rid of /healthz consider changing this to post-start-hook.
619+
err := s.addReadyzChecks(healthz.NewInformerSyncHealthz(c.SharedInformerFactory))
620+
if err != nil {
621+
return nil, err
622622
}
623623
}
624624

test/e2e/apimachinery/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ go_library(
2121
"framework.go",
2222
"garbage_collector.go",
2323
"generated_clientset.go",
24+
"health_handlers.go",
2425
"namespace.go",
2526
"protocol.go",
2627
"resource_quota.go",
@@ -62,6 +63,7 @@ go_library(
6263
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
6364
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
6465
"//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
66+
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
6567
"//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
6668
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
6769
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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 apimachinery
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"strings"
23+
"time"
24+
25+
"k8s.io/apimachinery/pkg/util/sets"
26+
"k8s.io/apimachinery/pkg/util/wait"
27+
clientset "k8s.io/client-go/kubernetes"
28+
restclient "k8s.io/client-go/rest"
29+
"k8s.io/kubernetes/test/e2e/framework"
30+
31+
"github.com/onsi/ginkgo"
32+
)
33+
34+
var (
35+
requiredHealthzChecks = sets.NewString(
36+
"[+]ping ok",
37+
"[+]log ok",
38+
"[+]etcd ok",
39+
"[+]poststarthook/start-kube-apiserver-admission-initializer ok",
40+
"[+]poststarthook/generic-apiserver-start-informers ok",
41+
"[+]poststarthook/start-apiextensions-informers ok",
42+
"[+]poststarthook/start-apiextensions-controllers ok",
43+
"[+]poststarthook/crd-informer-synced ok",
44+
"[+]poststarthook/bootstrap-controller ok",
45+
"[+]poststarthook/scheduling/bootstrap-system-priority-classes ok",
46+
"[+]poststarthook/start-cluster-authentication-info-controller ok",
47+
"[+]poststarthook/start-kube-aggregator-informers ok",
48+
"[+]poststarthook/apiservice-registration-controller ok",
49+
"[+]poststarthook/apiservice-status-available-controller ok",
50+
"[+]poststarthook/kube-apiserver-autoregistration ok",
51+
"[+]autoregister-completion ok",
52+
"[+]poststarthook/apiservice-openapi-controller ok",
53+
)
54+
requiredLivezChecks = sets.NewString(
55+
"[+]ping ok",
56+
"[+]log ok",
57+
"[+]etcd ok",
58+
"[+]poststarthook/start-kube-apiserver-admission-initializer ok",
59+
"[+]poststarthook/generic-apiserver-start-informers ok",
60+
"[+]poststarthook/start-apiextensions-informers ok",
61+
"[+]poststarthook/start-apiextensions-controllers ok",
62+
"[+]poststarthook/crd-informer-synced ok",
63+
"[+]poststarthook/bootstrap-controller ok",
64+
"[+]poststarthook/scheduling/bootstrap-system-priority-classes ok",
65+
"[+]poststarthook/start-cluster-authentication-info-controller ok",
66+
"[+]poststarthook/start-kube-aggregator-informers ok",
67+
"[+]poststarthook/apiservice-registration-controller ok",
68+
"[+]poststarthook/apiservice-status-available-controller ok",
69+
"[+]poststarthook/kube-apiserver-autoregistration ok",
70+
"[+]autoregister-completion ok",
71+
"[+]poststarthook/apiservice-openapi-controller ok",
72+
)
73+
requiredReadyzChecks = sets.NewString(
74+
"[+]ping ok",
75+
"[+]log ok",
76+
"[+]etcd ok",
77+
"[+]informer-sync ok",
78+
"[+]poststarthook/start-kube-apiserver-admission-initializer ok",
79+
"[+]poststarthook/generic-apiserver-start-informers ok",
80+
"[+]poststarthook/start-apiextensions-informers ok",
81+
"[+]poststarthook/start-apiextensions-controllers ok",
82+
"[+]poststarthook/crd-informer-synced ok",
83+
"[+]poststarthook/bootstrap-controller ok",
84+
"[+]poststarthook/scheduling/bootstrap-system-priority-classes ok",
85+
"[+]poststarthook/start-cluster-authentication-info-controller ok",
86+
"[+]poststarthook/start-kube-aggregator-informers ok",
87+
"[+]poststarthook/apiservice-registration-controller ok",
88+
"[+]poststarthook/apiservice-status-available-controller ok",
89+
"[+]poststarthook/kube-apiserver-autoregistration ok",
90+
"[+]autoregister-completion ok",
91+
"[+]poststarthook/apiservice-openapi-controller ok",
92+
)
93+
)
94+
95+
func testPath(client clientset.Interface, path string, requiredChecks sets.String) error {
96+
var result restclient.Result
97+
err := wait.Poll(100*time.Millisecond, 30*time.Second, func() (bool, error) {
98+
result = client.CoreV1().RESTClient().Get().RequestURI(path).Do(context.TODO())
99+
status := 0
100+
result.StatusCode(&status)
101+
return status == 200, nil
102+
})
103+
if err != nil {
104+
return err
105+
}
106+
body, err := result.Raw()
107+
if err != nil {
108+
return err
109+
}
110+
checks := sets.NewString(strings.Split(string(body), "\n")...)
111+
if missing := requiredChecks.Difference(checks); missing.Len() > 0 {
112+
return fmt.Errorf("missing required %s checks: %v in: %s", path, missing, string(body))
113+
}
114+
return nil
115+
}
116+
117+
var _ = SIGDescribe("health handlers", func() {
118+
f := framework.NewDefaultFramework("health")
119+
120+
ginkgo.It("should contain necessary checks", func() {
121+
ginkgo.By("/health")
122+
err := testPath(f.ClientSet, "/healthz?verbose=1", requiredHealthzChecks)
123+
framework.ExpectNoError(err)
124+
125+
ginkgo.By("/livez")
126+
err = testPath(f.ClientSet, "/livez?verbose=1", requiredLivezChecks)
127+
framework.ExpectNoError(err)
128+
129+
ginkgo.By("/readyz")
130+
err = testPath(f.ClientSet, "/readyz?verbose=1", requiredReadyzChecks)
131+
framework.ExpectNoError(err)
132+
})
133+
})

0 commit comments

Comments
 (0)