Skip to content

Commit

Permalink
Merge pull request #20 from vmware-tanzu/remove-update-mutation
Browse files Browse the repository at this point in the history
Remove update mutations
  • Loading branch information
tomkennedy513 authored Nov 16, 2022
2 parents 4119039 + 151b77f commit 9284758
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions pkg/certinjectionwebhook/admission_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (ac *admissionController) Admit(ctx context.Context, request *admissionv1.A
}

switch request.Operation {
case admissionv1.Create, admissionv1.Update:
case admissionv1.Create:
default:
logger.Infof("Unhandled webhook operation, letting it through %v", request.Operation)
return &admissionv1.AdmissionResponse{Allowed: true}
Expand Down Expand Up @@ -142,35 +142,19 @@ func (ac *admissionController) Admit(ctx context.Context, request *admissionv1.A

func (ac *admissionController) mutate(ctx context.Context, req *admissionv1.AdmissionRequest) ([]byte, error) {
newBytes := req.Object.Raw
oldBytes := req.OldObject.Raw

var oldObj, newObj corev1.Pod

var newObj corev1.Pod
if len(newBytes) != 0 {
newDecoder := json.NewDecoder(bytes.NewBuffer(newBytes))
if err := newDecoder.Decode(&newObj); err != nil {
return nil, fmt.Errorf("cannot decode incoming new object: %v", err)
}
}
if len(oldBytes) != 0 {
oldDecoder := json.NewDecoder(bytes.NewBuffer(oldBytes))
if err := oldDecoder.Decode(&oldObj); err != nil {
return nil, fmt.Errorf("cannot decode incoming old object: %v", err)
}
}
var patches duck.JSONPatch

var patches duck.JSONPatch
var err error

if &oldObj != nil {
if req.SubResource == "" {
ctx = apis.WithinUpdate(ctx, oldObj)
} else {
ctx = apis.WithinSubResourceUpdate(ctx, oldObj, req.SubResource)
}
} else {
ctx = apis.WithinCreate(ctx)
}
ctx = apis.WithinCreate(ctx)
ctx = apis.WithUserInfo(ctx, &req.UserInfo)

if patches, err = ac.setBuildServicePodDefaults(ctx, patches, newObj); err != nil {
Expand Down

0 comments on commit 9284758

Please sign in to comment.