This is an automated email from the ASF dual-hosted git repository.
manirajv06 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git
The following commit(s) were added to refs/heads/master by this push:
new 2f801310 [YUNIKORN-3279] Remove code: clean up utils.go (#1027)
2f801310 is described below
commit 2f801310de021ee1333d9ab3afe8d88d9304b2c1
Author: Manikandan R <[email protected]>
AuthorDate: Tue May 12 15:23:30 2026 +0530
[YUNIKORN-3279] Remove code: clean up utils.go (#1027)
Closes: #1027
Signed-off-by: Manikandan R <[email protected]>
---
pkg/cache/metadata_test.go | 10 ---------
pkg/common/utils/utils.go | 30 +-------------------------
pkg/common/utils/utils_test.go | 48 ++++++++++++++++++------------------------
3 files changed, 21 insertions(+), 67 deletions(-)
diff --git a/pkg/cache/metadata_test.go b/pkg/cache/metadata_test.go
index b5d45e05..09fc90b9 100644
--- a/pkg/cache/metadata_test.go
+++ b/pkg/cache/metadata_test.go
@@ -27,7 +27,6 @@ import (
apis "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/apache/yunikorn-k8shim/pkg/common/constants"
- "github.com/apache/yunikorn-k8shim/pkg/common/utils"
"github.com/apache/yunikorn-k8shim/pkg/conf"
"github.com/apache/yunikorn-scheduler-interface/lib/go/common"
)
@@ -107,9 +106,7 @@ func TestGetTaskMetadata(t *testing.T) {
}
func TestGetAppMetadata(t *testing.T) { //nolint:funlen
- defer utils.SetPluginMode(false)
defer func() { conf.GetSchedulerConf().GenerateUniqueAppIds = false }()
- utils.SetPluginMode(false)
conf.GetSchedulerConf().GenerateUniqueAppIds = false
pod := v1.Pod{
@@ -290,23 +287,16 @@ func TestGetAppMetadata(t *testing.T) { //nolint:funlen
Phase: v1.PodPending,
},
}
-
- utils.SetPluginMode(false)
app, ok = getAppMetadata(&pod)
conf.GetSchedulerConf().GenerateUniqueAppIds = true
assert.Equal(t, ok, true)
assert.Equal(t, app.ApplicationID, "yunikorn-app-namespace-01-autogen")
- utils.SetPluginMode(false)
conf.GetSchedulerConf().GenerateUniqueAppIds = true
app, ok = getAppMetadata(&pod)
assert.Equal(t, ok, true)
assert.Equal(t, app.ApplicationID, "app-namespace-01-UID-POD-00001")
- utils.SetPluginMode(true)
- app, ok = getAppMetadata(&pod)
- assert.Equal(t, ok, false)
-
// case: invalid annotation task groups
pod = v1.Pod{
TypeMeta: apis.TypeMeta{
diff --git a/pkg/common/utils/utils.go b/pkg/common/utils/utils.go
index 748d4e2e..0432b07a 100644
--- a/pkg/common/utils/utils.go
+++ b/pkg/common/utils/utils.go
@@ -44,20 +44,11 @@ import (
const userInfoKey = siCommon.DomainYuniKorn + "user.info"
const uniqueAutogenSuffix = "-uniqueautogen"
-var pluginMode bool
var (
// ErrorTimeout returned if waiting for a condition times out
ErrorTimeout = errors.New("timeout waiting for condition")
)
-func SetPluginMode(value bool) {
- pluginMode = value
-}
-
-func IsPluginMode() bool {
- return pluginMode
-}
-
func Convert2Pod(obj interface{}) (*v1.Pod, error) {
pod, ok := obj.(*v1.Pod)
if !ok {
@@ -146,27 +137,13 @@ func GenerateApplicationID(namespace string,
generateUniqueAppIds bool, podUID s
}
// GetApplicationIDFromPod returns the Application for a Pod. If a Pod is
marked as schedulable by YuniKorn but is
-// missing an ApplicationID, one will be generated here (if YuniKorn is
running in standard mode) or an empty string
-// will be returned (if YuniKorn is running in plugin mode).
-// If an Application ID is returned, the Pod is managed by YuniKorn.
Otherwise, it is managed by an external scheduler.
+// missing an ApplicationID, one will be generated here
func GetApplicationIDFromPod(pod *v1.Pod) string {
// SchedulerName needs to match
if strings.Compare(pod.Spec.SchedulerName, constants.SchedulerName) !=
0 {
return ""
}
- // If pod was tagged with ignore-application and plugin mode is active,
return
- if pluginMode {
- if value := GetPodAnnotationValue(pod,
constants.AnnotationIgnoreApplication); value != "" {
- ignore, err := strconv.ParseBool(value)
- if err != nil {
- log.Log(log.ShimUtils).Warn("Failed to parse
annotation "+constants.AnnotationIgnoreApplication, zap.Error(err))
- } else if ignore {
- return ""
- }
- }
- }
-
// Application ID can be defined in multiple places
// The application ID is determined by the following order.
// 1. Label: constants.CanonicalLabelApplicationID
@@ -193,11 +170,6 @@ func GetApplicationIDFromPod(pod *v1.Pod) string {
}
}
- // If plugin mode, interpret missing Application ID as a non-YuniKorn
pod
- if pluginMode && appID == "" {
- return ""
- }
-
// does appID end with '-uniqueautogen'?
if strings.HasSuffix(appID, uniqueAutogenSuffix) {
// replace suffix with pod UID
diff --git a/pkg/common/utils/utils_test.go b/pkg/common/utils/utils_test.go
index 282205f7..fb03ce9d 100644
--- a/pkg/common/utils/utils_test.go
+++ b/pkg/common/utils/utils_test.go
@@ -584,7 +584,6 @@ func TestPodUnderCondition(t *testing.T) {
// nolint: funlen
func TestGetApplicationIDFromPod(t *testing.T) {
- defer SetPluginMode(false)
defer func() { conf.GetSchedulerConf().GenerateUniqueAppIds = false }()
appIDInCanonicalLabel := "CanonicalLabelAppID"
@@ -592,50 +591,49 @@ func TestGetApplicationIDFromPod(t *testing.T) {
appIDInLabel := "labelAppID"
appIDInSelector := "sparkLabelAppID"
testCases := []struct {
- name string
- pod *v1.Pod
- expectedAppID string
- expectedAppIDPluginMode string
- generateUniqueAppIds bool
+ name string
+ pod *v1.Pod
+ expectedAppID string
+ generateUniqueAppIds bool
}{
{"AppID defined in canonical label", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels:
map[string]string{constants.CanonicalLabelApplicationID: appIDInCanonicalLabel},
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, appIDInCanonicalLabel, appIDInCanonicalLabel, false},
+ }, appIDInCanonicalLabel, false},
{"AppID defined in annotation", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations:
map[string]string{constants.AnnotationApplicationID: appIDInAnnotation},
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, appIDInAnnotation, appIDInAnnotation, false},
+ }, appIDInAnnotation, false},
{"AppID defined in legacy label", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels:
map[string]string{constants.LabelApplicationID: appIDInLabel},
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, appIDInLabel, appIDInLabel, false},
+ }, appIDInLabel, false},
{"AppID defined in spark app selector label", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels:
map[string]string{constants.SparkLabelAppID: appIDInSelector},
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, appIDInSelector, appIDInSelector, false},
+ }, appIDInSelector, false},
{"AppID defined in canonical label and annotation, canonical
label win", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations:
map[string]string{constants.AnnotationApplicationID: appIDInAnnotation},
Labels:
map[string]string{constants.CanonicalLabelApplicationID: appIDInCanonicalLabel},
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, appIDInCanonicalLabel, appIDInCanonicalLabel, false},
+ }, appIDInCanonicalLabel, false},
{"AppID defined in annotation and legacy label, annotation
win", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations:
map[string]string{constants.AnnotationApplicationID: appIDInAnnotation},
Labels:
map[string]string{constants.LabelApplicationID: appIDInLabel},
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, appIDInAnnotation, appIDInAnnotation, false},
+ }, appIDInAnnotation, false},
{"Spark AppID defined in legacy label and spark app selector,
legacy label win", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
@@ -644,22 +642,22 @@ func TestGetApplicationIDFromPod(t *testing.T) {
},
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, appIDInLabel, appIDInLabel, false},
- {"No AppID defined", &v1.Pod{}, "", "", false},
+ }, appIDInLabel, false},
+ {"No AppID defined", &v1.Pod{}, "", false},
{"No AppID defined but not generateUnique", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: "testns",
UID: "podUid",
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, "yunikorn-testns-autogen", "", false},
+ }, "yunikorn-testns-autogen", false},
{"No AppID defined but generateUnique", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: "testns",
UID: "podUid",
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, "testns-podUid", "", true},
+ }, "testns-podUid", true},
{"Unique autogen token found with generateUnique in canonical
AppId label", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: "testns",
@@ -667,7 +665,7 @@ func TestGetApplicationIDFromPod(t *testing.T) {
Labels:
map[string]string{constants.CanonicalLabelApplicationID:
"testns-uniqueautogen"},
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, "testns-podUid", "testns-podUid", true},
+ }, "testns-podUid", true},
{"Unique autogen token found with generateUnique in legacy
AppId labels", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: "testns",
@@ -675,19 +673,19 @@ func TestGetApplicationIDFromPod(t *testing.T) {
Labels:
map[string]string{constants.LabelApplicationID: "testns-uniqueautogen"},
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, "testns-podUid", "testns-podUid", true},
+ }, "testns-podUid", true},
{"Non-yunikorn schedulerName with canonical AppId label",
&v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels:
map[string]string{constants.CanonicalLabelApplicationID: appIDInCanonicalLabel},
},
Spec: v1.PodSpec{SchedulerName: "default"},
- }, "", "", false},
+ }, "", false},
{"Non-yunikorn schedulerName with legacy AppId label", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels:
map[string]string{constants.LabelApplicationID: appIDInLabel},
},
Spec: v1.PodSpec{SchedulerName: "default"},
- }, "", "", false},
+ }, "", false},
{"AppID defined but ignore-application set", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
@@ -696,7 +694,7 @@ func TestGetApplicationIDFromPod(t *testing.T) {
},
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, appIDInAnnotation, "", false},
+ }, appIDInAnnotation, false},
{"AppID defined and ignore-application invalid", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
@@ -705,20 +703,14 @@ func TestGetApplicationIDFromPod(t *testing.T) {
},
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
- }, appIDInAnnotation, appIDInAnnotation, false},
+ }, appIDInAnnotation, false},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
conf.GetSchedulerConf().GenerateUniqueAppIds =
tc.generateUniqueAppIds
- SetPluginMode(false)
- assert.Equal(t, IsPluginMode(), false)
appID := GetApplicationIDFromPod(tc.pod)
assert.Equal(t, appID, tc.expectedAppID, "Wrong appID
(standard mode)")
- SetPluginMode(true)
- assert.Equal(t, IsPluginMode(), true)
- appID2 := GetApplicationIDFromPod(tc.pod)
- assert.Equal(t, appID2, tc.expectedAppIDPluginMode,
"Wrong appID (plugin mode)")
})
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]