Skip to content

Commit

Permalink
support old placeholder representations before v1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyulin0719 committed Mar 30, 2024
1 parent 2ca2372 commit eb274a4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ const DaemonSetType = "DaemonSet"
const PlaceholderContainerImage = "registry.k8s.io/pause:3.7"
const PlaceholderContainerName = "pause"
const PlaceholderPodRestartPolicy = "Never"

// Deprecated: should remove old placeholder flags in 1.7.0
const OldLabelPlaceholderFlag = "placeholder"

// Deprecated: should remove old placeholder flags in 1.7.0
const OldAnnotationOldPlaceholderFlag = DomainYuniKorn + "placeholder"
const AnnotationPlaceholderFlag = DomainYuniKornInternal + "placeholder"
const AnnotationTaskGroupName = DomainYuniKorn + "task-group-name"
const AnnotationTaskGroups = DomainYuniKorn + "task-groups"
Expand Down
13 changes: 13 additions & 0 deletions pkg/common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,18 @@ func GetPlaceholderFlagFromPodSpec(pod *v1.Pod) bool {
return v
}
}

if value := GetPodAnnotationValue(pod, constants.OldAnnotationOldPlaceholderFlag); value != "" { // nolint:staticcheck
if v, err := strconv.ParseBool(value); err == nil {
return v
}
}

if value := GetPodLabelValue(pod, constants.OldLabelPlaceholderFlag); value != "" { // nolint:staticcheck
if v, err := strconv.ParseBool(value); err == nil {
return v
}
}

return false
}
47 changes: 45 additions & 2 deletions pkg/common/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ func TestGetPlaceholderFlagFromPodSpec(t *testing.T) {
pod *v1.Pod
expectedPlaceholderFlag bool
}{
{"Pod with placeholder annotation", &v1.Pod{
{"Setting by annotation", &v1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
Expand All @@ -992,7 +992,50 @@ func TestGetPlaceholderFlagFromPodSpec(t *testing.T) {
Name: "pod-01",
UID: "UID-01",
Annotations: map[string]string{
constants.AnnotationPlaceholderFlag: constants.True,
constants.AnnotationPlaceholderFlag: "true",
},
},
}, true},
{"Setting by deprecated annotation", &v1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "pod-01",
UID: "UID-01",
Annotations: map[string]string{
constants.OldAnnotationOldPlaceholderFlag: "true", // nolint:staticcheck
},
},
}, true},
{"Setting by deprecated label", &v1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "pod-01",
UID: "UID-01",
Labels: map[string]string{
constants.OldLabelPlaceholderFlag: "true", // nolint:staticcheck
},
},
}, true},
{"Set new placeholder annotation and old placeholder label/annotation together, new annotation has higher priority", &v1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "pod-01",
UID: "UID-01",
Labels: map[string]string{
constants.OldLabelPlaceholderFlag: "false", // nolint:staticcheck
},
Annotations: map[string]string{
constants.AnnotationPlaceholderFlag: "true",
constants.OldAnnotationOldPlaceholderFlag: "false", // nolint:staticcheck
},
},
}, true},
Expand Down

0 comments on commit eb274a4

Please sign in to comment.