Skip to content

Commit

Permalink
Generate work permanent id in webhook
Browse files Browse the repository at this point in the history
Signed-off-by: whitewindmills <jayfantasyhjh@gmail.com>
  • Loading branch information
whitewindmills committed May 10, 2024
1 parent 4ccffcc commit 4df0bf1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 0 additions & 3 deletions pkg/util/helper/work.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ func CreateOrUpdateWork(client client.Client, workMeta metav1.ObjectMeta, resour
runtimeObject.Spec = work.Spec
runtimeObject.Labels = util.DedupeAndMergeLabels(runtimeObject.Labels, work.Labels)
runtimeObject.Annotations = util.DedupeAndMergeAnnotations(runtimeObject.Annotations, work.Annotations)
if util.GetLabelValue(runtimeObject.Labels, workv1alpha2.WorkPermanentIDLabel) == "" {
runtimeObject.Labels = util.DedupeAndMergeLabels(runtimeObject.Labels, map[string]string{workv1alpha2.WorkPermanentIDLabel: uuid.New().String()})
}
return nil
})
return err
Expand Down
8 changes: 4 additions & 4 deletions pkg/webhook/work/mutating.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (a *MutatingAdmission) Handle(_ context.Context, req admission.Request) adm
}
klog.V(2).Infof("Mutating the work(%s/%s) for request: %s", work.Namespace, work.Name, req.Operation)

if util.GetLabelValue(work.Labels, workv1alpha2.WorkPermanentIDLabel) == "" {
util.MergeLabel(work, workv1alpha2.WorkPermanentIDLabel, uuid.New().String())
}

var manifests []workv1alpha1.Manifest

for _, manifest := range work.Spec.Workload.Manifests {
Expand Down Expand Up @@ -86,10 +90,6 @@ func (a *MutatingAdmission) Handle(_ context.Context, req admission.Request) adm
return admission.Errored(http.StatusInternalServerError, err)
}

if util.GetLabelValue(work.Labels, workv1alpha2.WorkPermanentIDLabel) == "" {
util.MergeLabel(work, workv1alpha2.WorkPermanentIDLabel, uuid.New().String())
}

return admission.PatchResponseFromRaw(req.Object.Raw, marshaledBytes)
}

Expand Down

0 comments on commit 4df0bf1

Please sign in to comment.