This is an automated email from the ASF dual-hosted git repository.
ccondit 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 c543ece2 [YUNIKORN-2369] AM: Add token suffix when using unique
applicationId feature (#773)
c543ece2 is described below
commit c543ece2b552c02e9d7cfea957b92580c0fec4a6
Author: Craig Condit <[email protected]>
AuthorDate: Wed Jan 31 16:38:41 2024 -0600
[YUNIKORN-2369] AM: Add token suffix when using unique applicationId
feature (#773)
Workaround missing pod UID in admission controller lifecycle by setting a
suffix of "-uniqueautogen" when the unique applicationId feature is in use.
This suffix will be detected and replaced by the scheduler since the pod
UID will exist at that point.
Closes: #773
---
pkg/common/utils/utils.go | 37 ++++++++++++++++++++++++++-----------
pkg/common/utils/utils_test.go | 11 +++++++++++
2 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/pkg/common/utils/utils.go b/pkg/common/utils/utils.go
index b0895ef8..b0a84470 100644
--- a/pkg/common/utils/utils.go
+++ b/pkg/common/utils/utils.go
@@ -41,6 +41,7 @@ import (
)
const userInfoKey = siCommon.DomainYuniKorn + "user.info"
+const uniqueAutogenSuffix = "-uniqueautogen"
var pluginMode bool
@@ -118,7 +119,12 @@ func GetQueueNameFromPod(pod *v1.Pod) string {
func GenerateApplicationID(namespace string, generateUniqueAppIds bool, podUID
string) string {
var generatedID string
if generateUniqueAppIds {
- generatedID = fmt.Sprintf("%.26s-%s", namespace, podUID)
+ if podUID == "" {
+ // we must be running in the admission controller and
don't yet have a pod UID assigned
+ generatedID = fmt.Sprintf("%.26s%s", namespace,
uniqueAutogenSuffix)
+ } else {
+ generatedID = fmt.Sprintf("%.26s-%s", namespace, podUID)
+ }
} else {
generatedID = fmt.Sprintf("%s-%s-%s",
constants.AutoGenAppPrefix, namespace, constants.AutoGenAppSuffix)
}
@@ -149,23 +155,32 @@ func GetApplicationIDFromPod(pod *v1.Pod) string {
}
// Application ID can be defined in annotation
- if value := GetPodAnnotationValue(pod,
constants.AnnotationApplicationID); value != "" {
- return value
+ appID := GetPodAnnotationValue(pod, constants.AnnotationApplicationID)
+ if appID == "" {
+ // Application ID can be defined in label
+ appID = GetPodLabelValue(pod, constants.LabelApplicationID)
}
- // Application ID can be defined in label
- if value := GetPodLabelValue(pod, constants.LabelApplicationID); value
!= "" {
- return value
- }
- // Spark can also define application ID
- if value := GetPodLabelValue(pod, constants.SparkLabelAppID); value !=
"" {
- return value
+ if appID == "" {
+ // Spark can also define application ID
+ appID = GetPodLabelValue(pod, constants.SparkLabelAppID)
}
// If plugin mode, interpret missing Application ID as a non-YuniKorn
pod
- if pluginMode {
+ if pluginMode && appID == "" {
return ""
}
+ // does appID end with '-uniqueautogen'?
+ if strings.HasSuffix(appID, uniqueAutogenSuffix) {
+ // replace suffix with pod UID
+ appID = fmt.Sprintf("%s-%s", strings.TrimSuffix(appID,
uniqueAutogenSuffix), string(pod.UID))
+ }
+
+ // if app ID is not empty, return it
+ if appID != "" {
+ return appID
+ }
+
// Standard deployment mode, so we need a valid Application ID to
proceed. Generate one now.
return GenerateApplicationID(pod.Namespace,
conf.GetSchedulerConf().GenerateUniqueAppIds, string(pod.UID))
}
diff --git a/pkg/common/utils/utils_test.go b/pkg/common/utils/utils_test.go
index c7e8a45b..9bebae2b 100644
--- a/pkg/common/utils/utils_test.go
+++ b/pkg/common/utils/utils_test.go
@@ -545,6 +545,14 @@ func TestGetApplicationIDFromPod(t *testing.T) {
},
Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
}, "testns-podUid", "", true},
+ {"Unique autogen token found with generateUnique", &v1.Pod{
+ ObjectMeta: metav1.ObjectMeta{
+ Namespace: "testns",
+ UID: "podUid",
+ Labels:
map[string]string{constants.LabelApplicationID: "testns-uniqueautogen"},
+ },
+ Spec: v1.PodSpec{SchedulerName:
constants.SchedulerName},
+ }, "testns-podUid", "testns-podUid", true},
{"Non-yunikorn schedulerName", &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels:
map[string]string{constants.LabelApplicationID: appIDInLabel},
@@ -643,6 +651,9 @@ func TestGenerateApplicationID(t *testing.T) {
assert.Equal(t, "longlonglonglonglonglonglo-pod-uid",
GenerateApplicationID(strings.Repeat("long", 100), true,
"pod-uid"))
+
+ assert.Equal(t, "namespace-uniqueautogen",
+ GenerateApplicationID("namespace", true, ""))
}
func TestMergeMaps(t *testing.T) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]