/
seed_health.go
145 lines (126 loc) · 6.14 KB
/
seed_health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package care
import (
"context"
"time"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
gardencorev1beta1helper "github.com/gardener/gardener/pkg/apis/core/v1beta1/helper"
resourcesv1alpha1 "github.com/gardener/gardener/pkg/apis/resources/v1alpha1"
"github.com/gardener/gardener/pkg/features"
gardenletfeatures "github.com/gardener/gardener/pkg/gardenlet/features"
"github.com/gardener/gardener/pkg/operation/botanist/component/clusterautoscaler"
"github.com/gardener/gardener/pkg/operation/botanist/component/clusteridentity"
"github.com/gardener/gardener/pkg/operation/botanist/component/dependencywatchdog"
"github.com/gardener/gardener/pkg/operation/botanist/component/etcd"
"github.com/gardener/gardener/pkg/operation/botanist/component/hvpa"
"github.com/gardener/gardener/pkg/operation/botanist/component/istio"
"github.com/gardener/gardener/pkg/operation/botanist/component/networkpolicies"
"github.com/gardener/gardener/pkg/operation/botanist/component/nginxingress"
"github.com/gardener/gardener/pkg/operation/botanist/component/seedadmissioncontroller"
"github.com/gardener/gardener/pkg/operation/botanist/component/seedsystem"
"github.com/gardener/gardener/pkg/operation/botanist/component/vpa"
"github.com/gardener/gardener/pkg/operation/common"
kutil "github.com/gardener/gardener/pkg/utils/kubernetes"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var requiredManagedResourcesSeed = sets.NewString(
etcd.Druid,
seedadmissioncontroller.Name,
networkpolicies.ManagedResourceControlName,
clusteridentity.ManagedResourceControlName,
clusterautoscaler.ManagedResourceControlName,
seedsystem.ManagedResourceName,
vpa.ManagedResourceControlName,
)
// SeedHealth contains information needed to execute health checks for seed.
type SeedHealth struct {
seed *gardencorev1beta1.Seed
seedClient client.Client
}
// NewHealthForSeed creates a new Health instance with the given parameters.
func NewHealthForSeed(seed *gardencorev1beta1.Seed, seedClient client.Client) *SeedHealth {
return &SeedHealth{
seedClient: seedClient,
seed: seed,
}
}
// CheckSeed conducts the health checks on all the given conditions.
func (h *SeedHealth) CheckSeed(ctx context.Context,
conditions []gardencorev1beta1.Condition,
thresholdMappings map[gardencorev1beta1.ConditionType]time.Duration) []gardencorev1beta1.Condition {
var systemComponentsCondition gardencorev1beta1.Condition
for _, cond := range conditions {
switch cond.Type {
case gardencorev1beta1.SeedSystemComponentsHealthy:
systemComponentsCondition = cond
}
}
checker := NewHealthChecker(thresholdMappings, nil, nil, nil, nil)
newSystemComponentsCondition, err := h.checkSeedSystemComponents(ctx, checker, systemComponentsCondition)
return []gardencorev1beta1.Condition{NewConditionOrError(systemComponentsCondition, newSystemComponentsCondition, err)}
}
func (h *SeedHealth) checkSeedSystemComponents(
ctx context.Context,
checker *HealthChecker,
condition gardencorev1beta1.Condition,
) (*gardencorev1beta1.Condition,
error) {
managedResources := requiredManagedResourcesSeed.List()
if gardenletfeatures.FeatureGate.Enabled(features.ManagedIstio) {
managedResources = append(managedResources, istio.ManagedResourceControlName)
}
if gardenletfeatures.FeatureGate.Enabled(features.HVPA) {
managedResources = append(managedResources, hvpa.ManagedResourceName)
}
if gardencorev1beta1helper.SeedSettingDependencyWatchdogEndpointEnabled(h.seed.Spec.Settings) {
managedResources = append(managedResources, dependencywatchdog.ManagedResourceDependencyWatchdogEndpoint)
}
if gardencorev1beta1helper.SeedSettingDependencyWatchdogProbeEnabled(h.seed.Spec.Settings) {
managedResources = append(managedResources, dependencywatchdog.ManagedResourceDependencyWatchdogProbe)
}
if gardencorev1beta1helper.SeedUsesNginxIngressController(h.seed) {
managedResources = append(managedResources, nginxingress.ManagedResourceName)
}
for _, name := range managedResources {
namespace := v1beta1constants.GardenNamespace
if name == istio.ManagedResourceControlName {
namespace = common.IstioNamespace
}
mr := &resourcesv1alpha1.ManagedResource{}
if err := h.seedClient.Get(ctx, kutil.Key(namespace, name), mr); err != nil {
if apierrors.IsNotFound(err) {
exitCondition := checker.FailedCondition(condition, "ResourceNotFound", err.Error())
return &exitCondition, nil
}
return nil, err
}
if exitCondition := checkManagedResourceForSeed(checker, condition, mr); exitCondition != nil {
return exitCondition, nil
}
}
c := gardencorev1beta1helper.UpdatedCondition(condition, gardencorev1beta1.ConditionTrue, "SystemComponentsRunning", "All system components are healthy.")
return &c, nil
}
func checkManagedResourceForSeed(checker *HealthChecker, condition gardencorev1beta1.Condition, managedResource *resourcesv1alpha1.ManagedResource) *gardencorev1beta1.Condition {
conditionsToCheck := map[gardencorev1beta1.ConditionType]func(status gardencorev1beta1.ConditionStatus) bool{
resourcesv1alpha1.ResourcesApplied: defaultSuccessfulCheck(),
resourcesv1alpha1.ResourcesHealthy: defaultSuccessfulCheck(),
resourcesv1alpha1.ResourcesProgressing: resourcesNotProgressingCheck(),
}
return checker.checkManagedResourceConditions(condition, managedResource, conditionsToCheck)
}