Merge pull request #120583 from ritazh/kms-livezchecks

kms: remove livez check
This commit is contained in:
Kubernetes Prow Robot
2023-09-12 12:18:12 -07:00
committed by GitHub
4 changed files with 104 additions and 30 deletions

View File

@@ -332,18 +332,23 @@ func (s *EtcdOptions) maybeApplyResourceTransformers(c *server.Config) (err erro
c.ResourceTransformers = dynamicTransformers
if !s.SkipHealthEndpoints {
c.AddHealthChecks(dynamicTransformers)
addHealthChecksWithoutLivez(c, dynamicTransformers)
}
} else {
c.ResourceTransformers = encryptionconfig.StaticTransformers(encryptionConfiguration.Transformers)
if !s.SkipHealthEndpoints {
c.AddHealthChecks(encryptionConfiguration.HealthChecks...)
addHealthChecksWithoutLivez(c, encryptionConfiguration.HealthChecks...)
}
}
return nil
}
func addHealthChecksWithoutLivez(c *server.Config, healthChecks ...healthz.HealthChecker) {
c.HealthzChecks = append(c.HealthzChecks, healthChecks...)
c.ReadyzChecks = append(c.ReadyzChecks, healthChecks...)
}
func (s *EtcdOptions) addEtcdHealthEndpoint(c *server.Config) error {
healthCheck, err := storagefactory.CreateHealthCheck(s.StorageConfig, c.DrainedNotify())
if err != nil {

View File

@@ -234,63 +234,85 @@ func TestKMSHealthzEndpoint(t *testing.T) {
testCases := []struct {
name string
encryptionConfigPath string
wantChecks []string
wantHealthzChecks []string
wantReadyzChecks []string
wantLivezChecks []string
skipHealth bool
reload bool
}{
{
name: "no kms-provider, expect no kms healthz check",
name: "no kms-provider, expect no kms healthz check, no kms livez check",
encryptionConfigPath: "testdata/encryption-configs/no-kms-provider.yaml",
wantChecks: []string{"etcd"},
wantHealthzChecks: []string{"etcd"},
wantReadyzChecks: []string{"etcd", "etcd-readiness"},
wantLivezChecks: []string{"etcd"},
},
{
name: "no kms-provider+reload, expect single kms healthz check",
name: "no kms-provider+reload, expect single kms healthz check, no kms livez check",
encryptionConfigPath: "testdata/encryption-configs/no-kms-provider.yaml",
reload: true,
wantChecks: []string{"etcd", "kms-providers"},
wantHealthzChecks: []string{"etcd", "kms-providers"},
wantReadyzChecks: []string{"etcd", "kms-providers", "etcd-readiness"},
wantLivezChecks: []string{"etcd"},
},
{
name: "single kms-provider, expect single kms healthz check",
name: "single kms-provider, expect single kms healthz check, no kms livez check",
encryptionConfigPath: "testdata/encryption-configs/single-kms-provider.yaml",
wantChecks: []string{"etcd", "kms-provider-0"},
wantHealthzChecks: []string{"etcd", "kms-provider-0"},
wantReadyzChecks: []string{"etcd", "kms-provider-0", "etcd-readiness"},
wantLivezChecks: []string{"etcd"},
},
{
name: "two kms-providers, expect two kms healthz checks",
name: "two kms-providers, expect two kms healthz checks, no kms livez check",
encryptionConfigPath: "testdata/encryption-configs/multiple-kms-providers.yaml",
wantChecks: []string{"etcd", "kms-provider-0", "kms-provider-1"},
wantHealthzChecks: []string{"etcd", "kms-provider-0", "kms-provider-1"},
wantReadyzChecks: []string{"etcd", "kms-provider-0", "kms-provider-1", "etcd-readiness"},
wantLivezChecks: []string{"etcd"},
},
{
name: "two kms-providers+reload, expect single kms healthz check",
name: "two kms-providers+reload, expect single kms healthz check, no kms livez check",
encryptionConfigPath: "testdata/encryption-configs/multiple-kms-providers.yaml",
reload: true,
wantChecks: []string{"etcd", "kms-providers"},
wantHealthzChecks: []string{"etcd", "kms-providers"},
wantReadyzChecks: []string{"etcd", "kms-providers", "etcd-readiness"},
wantLivezChecks: []string{"etcd"},
},
{
name: "kms v1+v2, expect three kms healthz checks",
name: "kms v1+v2, expect three kms healthz checks, no kms livez check",
encryptionConfigPath: "testdata/encryption-configs/multiple-kms-providers-with-v2.yaml",
wantChecks: []string{"etcd", "kms-provider-0", "kms-provider-1", "kms-provider-2"},
wantHealthzChecks: []string{"etcd", "kms-provider-0", "kms-provider-1", "kms-provider-2"},
wantReadyzChecks: []string{"etcd", "kms-provider-0", "kms-provider-1", "kms-provider-2", "etcd-readiness"},
wantLivezChecks: []string{"etcd"},
},
{
name: "kms v1+v2+reload, expect single kms healthz check",
name: "kms v1+v2+reload, expect single kms healthz check, no kms livez check",
encryptionConfigPath: "testdata/encryption-configs/multiple-kms-providers-with-v2.yaml",
reload: true,
wantChecks: []string{"etcd", "kms-providers"},
wantHealthzChecks: []string{"etcd", "kms-providers"},
wantReadyzChecks: []string{"etcd", "kms-providers", "etcd-readiness"},
wantLivezChecks: []string{"etcd"},
},
{
name: "multiple kms v2, expect single kms healthz check",
name: "multiple kms v2, expect single kms healthz check, no kms livez check",
encryptionConfigPath: "testdata/encryption-configs/multiple-kms-v2-providers.yaml",
wantChecks: []string{"etcd", "kms-providers"},
wantHealthzChecks: []string{"etcd", "kms-providers"},
wantReadyzChecks: []string{"etcd", "kms-providers", "etcd-readiness"},
wantLivezChecks: []string{"etcd"},
},
{
name: "multiple kms v2+reload, expect single kms healthz check",
name: "multiple kms v2+reload, expect single kms healthz check, no kms livez check",
encryptionConfigPath: "testdata/encryption-configs/multiple-kms-v2-providers.yaml",
reload: true,
wantChecks: []string{"etcd", "kms-providers"},
wantHealthzChecks: []string{"etcd", "kms-providers"},
wantReadyzChecks: []string{"etcd", "kms-providers", "etcd-readiness"},
wantLivezChecks: []string{"etcd"},
},
{
name: "two kms-providers with skip, expect zero kms healthz checks",
name: "two kms-providers with skip, expect zero kms healthz checks, no kms livez check",
encryptionConfigPath: "testdata/encryption-configs/multiple-kms-providers.yaml",
wantChecks: nil,
wantHealthzChecks: nil,
wantReadyzChecks: nil,
wantLivezChecks: nil,
skipHealth: true,
},
}
@@ -310,7 +332,9 @@ func TestKMSHealthzEndpoint(t *testing.T) {
t.Fatalf("Failed to add healthz error: %v", err)
}
healthChecksAreEqual(t, tc.wantChecks, serverConfig.HealthzChecks)
healthChecksAreEqual(t, tc.wantHealthzChecks, serverConfig.HealthzChecks, "healthz")
healthChecksAreEqual(t, tc.wantReadyzChecks, serverConfig.ReadyzChecks, "readyz")
healthChecksAreEqual(t, tc.wantLivezChecks, serverConfig.LivezChecks, "livez")
})
}
}
@@ -320,17 +344,20 @@ func TestReadinessCheck(t *testing.T) {
name string
wantReadyzChecks []string
wantHealthzChecks []string
wantLivezChecks []string
skipHealth bool
}{
{
name: "Readyz should have etcd-readiness check",
wantReadyzChecks: []string{"etcd", "etcd-readiness"},
wantHealthzChecks: []string{"etcd"},
wantLivezChecks: []string{"etcd"},
},
{
name: "skip health, Readyz should not have etcd-readiness check",
wantReadyzChecks: nil,
wantHealthzChecks: nil,
wantLivezChecks: nil,
skipHealth: true,
},
}
@@ -346,13 +373,14 @@ func TestReadinessCheck(t *testing.T) {
t.Fatalf("Failed to add healthz error: %v", err)
}
healthChecksAreEqual(t, tc.wantReadyzChecks, serverConfig.ReadyzChecks)
healthChecksAreEqual(t, tc.wantHealthzChecks, serverConfig.HealthzChecks)
healthChecksAreEqual(t, tc.wantReadyzChecks, serverConfig.ReadyzChecks, "readyz")
healthChecksAreEqual(t, tc.wantHealthzChecks, serverConfig.HealthzChecks, "healthz")
healthChecksAreEqual(t, tc.wantLivezChecks, serverConfig.LivezChecks, "livez")
})
}
}
func healthChecksAreEqual(t *testing.T, want []string, healthChecks []healthz.HealthChecker) {
func healthChecksAreEqual(t *testing.T, want []string, healthChecks []healthz.HealthChecker, checkerType string) {
t.Helper()
wantSet := sets.NewString(want...)
@@ -365,6 +393,6 @@ func healthChecksAreEqual(t *testing.T, want []string, healthChecks []healthz.He
gotSet.Delete("log", "ping") // not relevant for our tests
if !wantSet.Equal(gotSet) {
t.Errorf("healthz checks are not equal, missing=%q, extra=%q", wantSet.Difference(gotSet).List(), gotSet.Difference(wantSet).List())
t.Errorf("%s checks are not equal, missing=%q, extra=%q", checkerType, wantSet.Difference(gotSet).List(), gotSet.Difference(wantSet).List())
}
}