-
Notifications
You must be signed in to change notification settings - Fork 79
/
add.go
116 lines (107 loc) · 4.58 KB
/
add.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package healthcheck
import (
"context"
"time"
healthcheckconfig "github.com/gardener/gardener/extensions/pkg/apis/config"
extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
"github.com/gardener/gardener/extensions/pkg/controller/healthcheck"
"github.com/gardener/gardener/extensions/pkg/controller/healthcheck/general"
"github.com/gardener/gardener/extensions/pkg/controller/healthcheck/worker"
extensionspredicate "github.com/gardener/gardener/extensions/pkg/predicate"
"github.com/gardener/gardener/extensions/pkg/util"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"github.com/gardener/gardener-extension-provider-azure/pkg/apis/azure/helper"
"github.com/gardener/gardener-extension-provider-azure/pkg/azure"
)
var (
defaultSyncPeriod = time.Second * 30
// DefaultAddOptions are the default DefaultAddArgs for AddToManager.
DefaultAddOptions = healthcheck.DefaultAddArgs{
HealthCheckConfig: healthcheckconfig.HealthCheckConfig{
SyncPeriod: metav1.Duration{Duration: defaultSyncPeriod},
ShootRESTOptions: &healthcheckconfig.RESTOptions{
QPS: ptr.To[float32](100),
Burst: ptr.To(130),
},
},
}
)
// RegisterHealthChecks registers health checks for each extension resource
// HealthChecks are grouped by extension (e.g worker), extension.type (e.g azure) and Health Check Type (e.g SystemComponentsHealthy)
func RegisterHealthChecks(ctx context.Context, mgr manager.Manager, opts healthcheck.DefaultAddArgs) error {
remedyControllerPreCheckFunc := func(_ context.Context, _ client.Client, _ client.Object, cluster *extensionscontroller.Cluster) bool {
return cluster.Shoot.Annotations[azure.DisableRemedyControllerAnnotation] != "true"
}
if err := healthcheck.DefaultRegistration(
ctx,
azure.Type,
extensionsv1alpha1.SchemeGroupVersion.WithKind(extensionsv1alpha1.ControlPlaneResource),
func() client.ObjectList { return &extensionsv1alpha1.ControlPlaneList{} },
func() extensionsv1alpha1.Object { return &extensionsv1alpha1.ControlPlane{} },
mgr,
opts,
[]predicate.Predicate{extensionspredicate.HasPurpose(extensionsv1alpha1.Normal)},
[]healthcheck.ConditionTypeToHealthCheck{
{
ConditionType: string(gardencorev1beta1.ShootControlPlaneHealthy),
HealthCheck: general.NewSeedDeploymentHealthChecker(azure.CloudControllerManagerName),
},
{
ConditionType: string(gardencorev1beta1.ShootControlPlaneHealthy),
HealthCheck: general.NewSeedDeploymentHealthChecker(azure.CSIControllerDiskName),
},
{
ConditionType: string(gardencorev1beta1.ShootControlPlaneHealthy),
HealthCheck: general.NewSeedDeploymentHealthChecker(azure.CSIControllerFileName),
},
{
ConditionType: string(gardencorev1beta1.ShootControlPlaneHealthy),
HealthCheck: general.NewSeedDeploymentHealthChecker(azure.RemedyControllerName),
PreCheckFunc: remedyControllerPreCheckFunc,
},
{
ConditionType: string(gardencorev1beta1.ShootControlPlaneHealthy),
HealthCheck: general.NewSeedDeploymentHealthChecker(azure.CSISnapshotControllerName),
},
{
ConditionType: string(gardencorev1beta1.ShootControlPlaneHealthy),
HealthCheck: general.NewSeedDeploymentHealthChecker(azure.CSISnapshotValidationName),
},
},
sets.Set[gardencorev1beta1.ConditionType]{},
); err != nil {
return err
}
return healthcheck.DefaultRegistration(
ctx,
azure.Type,
extensionsv1alpha1.SchemeGroupVersion.WithKind(extensionsv1alpha1.WorkerResource),
func() client.ObjectList { return &extensionsv1alpha1.WorkerList{} },
func() extensionsv1alpha1.Object { return &extensionsv1alpha1.Worker{} },
mgr,
opts,
nil,
[]healthcheck.ConditionTypeToHealthCheck{{
ConditionType: string(gardencorev1beta1.ShootEveryNodeReady),
HealthCheck: worker.NewNodesChecker(),
ErrorCodeCheckFunc: func(err error) []gardencorev1beta1.ErrorCode {
return util.DetermineErrorCodes(err, helper.KnownCodes)
},
}},
sets.New(gardencorev1beta1.ShootControlPlaneHealthy),
)
}
// AddToManager adds a controller with the default Options.
func AddToManager(ctx context.Context, mgr manager.Manager) error {
return RegisterHealthChecks(ctx, mgr, DefaultAddOptions)
}