Skip to content

Commit

Permalink
colocationprofile: support mutating pod labels and annotations with m…
Browse files Browse the repository at this point in the history
…apping (#1781)

Signed-off-by: saintube <[email protected]>
  • Loading branch information
saintube authored Dec 28, 2023
1 parent a404e7f commit 3b10d2a
Show file tree
Hide file tree
Showing 5 changed files with 487 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apis/config/v1alpha1/cluster_colocation_profile_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ type ClusterColocationProfileSpec struct {
// +optional
Annotations map[string]string `json:"annotations,omitempty"`

// LabelKeysMapping describes the labels that needs to inject into Pod.Labels with the same values.
// It sets the Pod.Labels[LabelsToLabels[k]] = Pod.Labels[k] for each key k.
// +optional
LabelKeysMapping map[string]string `json:"labelKeysMapping,omitempty"`

// AnnotationKeysMapping describes the annotations that needs to inject into Pod.Annotations with the same values.
// It sets the Pod.Annotations[AnnotationsToAnnotations[k]] = Pod.Annotations[k] for each key k.
// +optional
AnnotationKeysMapping map[string]string `json:"annotationKeysMapping,omitempty"`

// If specified, the pod will be dispatched by specified scheduler.
// +optional
SchedulerName string `json:"schedulerName,omitempty"`
Expand Down
14 changes: 14 additions & 0 deletions apis/config/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ spec:
spec:
description: ClusterColocationProfileSpec is a description of a ClusterColocationProfile.
properties:
annotationKeysMapping:
additionalProperties:
type: string
description: AnnotationKeysMapping describes the annotations that
needs to inject into Pod.Annotations with the same values. It sets
the Pod.Annotations[AnnotationsToAnnotations[k]] = Pod.Annotations[k]
for each key k.
type: object
annotations:
additionalProperties:
type: string
Expand All @@ -51,6 +59,13 @@ spec:
priority.
format: int32
type: integer
labelKeysMapping:
additionalProperties:
type: string
description: LabelKeysMapping describes the labels that needs to inject
into Pod.Labels with the same values. It sets the Pod.Labels[LabelsToLabels[k]]
= Pod.Labels[k] for each key k.
type: object
labels:
additionalProperties:
type: string
Expand Down
18 changes: 18 additions & 0 deletions pkg/webhook/pod/mutating/cluster_colocation_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,24 @@ func (h *PodMutatingHandler) doMutateByColocationProfile(ctx context.Context, po
}
}

if len(profile.Spec.LabelKeysMapping) > 0 {
if pod.Labels == nil {
pod.Labels = make(map[string]string)
}
for keyOld, keyNew := range profile.Spec.LabelKeysMapping {
pod.Labels[keyNew] = pod.Labels[keyOld]
}
}

if len(profile.Spec.AnnotationKeysMapping) > 0 {
if pod.Annotations == nil {
pod.Annotations = make(map[string]string)
}
for keyOld, keyNew := range profile.Spec.AnnotationKeysMapping {
pod.Annotations[keyNew] = pod.Annotations[keyOld]
}
}

if profile.Spec.SchedulerName != "" {
pod.Spec.SchedulerName = profile.Spec.SchedulerName
}
Expand Down
Loading

0 comments on commit 3b10d2a

Please sign in to comment.