-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathopenstackversion_controller.go
More file actions
534 lines (478 loc) · 22.5 KB
/
openstackversion_controller.go
File metadata and controls
534 lines (478 loc) · 22.5 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
/*
Copyright 2023.
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 core
import (
"context"
"fmt"
"os"
"strings"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"github.com/go-logr/logr"
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/api/core/v1beta1"
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/api/dataplane/v1beta1"
"github.com/openstack-k8s-operators/openstack-operator/internal/openstack"
)
var (
envContainerImages (map[string]*string)
envAvailableVersion string
)
// SetupVersionDefaults -
func SetupVersionDefaults() {
localVars := make(map[string]*string)
for _, name := range os.Environ() {
envArr := strings.Split(name, "=")
if envArr[0] == "OPENSTACK_RELEASE_VERSION" {
envAvailableVersion = envArr[1]
}
if strings.HasPrefix(envArr[0], "RELATED_IMAGE_") {
localVars[envArr[0]] = &envArr[1]
}
// we have some TEST_ env vars which specify images that aren't released downstream
if strings.HasPrefix(envArr[0], "TEST_") {
localVars[envArr[0]] = &envArr[1]
}
}
envAvailableVersion = corev1beta1.GetOpenStackReleaseVersion(os.Environ())
envContainerImages = localVars
}
// OpenStackVersionReconciler reconciles a OpenStackVersion object
type OpenStackVersionReconciler struct {
client.Client
Kclient kubernetes.Interface
Scheme *runtime.Scheme
}
// GetLogger returns a logger object with a prefix of "controller.name" and additional controller context fields
func (r *OpenStackVersionReconciler) GetLogger(ctx context.Context) logr.Logger {
return log.FromContext(ctx).WithName("Controllers").WithName("OpenStackVersion")
}
// +kubebuilder:rbac:groups=core.openstack.org,resources=openstackversions,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core.openstack.org,resources=openstackversions/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=core.openstack.org,resources=openstackversions/finalizers,verbs=update;patch
// +kubebuilder:rbac:groups=core.openstack.org,resources=openstackcontrolplanes,verbs=get;list;watch
// +kubebuilder:rbac:groups=dataplane.openstack.org,resources=openstackdataplanenodesets,verbs=get;list;watch
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.1/pkg/reconcile
func (r *OpenStackVersionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) {
Log := r.GetLogger(ctx)
Log.Info("Reconciling OpenStackVersion")
// Fetch the instance
instance := &corev1beta1.OpenStackVersion{}
err := r.Get(ctx, req.NamespacedName, instance)
if err != nil {
if k8s_errors.IsNotFound(err) {
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected.
// For additional cleanup logic use finalizers. Return and don't requeue.
return ctrl.Result{}, nil
}
// Error reading the object - requeue the request.
return ctrl.Result{}, err
}
versionHelper, err := helper.NewHelper(
instance,
r.Client,
r.Kclient,
r.Scheme,
Log,
)
if err != nil {
Log.Error(err, "unable to create helper")
return ctrl.Result{}, err
}
isNewInstance := instance.Status.Conditions == nil
if isNewInstance {
instance.Status.Conditions = condition.Conditions{}
}
// Save a copy of the condtions so that we can restore the LastTransitionTime
// when a condition's state doesn't change.
savedConditions := instance.Status.Conditions.DeepCopy()
// Always patch the instance status when exiting this function so we can persist any changes.
defer func() {
// Don't update the status, if reconciler Panics
if r := recover(); r != nil {
Log.Info(fmt.Sprintf("panic during reconcile %v\n", r))
panic(r)
}
// update the Ready condition based on the sub conditions
if instance.Status.Conditions.AllSubConditionIsTrue() {
instance.Status.Conditions.MarkTrue(
condition.ReadyCondition, condition.ReadyMessage)
} else {
// something is not ready so reset the Ready condition
instance.Status.Conditions.MarkUnknown(
condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage)
// and recalculate it based on the state of the rest of the conditions
instance.Status.Conditions.Set(
instance.Status.Conditions.Mirror(condition.ReadyCondition))
}
condition.RestoreLastTransitionTimes(
&instance.Status.Conditions, savedConditions)
err := versionHelper.PatchInstance(ctx, instance)
if err != nil {
_err = err
return
}
}()
// greenfield deployment
cl := condition.CreateList(
condition.UnknownCondition(corev1beta1.OpenStackVersionInitialized, condition.InitReason, string(corev1beta1.OpenStackVersionInitializedInitMessage)),
)
// no minor update conditions unless we have a deployed version
if instance.Status.DeployedVersion != nil && instance.Spec.TargetVersion != *instance.Status.DeployedVersion {
cl = append(cl,
*condition.UnknownCondition(corev1beta1.OpenStackVersionMinorUpdateOVNControlplane, condition.InitReason, string(corev1beta1.OpenStackVersionMinorUpdateInitMessage)),
*condition.UnknownCondition(corev1beta1.OpenStackVersionMinorUpdateOVNDataplane, condition.InitReason, string(corev1beta1.OpenStackVersionMinorUpdateInitMessage)),
*condition.UnknownCondition(corev1beta1.OpenStackVersionMinorUpdateRabbitMQ, condition.InitReason, string(corev1beta1.OpenStackVersionMinorUpdateInitMessage)),
*condition.UnknownCondition(corev1beta1.OpenStackVersionMinorUpdateMariaDB, condition.InitReason, string(corev1beta1.OpenStackVersionMinorUpdateInitMessage)),
*condition.UnknownCondition(corev1beta1.OpenStackVersionMinorUpdateMemcached, condition.InitReason, string(corev1beta1.OpenStackVersionMinorUpdateInitMessage)),
*condition.UnknownCondition(corev1beta1.OpenStackVersionMinorUpdateKeystone, condition.InitReason, string(corev1beta1.OpenStackVersionMinorUpdateInitMessage)),
*condition.UnknownCondition(corev1beta1.OpenStackVersionMinorUpdateControlplane, condition.InitReason, string(corev1beta1.OpenStackVersionMinorUpdateInitMessage)),
*condition.UnknownCondition(corev1beta1.OpenStackVersionMinorUpdateDataplane, condition.InitReason, string(corev1beta1.OpenStackVersionMinorUpdateInitMessage)),
)
}
instance.Status.Conditions.Init(&cl)
instance.Status.ObservedGeneration = instance.Generation
// If we're not deleting this and the service object doesn't have our finalizer, add it.
if instance.DeletionTimestamp.IsZero() && isNewInstance {
controllerutil.AddFinalizer(instance, versionHelper.GetFinalizer())
// Register overall status immediately to have an early feedback e.g. in the cli
return ctrl.Result{}, nil
}
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionInitialized,
condition.RequestedReason,
condition.SeverityInfo,
corev1beta1.OpenStackVersionInitializedReadyRunningMessage))
instance.Status.AvailableVersion = &envAvailableVersion
defaults := openstack.InitializeOpenStackVersionImageDefaults(ctx, envContainerImages)
if instance.Status.ContainerImageVersionDefaults == nil {
instance.Status.ContainerImageVersionDefaults = make(map[string]*corev1beta1.ContainerDefaults)
}
// store the defaults for the currently available version
instance.Status.ContainerImageVersionDefaults[envAvailableVersion] = defaults
// calculate the container images for the target version
Log.Info("Target version: ", "targetVersion", instance.Spec.TargetVersion)
val, ok := instance.Status.ContainerImageVersionDefaults[instance.Spec.TargetVersion]
if !ok {
Log.Info("Target version not found in defaults", "targetVersion", instance.Spec.TargetVersion)
return ctrl.Result{}, nil
}
instance.Status.ContainerImages = openstack.GetContainerImages(val, *instance)
// Track CustomContainerImages for this version
if instance.Status.TrackedCustomImages == nil {
instance.Status.TrackedCustomImages = make(map[string]corev1beta1.CustomContainerImages)
}
instance.Status.TrackedCustomImages[instance.Spec.TargetVersion] = instance.Spec.CustomContainerImages
// initialize service defaults
serviceDefaults := openstack.InitializeOpenStackVersionServiceDefaults(ctx)
if instance.Status.AvailableServiceDefaults == nil {
instance.Status.AvailableServiceDefaults = make(map[string]*corev1beta1.ServiceDefaults)
}
// store the service defaults for the currently available version
instance.Status.AvailableServiceDefaults[envAvailableVersion] = serviceDefaults
serviceDefVal, ok := instance.Status.AvailableServiceDefaults[instance.Spec.TargetVersion]
if !ok {
instance.Status.ServiceDefaults = corev1beta1.ServiceDefaults{}
} else {
instance.Status.ServiceDefaults = *serviceDefVal
}
instance.Status.Conditions.MarkTrue(
corev1beta1.OpenStackVersionInitialized,
corev1beta1.OpenStackVersionInitializedReadyMessage)
Log.Info("OpenStackVersion Initialized")
// lookup the current Controlplane object
controlPlane := &corev1beta1.OpenStackControlPlane{}
err = r.Get(ctx, client.ObjectKey{
Namespace: instance.Namespace,
Name: instance.Name,
}, controlPlane)
if err != nil {
if k8s_errors.IsNotFound(err) {
Log.Info("Controlplane not found:", "instance name", instance.Name)
return ctrl.Result{}, nil
}
return ctrl.Result{}, err
}
// lookup nodesets
dataplaneNodesets, err := openstack.GetDataplaneNodesets(ctx, controlPlane, versionHelper)
if err != nil {
Log.Error(err, "Failed to get dataplane nodesets")
return ctrl.Result{}, err
}
// greenfield deployment
if controlPlane.Status.DeployedVersion == nil && !openstack.DataplaneNodesetsDeployedVersionIsSet(dataplaneNodesets) {
Log.Info("Waiting for controlplane and dataplane nodesets to be deployed.")
return ctrl.Result{}, nil
}
// minor update in progress
if instance.Status.DeployedVersion != nil && instance.Spec.TargetVersion != *instance.Status.DeployedVersion {
// Only check OVN when enabled to avoid hanging on a removed condition
if controlPlane.Spec.Ovn.Enabled {
if !openstack.OVNControllerImageMatch(ctx, controlPlane, instance) ||
!controlPlane.Status.Conditions.IsTrue(corev1beta1.OpenStackControlPlaneOVNReadyCondition) {
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionMinorUpdateOVNControlplane,
condition.RequestedReason,
condition.SeverityInfo,
corev1beta1.OpenStackVersionMinorUpdateReadyRunningMessage))
Log.Info("Minor update for OVN Controlplane in progress")
return ctrl.Result{}, nil
}
}
instance.Status.Conditions.MarkTrue(
corev1beta1.OpenStackVersionMinorUpdateOVNControlplane,
corev1beta1.OpenStackVersionMinorUpdateReadyMessage)
// minor update for Dataplane OVN
// Only check OVN when enabled to avoid hanging on a removed condition
if controlPlane.Spec.Ovn.Enabled {
if !openstack.DataplaneNodesetsOVNControllerImagesMatch(instance, dataplaneNodesets) {
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionMinorUpdateOVNDataplane,
condition.RequestedReason,
condition.SeverityInfo,
corev1beta1.OpenStackVersionMinorUpdateReadyRunningMessage))
Log.Info("Waiting on OVN Dataplane updates to complete")
return ctrl.Result{}, nil
}
// When the OVN controller image is the same between the deployed
// version and the target version, the image comparison above always
// passes because the nodeset already has the matching image from
// the previous update. In this case we need additional checks to
// confirm the OVN dataplane deployment for this update cycle has
// actually completed.
//
// We use the saved condition state (from before Init reset) to
// track whether we have observed a running OVN deployment during
// this update cycle:
// - If we see a running OVN deployment now: set condition False
// (RequestedReason) to record that we observed one
// - If no running OVN deployment AND the previous condition was
// False/RequestedReason: the deployment we saw previously has
// completed → proceed (fall through to set True)
// - If no running OVN deployment AND the previous condition was
// NOT False/RequestedReason (e.g. still Unknown from Init):
// we haven't seen a deployment yet → keep waiting
//
// When the image differs between versions, the image match alone
// is sufficient proof that a deployment updated it, since the
// nodeset's ContainerImages are only set on successful completion.
deployedDefaults, hasDeployedDefaults := instance.Status.ContainerImageVersionDefaults[*instance.Status.DeployedVersion]
if hasDeployedDefaults &&
deployedDefaults.OvnControllerImage != nil &&
instance.Status.ContainerImages.OvnControllerImage != nil &&
*deployedDefaults.OvnControllerImage == *instance.Status.ContainerImages.OvnControllerImage {
ovnDeploymentRunning, err := openstack.IsDataplaneDeploymentRunningForContainerImage(
ctx, versionHelper, instance.Namespace, dataplaneNodesets, "OvnControllerImage")
if err != nil {
return ctrl.Result{}, err
}
if ovnDeploymentRunning {
// OVN deployment is actively running — record this in
// the condition so we can detect its completion later.
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionMinorUpdateOVNDataplane,
condition.RequestedReason,
condition.SeverityInfo,
corev1beta1.OpenStackVersionMinorUpdateReadyRunningMessage))
Log.Info("Waiting on OVN Dataplane deployment to complete (OVN image unchanged between versions)")
return ctrl.Result{}, nil
}
// No OVN deployment running. Check the saved condition state
// from the previous reconciliation to determine if we ever
// observed one running during this update cycle.
prevOvnDataplaneCond := savedConditions.Get(corev1beta1.OpenStackVersionMinorUpdateOVNDataplane)
if prevOvnDataplaneCond == nil ||
prevOvnDataplaneCond.Reason != condition.RequestedReason {
// We have never observed a running OVN deployment in
// this update cycle — the deployment has not been
// created yet. Keep waiting.
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionMinorUpdateOVNDataplane,
condition.InitReason,
condition.SeverityInfo,
corev1beta1.OpenStackVersionMinorUpdateReadyRunningMessage))
Log.Info("Waiting for OVN Dataplane deployment to be created (OVN image unchanged between versions)")
return ctrl.Result{}, nil
}
// Previously saw a running OVN deployment (condition was
// False/RequestedReason), now no OVN deployment is running
// → the deployment has completed. Fall through to set True.
Log.Info("OVN Dataplane deployment completed (OVN image unchanged between versions)")
}
}
instance.Status.Conditions.MarkTrue(
corev1beta1.OpenStackVersionMinorUpdateOVNDataplane,
corev1beta1.OpenStackVersionMinorUpdateReadyMessage)
// minor update for RabbitMQ
if !openstack.RabbitmqImageMatch(ctx, controlPlane, instance) ||
!controlPlane.Status.Conditions.IsTrue(corev1beta1.OpenStackControlPlaneRabbitMQReadyCondition) {
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionMinorUpdateRabbitMQ,
condition.RequestedReason,
condition.SeverityInfo,
corev1beta1.OpenStackVersionMinorUpdateReadyRunningMessage))
Log.Info("Minor update for RabbitMQ in progress")
return ctrl.Result{}, nil
}
instance.Status.Conditions.MarkTrue(
corev1beta1.OpenStackVersionMinorUpdateRabbitMQ,
corev1beta1.OpenStackVersionMinorUpdateReadyMessage)
// minor update for MariaDB
if !openstack.GaleraImageMatch(ctx, controlPlane, instance) ||
!controlPlane.Status.Conditions.IsTrue(corev1beta1.OpenStackControlPlaneMariaDBReadyCondition) {
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionMinorUpdateMariaDB,
condition.RequestedReason,
condition.SeverityInfo,
corev1beta1.OpenStackVersionMinorUpdateReadyRunningMessage))
Log.Info("Minor update for MariaDB in progress")
return ctrl.Result{}, nil
}
instance.Status.Conditions.MarkTrue(
corev1beta1.OpenStackVersionMinorUpdateMariaDB,
corev1beta1.OpenStackVersionMinorUpdateReadyMessage)
// minor update for Memcached
if !openstack.MemcachedImageMatch(ctx, controlPlane, instance) ||
!controlPlane.Status.Conditions.IsTrue(corev1beta1.OpenStackControlPlaneMemcachedReadyCondition) {
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionMinorUpdateMemcached,
condition.RequestedReason,
condition.SeverityInfo,
corev1beta1.OpenStackVersionMinorUpdateReadyRunningMessage))
Log.Info("Minor update for Memcached in progress")
return ctrl.Result{}, nil
}
instance.Status.Conditions.MarkTrue(
corev1beta1.OpenStackVersionMinorUpdateMemcached,
corev1beta1.OpenStackVersionMinorUpdateReadyMessage)
// minor update for Keystone API
if !openstack.KeystoneImageMatch(ctx, controlPlane, instance) ||
!controlPlane.Status.Conditions.IsTrue(corev1beta1.OpenStackControlPlaneKeystoneAPIReadyCondition) {
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionMinorUpdateKeystone,
condition.RequestedReason,
condition.SeverityInfo,
corev1beta1.OpenStackVersionMinorUpdateReadyRunningMessage))
Log.Info("Minor update for Keystone in progress")
return ctrl.Result{}, nil
}
instance.Status.Conditions.MarkTrue(
corev1beta1.OpenStackVersionMinorUpdateKeystone,
corev1beta1.OpenStackVersionMinorUpdateReadyMessage)
// minor update for Controlplane in progress
if !controlPlane.IsReady() {
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionMinorUpdateControlplane,
condition.RequestedReason,
condition.SeverityInfo,
corev1beta1.OpenStackVersionMinorUpdateReadyRunningMessage))
Log.Info("Minor update for Controlplane in progress")
return ctrl.Result{}, nil
}
// ctlplane is ready, lets make sure all images match newly deployed versions
ctlplaneImagesMatch, badMatches := openstack.ControlplaneContainerImageMatch(ctx, controlPlane, instance)
if !ctlplaneImagesMatch {
// Since we need the images to match and we cannot proceed without it,
// we treat this as a warning because it means that reconciliation will not be able to continue.
errMsgBadMatches := "Controlplane images do not match the target version for the following services: " + strings.Join(badMatches, ", ")
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionMinorUpdateControlplane,
condition.ErrorReason,
condition.SeverityWarning,
corev1beta1.OpenStackVersionMinorUpdateReadyErrorMessage,
errMsgBadMatches))
return ctrl.Result{}, nil
}
instance.Status.Conditions.MarkTrue(
corev1beta1.OpenStackVersionMinorUpdateControlplane,
corev1beta1.OpenStackVersionMinorUpdateReadyMessage)
Log.Info("Minor update for ControlPlane completed")
if !openstack.DataplaneNodesetsDeployed(instance, dataplaneNodesets) {
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackVersionMinorUpdateDataplane,
condition.RequestedReason,
condition.SeverityInfo,
corev1beta1.OpenStackVersionMinorUpdateReadyRunningMessage))
Log.Info("Waiting on Dataplane update to complete")
return ctrl.Result{}, nil
}
instance.Status.Conditions.MarkTrue(
corev1beta1.OpenStackVersionMinorUpdateDataplane,
corev1beta1.OpenStackVersionMinorUpdateReadyMessage)
}
if controlPlane.IsReady() {
Log.Info("Setting DeployedVersion")
instance.Status.DeployedVersion = &instance.Spec.TargetVersion
// Remove skip-custom-images-validation annotation after minor update completion
if instance.Annotations != nil {
if _, exists := instance.Annotations["core.openstack.org/skip-custom-images-validation"]; exists {
delete(instance.Annotations, "core.openstack.org/skip-custom-images-validation")
Log.Info("Removed skip-custom-images-validation annotation after minor update completion")
}
}
}
if instance.Status.DeployedVersion != nil &&
*instance.Status.AvailableVersion != *instance.Status.DeployedVersion {
instance.Status.Conditions.Set(condition.TrueCondition(
corev1beta1.OpenStackVersionMinorUpdateAvailable,
corev1beta1.OpenStackVersionMinorUpdateAvailableMessage))
} else {
instance.Status.Conditions.Remove(corev1beta1.OpenStackVersionMinorUpdateAvailable)
}
return ctrl.Result{}, nil
}
// SetupWithManager sets up the controller with the Manager.
func (r *OpenStackVersionReconciler) SetupWithManager(mgr ctrl.Manager) error {
versionFunc := handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request {
Log := r.GetLogger(ctx)
versionList := &corev1beta1.OpenStackVersionList{}
result := []reconcile.Request{}
listOpts := []client.ListOption{
client.InNamespace(o.GetNamespace()),
}
if err := r.List(ctx, versionList, listOpts...); err != nil {
Log.Error(err, "Unable to retrieve OpenStackVersion")
return nil
}
for _, i := range versionList.Items {
name := client.ObjectKey{
Namespace: o.GetNamespace(),
Name: i.Name,
}
result = append(result, reconcile.Request{NamespacedName: name})
}
if len(result) > 0 {
Log.Info("Reconcile request for:", "result", result)
return result
}
return nil
})
return ctrl.NewControllerManagedBy(mgr).
Watches(&corev1beta1.OpenStackControlPlane{}, versionFunc).
Watches(&dataplanev1.OpenStackDataPlaneNodeSet{}, versionFunc).
For(&corev1beta1.OpenStackVersion{}).
Complete(r)
}