-
Notifications
You must be signed in to change notification settings - Fork 99
/
actuator.go
131 lines (109 loc) · 3.64 KB
/
actuator.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package worker
import (
"context"
extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
"github.com/gardener/gardener/extensions/pkg/controller/worker"
"github.com/gardener/gardener/extensions/pkg/controller/worker/genericactuator"
"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"
gardener "github.com/gardener/gardener/pkg/client/kubernetes"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/manager"
api "github.com/gardener/gardener-extension-provider-aws/pkg/apis/aws"
"github.com/gardener/gardener-extension-provider-aws/pkg/apis/aws/helper"
)
type delegateFactory struct {
gardenReader client.Reader
seedClient client.Client
decoder runtime.Decoder
restConfig *rest.Config
scheme *runtime.Scheme
}
// NewActuator creates a new Actuator that updates the status of the handled WorkerPoolConfigs.
func NewActuator(mgr manager.Manager, gardenCluster cluster.Cluster) worker.Actuator {
workerDelegate := &delegateFactory{
gardenReader: gardenCluster.GetAPIReader(),
seedClient: mgr.GetClient(),
decoder: serializer.NewCodecFactory(mgr.GetScheme(), serializer.EnableStrict).UniversalDecoder(),
restConfig: mgr.GetConfig(),
scheme: mgr.GetScheme(),
}
return genericactuator.NewActuator(
mgr,
gardenCluster,
workerDelegate,
func(err error) []gardencorev1beta1.ErrorCode {
return util.DetermineErrorCodes(err, helper.KnownCodes)
},
)
}
func (d *delegateFactory) WorkerDelegate(_ context.Context, worker *extensionsv1alpha1.Worker, cluster *extensionscontroller.Cluster) (genericactuator.WorkerDelegate, error) {
clientset, err := kubernetes.NewForConfig(d.restConfig)
if err != nil {
return nil, err
}
serverVersion, err := clientset.Discovery().ServerVersion()
if err != nil {
return nil, err
}
seedChartApplier, err := gardener.NewChartApplierForConfig(d.restConfig)
if err != nil {
return nil, err
}
return NewWorkerDelegate(
d.seedClient,
d.decoder,
d.scheme,
seedChartApplier,
serverVersion.GitVersion,
worker,
cluster,
)
}
type workerDelegate struct {
client client.Client
decoder runtime.Decoder
scheme *runtime.Scheme
seedChartApplier gardener.ChartApplier
serverVersion string
cloudProfileConfig *api.CloudProfileConfig
cluster *extensionscontroller.Cluster
worker *extensionsv1alpha1.Worker
machineClasses []map[string]interface{}
machineDeployments worker.MachineDeployments
machineImages []api.MachineImage
}
// NewWorkerDelegate creates a new context for a worker reconciliation.
func NewWorkerDelegate(
client client.Client,
decoder runtime.Decoder,
scheme *runtime.Scheme,
seedChartApplier gardener.ChartApplier,
serverVersion string,
worker *extensionsv1alpha1.Worker,
cluster *extensionscontroller.Cluster,
) (genericactuator.WorkerDelegate, error) {
config, err := helper.CloudProfileConfigFromCluster(cluster)
if err != nil {
return nil, err
}
return &workerDelegate{
client: client,
decoder: decoder,
scheme: scheme,
seedChartApplier: seedChartApplier,
serverVersion: serverVersion,
cloudProfileConfig: config,
cluster: cluster,
worker: worker,
}, nil
}