-
Notifications
You must be signed in to change notification settings - Fork 11
/
actuator.go
157 lines (126 loc) · 4.18 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package worker
import (
"context"
"github.com/gardener/gardener/extensions/pkg/util"
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/metal-stack/gardener-extension-provider-metal/pkg/apis/config"
apismetal "github.com/metal-stack/gardener-extension-provider-metal/pkg/apis/metal"
"github.com/metal-stack/gardener-extension-provider-metal/pkg/imagevector"
"github.com/metal-stack/gardener-extension-provider-metal/pkg/metal"
metalv1alpha1 "github.com/metal-stack/machine-controller-manager-provider-metal/pkg/provider/migration/legacy-api/machine/v1alpha1"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
gardener "github.com/gardener/gardener/pkg/client/kubernetes"
"github.com/go-logr/logr"
"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/log"
)
type delegateFactory struct {
logger logr.Logger
restConfig *rest.Config
client client.Client
scheme *runtime.Scheme
decoder runtime.Decoder
machineImageMapping []config.MachineImage
}
// NewActuator creates a new Actuator that updates the status of the handled WorkerPoolConfigs.
func NewActuator(machineImages []config.MachineImage) worker.Actuator {
delegateFactory := &delegateFactory{
logger: log.Log.WithName("worker-actuator"),
machineImageMapping: machineImages,
}
return genericactuator.NewActuator(
log.Log.WithName("metal-worker-actuator"),
delegateFactory,
metal.MachineControllerManagerName,
mcmChart,
mcmShootChart,
imagevector.ImageVector(),
extensionscontroller.ChartRendererFactoryFunc(util.NewChartRendererForShoot),
)
}
func (d *delegateFactory) InjectScheme(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(metalv1alpha1.SchemeGroupVersion,
&metalv1alpha1.MetalMachineClass{},
&metalv1alpha1.MetalMachineClassList{},
)
d.scheme = scheme
d.decoder = serializer.NewCodecFactory(scheme).UniversalDecoder()
return nil
}
func (d *delegateFactory) InjectConfig(restConfig *rest.Config) error {
d.restConfig = restConfig
return nil
}
func (d *delegateFactory) InjectClient(client client.Client) error {
d.client = client
return nil
}
func (d *delegateFactory) WorkerDelegate(ctx 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.logger,
d.client,
d.scheme,
d.decoder,
d.machineImageMapping,
seedChartApplier,
serverVersion.GitVersion,
worker,
cluster,
), nil
}
type workerDelegate struct {
logger logr.Logger
client client.Client
scheme *runtime.Scheme
decoder runtime.Decoder
machineImageMapping []config.MachineImage
seedChartApplier gardener.ChartApplier
serverVersion string
cluster *extensionscontroller.Cluster
worker *extensionsv1alpha1.Worker
machineClasses []map[string]interface{}
machineDeployments worker.MachineDeployments
machineImages []apismetal.MachineImage
}
// NewWorkerDelegate creates a new context for a worker reconciliation.
func NewWorkerDelegate(
logger logr.Logger,
client client.Client,
scheme *runtime.Scheme,
decoder runtime.Decoder,
machineImageMapping []config.MachineImage,
seedChartApplier gardener.ChartApplier,
serverVersion string,
worker *extensionsv1alpha1.Worker,
cluster *extensionscontroller.Cluster,
) genericactuator.WorkerDelegate {
return &workerDelegate{
logger: logger,
client: client,
scheme: scheme,
decoder: decoder,
machineImageMapping: machineImageMapping,
seedChartApplier: seedChartApplier,
serverVersion: serverVersion,
cluster: cluster,
worker: worker,
}
}