@@ -41,7 +41,6 @@ import (
41
41
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct"
42
42
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/directbase"
43
43
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/registry"
44
- "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/resourceoverrides"
45
44
)
46
45
47
46
func init () {
@@ -69,20 +68,6 @@ func (m *backupPlanModel) AdapterForObject(ctx context.Context, reader client.Re
69
68
return nil , err
70
69
}
71
70
72
- // normalize reference fields
73
- if obj .Spec .ClusterRef != nil {
74
- if _ , err := obj .Spec .ClusterRef .NormalizedExternal (ctx , reader , obj .GetNamespace ()); err != nil {
75
- return nil , err
76
- }
77
- }
78
- if obj .Spec .BackupConfig != nil &&
79
- obj .Spec .BackupConfig .EncryptionKey != nil &&
80
- obj .Spec .BackupConfig .EncryptionKey .KMSKeyRef != nil {
81
- if _ , err := refs .ResolveKMSCryptoKeyRef (ctx , reader , obj , obj .Spec .BackupConfig .EncryptionKey .KMSKeyRef ); err != nil {
82
- return nil , err
83
- }
84
- }
85
-
86
71
// Get gkebackup GCP client
87
72
gcpClient , err := newGCPClient (ctx , & m .config )
88
73
if err != nil {
@@ -96,6 +81,7 @@ func (m *backupPlanModel) AdapterForObject(ctx context.Context, reader client.Re
96
81
gcpClient : client ,
97
82
id : id ,
98
83
desired : obj ,
84
+ reader : reader ,
99
85
}, nil
100
86
}
101
87
@@ -105,11 +91,11 @@ func (m *backupPlanModel) AdapterForURL(ctx context.Context, url string) (direct
105
91
}
106
92
107
93
type backupPlanAdapter struct {
108
- gcpClient * gcp.BackupForGKEClient
109
- id * krm.BackupPlanIdentity
110
- desired * krm.GKEBackupBackupPlan
111
- actual * pb.BackupPlan
112
- resourceOverrides resourceoverrides. ResourceOverrides
94
+ gcpClient * gcp.BackupForGKEClient
95
+ id * krm.BackupPlanIdentity
96
+ desired * krm.GKEBackupBackupPlan
97
+ actual * pb.BackupPlan
98
+ reader client. Reader
113
99
}
114
100
115
101
var _ directbase.Adapter = & backupPlanAdapter {}
@@ -134,8 +120,12 @@ func (a *backupPlanAdapter) Find(ctx context.Context) (bool, error) {
134
120
func (a * backupPlanAdapter ) Create (ctx context.Context , createOp * directbase.CreateOperation ) error {
135
121
log := klog .FromContext (ctx )
136
122
log .V (2 ).Info ("creating gkebackup backupplan" , "name" , a .id )
137
- mapCtx := & direct.MapContext {}
138
123
124
+ if err := a .normalizeReferenceFields (ctx ); err != nil {
125
+ return err
126
+ }
127
+
128
+ mapCtx := & direct.MapContext {}
139
129
desired := a .desired .DeepCopy ()
140
130
resource := GKEBackupBackupPlanSpec_ToProto (mapCtx , & desired .Spec )
141
131
if mapCtx .Err () != nil {
@@ -169,8 +159,12 @@ func (a *backupPlanAdapter) Create(ctx context.Context, createOp *directbase.Cre
169
159
func (a * backupPlanAdapter ) Update (ctx context.Context , updateOp * directbase.UpdateOperation ) error {
170
160
log := klog .FromContext (ctx )
171
161
log .V (2 ).Info ("updating gkebackup backupplan" , "name" , a .id )
172
- mapCtx := & direct.MapContext {}
173
162
163
+ if err := a .normalizeReferenceFields (ctx ); err != nil {
164
+ return err
165
+ }
166
+
167
+ mapCtx := & direct.MapContext {}
174
168
desired := a .desired .DeepCopy ()
175
169
resource := GKEBackupBackupPlanSpec_ToProto (mapCtx , & desired .Spec )
176
170
if mapCtx .Err () != nil {
@@ -330,3 +324,22 @@ func backupConfigsEqual(a, b *gkebackuppb.BackupPlan_BackupConfig) bool {
330
324
331
325
return true
332
326
}
327
+
328
+ func (a * backupPlanAdapter ) normalizeReferenceFields (ctx context.Context ) error {
329
+ obj := a .desired
330
+
331
+ if obj .Spec .ClusterRef != nil {
332
+ if _ , err := obj .Spec .ClusterRef .NormalizedExternal (ctx , a .reader , obj .GetNamespace ()); err != nil {
333
+ return err
334
+ }
335
+ }
336
+ if obj .Spec .BackupConfig != nil &&
337
+ obj .Spec .BackupConfig .EncryptionKey != nil &&
338
+ obj .Spec .BackupConfig .EncryptionKey .KMSKeyRef != nil {
339
+ if _ , err := refs .ResolveKMSCryptoKeyRef (ctx , a .reader , obj , obj .Spec .BackupConfig .EncryptionKey .KMSKeyRef ); err != nil {
340
+ return err
341
+ }
342
+ }
343
+
344
+ return nil
345
+ }
0 commit comments