-
Notifications
You must be signed in to change notification settings - Fork 77
/
machine_dependencies.go
90 lines (76 loc) · 3.19 KB
/
machine_dependencies.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package worker
import (
"context"
"github.com/gardener/gardener-extension-provider-azure/pkg/apis/azure/helper"
)
// DeployMachineDependencies implements genericactuator.WorkerDelegate.
// Deprecated: Do not use this func. It is deprecated in genericactuator.WorkerDelegate.
func (w *workerDelegate) DeployMachineDependencies(_ context.Context) error {
return nil
}
// CleanupMachineDependencies implements genericactuator.WorkerDelegate.
// Deprecated: Do not use this func. It is deprecated in genericactuator.WorkerDelegate.
func (w *workerDelegate) CleanupMachineDependencies(_ context.Context) error {
return nil
}
// PreReconcileHook implements genericactuator.WorkerDelegate.
func (w *workerDelegate) PreReconcileHook(ctx context.Context) error {
infrastructureStatus, err := w.decodeAzureInfrastructureStatus()
if err != nil {
return err
}
workerProviderStatus, err := w.decodeWorkerProviderStatus()
if err != nil {
return err
}
if helper.IsVmoRequired(infrastructureStatus) {
vmoDependencies, err := w.reconcileVmoDependencies(ctx, infrastructureStatus, workerProviderStatus)
workerProviderStatus.VmoDependencies = vmoDependencies
if err != nil {
return w.updateWorkerProviderStatusWithError(ctx, workerProviderStatus, err)
}
return w.updateWorkerProviderStatus(ctx, workerProviderStatus)
}
return nil
}
// PostReconcileHook implements genericactuator.WorkerDelegate.
func (w *workerDelegate) PostReconcileHook(ctx context.Context) error {
return w.cleanupMachineDependencies(ctx)
}
// PreDeleteHook implements genericactuator.WorkerDelegate.
func (w *workerDelegate) PreDeleteHook(_ context.Context) error {
return nil
}
// PostDeleteHook implements genericactuator.WorkerDelegate.
func (w *workerDelegate) PostDeleteHook(ctx context.Context) error {
return w.cleanupMachineDependencies(ctx)
}
// cleanupMachineDependencies cleans up machine dependencies.
//
// TODO(dkistner, kon-angelo): Currently both PostReconcileHook and PostDeleteHook funcs call cleanupMachineDependencies.
// cleanupMachineDependencies calls cleanupVmoDependencies. cleanupVmoDependencies handles the cases when the Worker is being
// deleted (logic applicable for PostDeleteHook) and is not being deleted (logic applicable for PostReconcileHook).
// Refactor this so that PostDeleteHook executes only the handling for Worker being deleted and PostReconcileHook executes only
// the handling for Worker reconciled (not being deleted).
func (w *workerDelegate) cleanupMachineDependencies(ctx context.Context) error {
infrastructureStatus, err := w.decodeAzureInfrastructureStatus()
if err != nil {
return err
}
workerProviderStatus, err := w.decodeWorkerProviderStatus()
if err != nil {
return err
}
if helper.IsVmoRequired(infrastructureStatus) {
vmoDependencies, err := w.cleanupVmoDependencies(ctx, infrastructureStatus, workerProviderStatus)
workerProviderStatus.VmoDependencies = vmoDependencies
if err != nil {
return w.updateWorkerProviderStatusWithError(ctx, workerProviderStatus, err)
}
return w.updateWorkerProviderStatus(ctx, workerProviderStatus)
}
return nil
}