Skip to content

Commit

Permalink
feat(pluginpresets) Avoid plugin preset deletion when prevent deletio…
Browse files Browse the repository at this point in the history
…n annotation is set (#804)
  • Loading branch information
gciezkowski-acc committed Dec 17, 2024
1 parent a2cc413 commit ea2d5b1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/admission/pluginpreset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ func ValidateUpdatePluginPreset(ctx context.Context, c client.Client, oldObj, cu
return nil, nil
}

func ValidateDeletePluginPreset(_ context.Context, _ client.Client, _ runtime.Object) (admission.Warnings, error) {
func ValidateDeletePluginPreset(_ context.Context, _ client.Client, obj runtime.Object) (admission.Warnings, error) {
pluginPreset, ok := obj.(*greenhousev1alpha1.PluginPreset)
if !ok {
return nil, nil
}

var allErrs field.ErrorList
if _, ok := pluginPreset.Annotations["greenhouse.sap/prevent-deletion"]; ok {
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("annotation").Child("greenhouse.sap/prevent-deletion"), pluginPreset.Annotations,
"Plugin preset has prevent deletion annotation"))
}

if len(allErrs) > 0 {
return nil, apierrors.NewInvalid(pluginPreset.GroupVersionKind().GroupKind(), pluginPreset.Name, allErrs)
}

return nil, nil
}

0 comments on commit ea2d5b1

Please sign in to comment.