|
| 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