Generate work permanent id in webhook
Signed-off-by: whitewindmills <jayfantasyhjh@gmail.com>
This commit is contained in:
parent
4ccffccc70
commit
93a04cbf0d
|
@ -20,7 +20,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
@ -72,9 +71,6 @@ func CreateOrUpdateWork(client client.Client, workMeta metav1.ObjectMeta, resour
|
||||||
runtimeObject.Spec = work.Spec
|
runtimeObject.Spec = work.Spec
|
||||||
runtimeObject.Labels = util.DedupeAndMergeLabels(runtimeObject.Labels, work.Labels)
|
runtimeObject.Labels = util.DedupeAndMergeLabels(runtimeObject.Labels, work.Labels)
|
||||||
runtimeObject.Annotations = util.DedupeAndMergeAnnotations(runtimeObject.Annotations, work.Annotations)
|
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 nil
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -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)
|
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
|
var manifests []workv1alpha1.Manifest
|
||||||
|
|
||||||
for _, manifest := range work.Spec.Workload.Manifests {
|
for _, manifest := range work.Spec.Workload.Manifests {
|
||||||
|
@ -86,10 +90,6 @@ func (a *MutatingAdmission) Handle(_ context.Context, req admission.Request) adm
|
||||||
return admission.Errored(http.StatusInternalServerError, err)
|
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)
|
return admission.PatchResponseFromRaw(req.Object.Raw, marshaledBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue