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

Commit

Permalink
Merge pull request #123 from FabianKramm/master
Browse files Browse the repository at this point in the history
feat: add webhook support for update / delete
  • Loading branch information
FabianKramm authored May 7, 2021
2 parents d813152 + fcdc3e3 commit 664add3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
33 changes: 32 additions & 1 deletion pkg/apiserver/registry/account/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ func (r *accountREST) Create(ctx context.Context, obj runtime.Object, createVali
if !ok {
return nil, fmt.Errorf("not an account: %#v", obj)
}
if createValidation != nil {
err := createValidation(ctx, account)
if err != nil {
return nil, err
}
}

configAccount, err := ConvertTenancyAccount(account)
if err != nil {
return nil, err
Expand Down Expand Up @@ -189,6 +196,19 @@ func (r *accountREST) Update(ctx context.Context, name string, objInfo rest.Upda
return nil, false, fmt.Errorf("New object is not an account")
}

if createValidation != nil {
err := createValidation(ctx, newAccount)
if err != nil {
return nil, false, err
}
}
if updateValidation != nil {
err := updateValidation(ctx, newAccount, oldObj)
if err != nil {
return nil, false, err
}
}

newConfigAccount, err := ConvertTenancyAccount(newAccount)
if err != nil {
return nil, false, err
Expand All @@ -213,6 +233,17 @@ func (r *accountREST) Delete(ctx context.Context, name string, deleteValidation
return nil, false, err
}

account, err := ConvertConfigAccount(configAccount)
if err != nil {
return nil, false, err
}
if deleteValidation != nil {
err = deleteValidation(ctx, account)
if err != nil {
return nil, false, err
}
}

// we have to use a background context here, because it might
// be possible that the user is cancelling the request and we want
// to fully delete the account and its children
Expand All @@ -223,7 +254,7 @@ func (r *accountREST) Delete(ctx context.Context, name string, deleteValidation
return nil, false, err
}

account, err := ConvertConfigAccount(configAccount)
account, err = ConvertConfigAccount(configAccount)
if err != nil {
return nil, false, err
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/apiserver/registry/space/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,19 @@ func (r *spaceStorage) Update(ctx context.Context, name string, objInfo rest.Upd
return nil, false, fmt.Errorf("new object is not a space")
}

if createValidation != nil {
err = createValidation(ctx, newSpace)
if err != nil {
return nil, false, err
}
}
if updateValidation != nil {
err = updateValidation(ctx, newSpace, oldObj)
if err != nil {
return nil, false, err
}
}

namespace := ConvertSpace(newSpace)
err = r.client.Update(ctx, namespace, &client.UpdateOptions{
Raw: options,
Expand Down Expand Up @@ -472,6 +485,13 @@ func (r *spaceStorage) Delete(ctx context.Context, name string, deleteValidation
return nil, false, err
}

if deleteValidation != nil {
err = deleteValidation(ctx, ConvertNamespace(namespace))
if err != nil {
return nil, false, err
}
}

// we have to use a background context here, because it might
// be possible that the user is cancelling the request and we want
// to fully delete the namespace or otherwise there might be left overs
Expand Down

0 comments on commit 664add3

Please sign in to comment.