Skip to content

Commit

Permalink
Remove orhapn UPDATE validation
Browse files Browse the repository at this point in the history
Longhorn 6246

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit committed Jul 7, 2023
1 parent a9d6289 commit 2c4081d
Showing 1 changed file with 0 additions and 26 deletions.
26 changes: 0 additions & 26 deletions webhook/resources/orphan/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package orphan

import (
"fmt"
"reflect"

admissionregv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -31,7 +30,6 @@ func (o *orphanValidator) Resource() admission.Resource {
ObjectType: &longhorn.Orphan{},
OperationTypes: []admissionregv1.OperationType{
admissionregv1.Create,
admissionregv1.Update,
},
}
}
Expand All @@ -53,30 +51,6 @@ func (o *orphanValidator) Create(request *admission.Request, newObj runtime.Obje
return nil
}

func (o *orphanValidator) Update(request *admission.Request, oldObj runtime.Object, newObj runtime.Object) error {
oldOrphan := oldObj.(*longhorn.Orphan)
newOrphan := newObj.(*longhorn.Orphan)

if err := checkOrphanParameters(newOrphan); err != nil {
return werror.NewInvalidError(err.Error(), "")
}

if !reflect.DeepEqual(oldOrphan.Spec, newOrphan.Spec) {
return werror.NewInvalidError(fmt.Sprintf("orphan %v spec fields are immutable", oldOrphan.Name), "")
}

return nil
}

func checkOrphanParameters(orphan *longhorn.Orphan) error {
switch {
case orphan.Spec.Type == longhorn.OrphanTypeReplica:
return checkOrphanForReplicaDirectory(orphan)
}

return werror.NewInvalidError(fmt.Sprintf("unknown orphan type %v for orphan %v", orphan.Spec.Type, orphan.Name), "")
}

func checkOrphanForReplicaDirectory(orphan *longhorn.Orphan) error {
params := []string{
longhorn.OrphanDataName,
Expand Down

0 comments on commit 2c4081d

Please sign in to comment.