From 64e442b995b26e8379006d57469a69e2c564a6e4 Mon Sep 17 00:00:00 2001 From: Joey <569475269@qq.com> Date: Tue, 18 Nov 2025 09:16:41 +0800 Subject: [PATCH 1/2] fix: bump deps, inject-container convert from limits --- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- internal/webhook/v1/tf_parser.go | 8 +++++--- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index ca387491..4b2b42b8 100644 --- a/go.mod +++ b/go.mod @@ -32,13 +32,13 @@ require ( gorm.io/gorm v1.31.1 k8s.io/api v0.34.2 k8s.io/apimachinery v0.34.2 - k8s.io/apiserver v0.34.1 + k8s.io/apiserver v0.34.2 k8s.io/autoscaler/vertical-pod-autoscaler v1.5.1 k8s.io/client-go v0.34.2 - k8s.io/component-base v0.34.1 - k8s.io/component-helpers v0.34.1 + k8s.io/component-base v0.34.2 + k8s.io/component-helpers v0.34.2 k8s.io/klog/v2 v2.130.1 - k8s.io/kube-scheduler v0.34.1 + k8s.io/kube-scheduler v0.34.2 k8s.io/kubernetes v1.34.2 k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 sigs.k8s.io/controller-runtime v0.22.4 @@ -184,7 +184,7 @@ require ( k8s.io/controller-manager v0.34.1 // indirect k8s.io/csi-translation-lib v0.34.1 // indirect k8s.io/dynamic-resource-allocation v0.34.0 // indirect - k8s.io/kms v0.34.1 // indirect + k8s.io/kms v0.34.2 // indirect k8s.io/kube-openapi v0.0.0-20250905212525-66792eed8611 // indirect k8s.io/kubelet v0.34.0 // indirect sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.33.0 // indirect diff --git a/go.sum b/go.sum index 8022ac4b..72ec8d45 100644 --- a/go.sum +++ b/go.sum @@ -516,18 +516,18 @@ k8s.io/apiextensions-apiserver v0.34.1 h1:NNPBva8FNAPt1iSVwIE0FsdrVriRXMsaWFMqJb k8s.io/apiextensions-apiserver v0.34.1/go.mod h1:hP9Rld3zF5Ay2Of3BeEpLAToP+l4s5UlxiHfqRaRcMc= k8s.io/apimachinery v0.34.2 h1:zQ12Uk3eMHPxrsbUJgNF8bTauTVR2WgqJsTmwTE/NW4= k8s.io/apimachinery v0.34.2/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw= -k8s.io/apiserver v0.34.1 h1:U3JBGdgANK3dfFcyknWde1G6X1F4bg7PXuvlqt8lITA= -k8s.io/apiserver v0.34.1/go.mod h1:eOOc9nrVqlBI1AFCvVzsob0OxtPZUCPiUJL45JOTBG0= +k8s.io/apiserver v0.34.2 h1:2/yu8suwkmES7IzwlehAovo8dDE07cFRC7KMDb1+MAE= +k8s.io/apiserver v0.34.2/go.mod h1:gqJQy2yDOB50R3JUReHSFr+cwJnL8G1dzTA0YLEqAPI= k8s.io/autoscaler/vertical-pod-autoscaler v1.5.1 h1:LlVtM3IKqIVHz1ZXC3ahe/mAtDWb7Eob0tyTzqFULqg= k8s.io/autoscaler/vertical-pod-autoscaler v1.5.1/go.mod h1:znhUnV0Yn+CkZu3TZ2HVqd8GFRMkPj/CXszX1gdBjTU= k8s.io/client-go v0.34.2 h1:Co6XiknN+uUZqiddlfAjT68184/37PS4QAzYvQvDR8M= k8s.io/client-go v0.34.2/go.mod h1:2VYDl1XXJsdcAxw7BenFslRQX28Dxz91U9MWKjX97fE= k8s.io/cloud-provider v0.34.1 h1:FS+4C1vq9pIngd/5LR5Jha1sEbn+fo0HJitgZmUyBNc= k8s.io/cloud-provider v0.34.1/go.mod h1:ghyQYfQIWZAXKNS+TEgEiQ8wPuhzIVt3wFO6rKqS/rQ= -k8s.io/component-base v0.34.1 h1:v7xFgG+ONhytZNFpIz5/kecwD+sUhVE6HU7qQUiRM4A= -k8s.io/component-base v0.34.1/go.mod h1:mknCpLlTSKHzAQJJnnHVKqjxR7gBeHRv0rPXA7gdtQ0= -k8s.io/component-helpers v0.34.1 h1:gWhH3CCdwAx5P3oJqZKb4Lg5FYZTWVbdWtOI8n9U4XY= -k8s.io/component-helpers v0.34.1/go.mod h1:4VgnUH7UA/shuBur+OWoQC0xfb69sy/93ss0ybZqm3c= +k8s.io/component-base v0.34.2 h1:HQRqK9x2sSAsd8+R4xxRirlTjowsg6fWCPwWYeSvogQ= +k8s.io/component-base v0.34.2/go.mod h1:9xw2FHJavUHBFpiGkZoKuYZ5pdtLKe97DEByaA+hHbM= +k8s.io/component-helpers v0.34.2 h1:RIUGDdU+QFzeVKLZ9f05sXTNAtJrRJ3bnbMLrogCrvM= +k8s.io/component-helpers v0.34.2/go.mod h1:pLi+GByuRTeFjjcezln8gHL7LcT6HImkwVQ3A2SQaEE= k8s.io/controller-manager v0.34.1 h1:c9Cmun/zF740kmdRQWPGga+4MglT5SlrwsCXDS/KtJI= k8s.io/controller-manager v0.34.1/go.mod h1:fGiJDhi3OSzSAB4f40ZkJLAqMQSag9RM+7m5BRhBO3Q= k8s.io/csi-translation-lib v0.34.1 h1:8+QMIWBwPGFsqWw9eAvimA2GaHXGgLLYT61I1NzDnXw= @@ -536,12 +536,12 @@ k8s.io/dynamic-resource-allocation v0.34.0 h1:RrFNZXb2s5cvvf+KKdO92ss/e+zjGFFaDK k8s.io/dynamic-resource-allocation v0.34.0/go.mod h1:aqmoDIvXjQRhSgxQkFLl6+Ndg6MfdEOI+TQsj1j9V+g= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kms v0.34.1 h1:iCFOvewDPzWM9fMTfyIPO+4MeuZ0tcZbugxLNSHFG4w= -k8s.io/kms v0.34.1/go.mod h1:s1CFkLG7w9eaTYvctOxosx88fl4spqmixnNpys0JAtM= +k8s.io/kms v0.34.2 h1:91rj4MDZLyIT9KxG8J5/CcMH666Z88CF/xJQeuPfJc8= +k8s.io/kms v0.34.2/go.mod h1:s1CFkLG7w9eaTYvctOxosx88fl4spqmixnNpys0JAtM= k8s.io/kube-openapi v0.0.0-20250905212525-66792eed8611 h1:o4oKOsvSymDkZRsMAPZU7bRdwL+lPOK5VS10Dr1D6eg= k8s.io/kube-openapi v0.0.0-20250905212525-66792eed8611/go.mod h1:kdmbQkyfwUagLfXIad1y2TdrjPFWp2Q89B3qkRwf/pQ= -k8s.io/kube-scheduler v0.34.1 h1:S5td6VZwC3lCqERXclerDXhJ26zYc6JroY0s03+PqJ8= -k8s.io/kube-scheduler v0.34.1/go.mod h1:UiOkod/w+HKoGut9mz9ie4s4KcI82vmLFdq1iIgsmRs= +k8s.io/kube-scheduler v0.34.2 h1:TtLcaXeIpkqgzMr2ch7Ap8Cluq4M182XUDRlnOPDdoc= +k8s.io/kube-scheduler v0.34.2/go.mod h1:PTn4QYiSet8/00VQ2qGO/HWdo5iNJlVRCXz/7R3Ut5I= k8s.io/kubelet v0.34.0 h1:1nZt1Q6Kfx7xCaTS9vnqR9sjZDxf3cRSQkAFCczULmc= k8s.io/kubelet v0.34.0/go.mod h1:NqbF8ViVettlZbf9hw9DJhubaWn7rGvDDTcLMDm6tQ0= k8s.io/kubernetes v1.34.2 h1:WQdDvYJazkmkwSncgNwGvVtaCt4TYXIU3wSMRgvp3MI= diff --git a/internal/webhook/v1/tf_parser.go b/internal/webhook/v1/tf_parser.go index c3a8d49e..aeb9e680 100644 --- a/internal/webhook/v1/tf_parser.go +++ b/internal/webhook/v1/tf_parser.go @@ -182,7 +182,7 @@ func parseAutoScalingAnnotations(pod *corev1.Pod, workloadProfile *tfv1.Workload func parseGPUResourcesAnnotations(pod *corev1.Pod, workloadProfile *tfv1.WorkloadProfile) error { // extract any containers has GPU count limits and set to annotation - isMigratedFromContainerLimits := false + migratedContainerLimits := []string{} gpuCount, hasValue := pod.Annotations[constants.GpuCountAnnotation] if hasValue { val, err := strconv.ParseInt(gpuCount, 10, 32) @@ -201,7 +201,7 @@ func parseGPUResourcesAnnotations(pod *corev1.Pod, workloadProfile *tfv1.Workloa // For seamless migration with only one tensor-fusion.ai/enabled label // and one tensor-fusion.ai/vram-limit annotation, convert this to 100% computing-percent workloadProfile.Spec.Resources.Limits.ComputePercent = resource.MustParse("100") - isMigratedFromContainerLimits = true + migratedContainerLimits = append(migratedContainerLimits, container.Name) break } } @@ -211,8 +211,10 @@ func parseGPUResourcesAnnotations(pod *corev1.Pod, workloadProfile *tfv1.Workloa if tflopsLimit, hasValue := parseResourceQuantity(pod, constants.TFLOPSLimitAnnotation); hasValue { workloadProfile.Spec.Resources.Limits.Tflops = tflopsLimit // clean compute percent limit when tflops limit is set in annotation - if isMigratedFromContainerLimits { + if len(migratedContainerLimits) > 0 { workloadProfile.Spec.Resources.Limits.ComputePercent = resource.Quantity{} + // convert limits containers to annotation for inject container + pod.Annotations[constants.InjectContainerAnnotation] = strings.Join(migratedContainerLimits, ",") } } if vramLimit, hasValue := parseResourceQuantity(pod, constants.VRAMLimitAnnotation); hasValue { From 0b783bfcc8ba33ae6bbc60e8948896d9cdbcc00e Mon Sep 17 00:00:00 2001 From: Joey <569475269@qq.com> Date: Tue, 18 Nov 2025 09:24:12 +0800 Subject: [PATCH 2/2] fix: auto parse inject container from limits --- internal/webhook/v1/tf_parser.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/webhook/v1/tf_parser.go b/internal/webhook/v1/tf_parser.go index aeb9e680..0066b442 100644 --- a/internal/webhook/v1/tf_parser.go +++ b/internal/webhook/v1/tf_parser.go @@ -182,7 +182,7 @@ func parseAutoScalingAnnotations(pod *corev1.Pod, workloadProfile *tfv1.Workload func parseGPUResourcesAnnotations(pod *corev1.Pod, workloadProfile *tfv1.WorkloadProfile) error { // extract any containers has GPU count limits and set to annotation - migratedContainerLimits := []string{} + isMigratedFromContainerLimits := false gpuCount, hasValue := pod.Annotations[constants.GpuCountAnnotation] if hasValue { val, err := strconv.ParseInt(gpuCount, 10, 32) @@ -201,7 +201,11 @@ func parseGPUResourcesAnnotations(pod *corev1.Pod, workloadProfile *tfv1.Workloa // For seamless migration with only one tensor-fusion.ai/enabled label // and one tensor-fusion.ai/vram-limit annotation, convert this to 100% computing-percent workloadProfile.Spec.Resources.Limits.ComputePercent = resource.MustParse("100") - migratedContainerLimits = append(migratedContainerLimits, container.Name) + isMigratedFromContainerLimits = true + // convert limits containers to annotation for inject container when not specified + if pod.Annotations[constants.InjectContainerAnnotation] == "" { + pod.Annotations[constants.InjectContainerAnnotation] = container.Name + } break } } @@ -211,10 +215,8 @@ func parseGPUResourcesAnnotations(pod *corev1.Pod, workloadProfile *tfv1.Workloa if tflopsLimit, hasValue := parseResourceQuantity(pod, constants.TFLOPSLimitAnnotation); hasValue { workloadProfile.Spec.Resources.Limits.Tflops = tflopsLimit // clean compute percent limit when tflops limit is set in annotation - if len(migratedContainerLimits) > 0 { + if isMigratedFromContainerLimits { workloadProfile.Spec.Resources.Limits.ComputePercent = resource.Quantity{} - // convert limits containers to annotation for inject container - pod.Annotations[constants.InjectContainerAnnotation] = strings.Join(migratedContainerLimits, ",") } } if vramLimit, hasValue := parseResourceQuantity(pod, constants.VRAMLimitAnnotation); hasValue {