Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit fcdc3e3

Browse files
committed
feat: add webhook support for update / delete
1 parent 39ae8e9 commit fcdc3e3

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

pkg/apiserver/registry/account/rest.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ func (r *accountREST) Create(ctx context.Context, obj runtime.Object, createVali
157157
if !ok {
158158
return nil, fmt.Errorf("not an account: %#v", obj)
159159
}
160+
if createValidation != nil {
161+
err := createValidation(ctx, account)
162+
if err != nil {
163+
return nil, err
164+
}
165+
}
166+
160167
configAccount, err := ConvertTenancyAccount(account)
161168
if err != nil {
162169
return nil, err
@@ -189,6 +196,19 @@ func (r *accountREST) Update(ctx context.Context, name string, objInfo rest.Upda
189196
return nil, false, fmt.Errorf("New object is not an account")
190197
}
191198

199+
if createValidation != nil {
200+
err := createValidation(ctx, newAccount)
201+
if err != nil {
202+
return nil, false, err
203+
}
204+
}
205+
if updateValidation != nil {
206+
err := updateValidation(ctx, newAccount, oldObj)
207+
if err != nil {
208+
return nil, false, err
209+
}
210+
}
211+
192212
newConfigAccount, err := ConvertTenancyAccount(newAccount)
193213
if err != nil {
194214
return nil, false, err
@@ -213,6 +233,17 @@ func (r *accountREST) Delete(ctx context.Context, name string, deleteValidation
213233
return nil, false, err
214234
}
215235

236+
account, err := ConvertConfigAccount(configAccount)
237+
if err != nil {
238+
return nil, false, err
239+
}
240+
if deleteValidation != nil {
241+
err = deleteValidation(ctx, account)
242+
if err != nil {
243+
return nil, false, err
244+
}
245+
}
246+
216247
// we have to use a background context here, because it might
217248
// be possible that the user is cancelling the request and we want
218249
// to fully delete the account and its children
@@ -223,7 +254,7 @@ func (r *accountREST) Delete(ctx context.Context, name string, deleteValidation
223254
return nil, false, err
224255
}
225256

226-
account, err := ConvertConfigAccount(configAccount)
257+
account, err = ConvertConfigAccount(configAccount)
227258
if err != nil {
228259
return nil, false, err
229260
}

pkg/apiserver/registry/space/rest.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,19 @@ func (r *spaceStorage) Update(ctx context.Context, name string, objInfo rest.Upd
440440
return nil, false, fmt.Errorf("new object is not a space")
441441
}
442442

443+
if createValidation != nil {
444+
err = createValidation(ctx, newSpace)
445+
if err != nil {
446+
return nil, false, err
447+
}
448+
}
449+
if updateValidation != nil {
450+
err = updateValidation(ctx, newSpace, oldObj)
451+
if err != nil {
452+
return nil, false, err
453+
}
454+
}
455+
443456
namespace := ConvertSpace(newSpace)
444457
err = r.client.Update(ctx, namespace, &client.UpdateOptions{
445458
Raw: options,
@@ -472,6 +485,13 @@ func (r *spaceStorage) Delete(ctx context.Context, name string, deleteValidation
472485
return nil, false, err
473486
}
474487

488+
if deleteValidation != nil {
489+
err = deleteValidation(ctx, ConvertNamespace(namespace))
490+
if err != nil {
491+
return nil, false, err
492+
}
493+
}
494+
475495
// we have to use a background context here, because it might
476496
// be possible that the user is cancelling the request and we want
477497
// to fully delete the namespace or otherwise there might be left overs

0 commit comments

Comments
 (0)