Skip to content

Commit

Permalink
Refuse to delete known settings
Browse files Browse the repository at this point in the history
Longhorn 4984

Signed-off-by: Eric Weber <eric.weber@suse.com>
  • Loading branch information
ejweber committed Sep 18, 2023
1 parent fd81656 commit 9c0caac
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions webhook/resources/setting/validator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package setting

import (
"fmt"

"k8s.io/apimachinery/pkg/runtime"

admissionregv1 "k8s.io/api/admissionregistration/v1"
Expand Down Expand Up @@ -32,6 +34,7 @@ func (v *settingValidator) Resource() admission.Resource {
OperationTypes: []admissionregv1.OperationType{
admissionregv1.Create,
admissionregv1.Update,
admissionregv1.Delete,
},
}
}
Expand All @@ -44,6 +47,16 @@ func (v *settingValidator) Update(request *admission.Request, oldObj runtime.Obj
return v.validateSetting(newObj)
}

func (v *settingValidator) Delete(request *admission.Request, oldObj runtime.Object) error {
setting := oldObj.(*longhorn.Setting)
if _, ok := types.GetSettingDefinition(types.SettingName(setting.Name)); ok {
return werror.NewInvalidError(fmt.Sprintf("setting %s can be modified but not deleted", setting.Name),
"metadata.name")
}
// If we reach this point, the setting is either from a previous version or is otherwise erroneous. Allow deletion.
return nil
}

func (v *settingValidator) validateSetting(newObj runtime.Object) error {
setting := newObj.(*longhorn.Setting)

Expand Down

0 comments on commit 9c0caac

Please sign in to comment.