mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
use match not equal to find svc by pod label in fargate mode
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"reflect"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -12,6 +11,7 @@ import (
|
|||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
k8sjson "k8s.io/apimachinery/pkg/util/json"
|
k8sjson "k8s.io/apimachinery/pkg/util/json"
|
||||||
@@ -108,7 +108,7 @@ func ModifyServiceTargetPort(ctx context.Context, clientset *kubernetes.Clientse
|
|||||||
|
|
||||||
var svc *v1.Service
|
var svc *v1.Service
|
||||||
for _, item := range list.Items {
|
for _, item := range list.Items {
|
||||||
if reflect.DeepEqual(item.Spec.Selector, podLabels) {
|
if labels.SelectorFromSet(item.Spec.Selector).Matches(labels.Set(podLabels)) {
|
||||||
svc = &item
|
svc = &item
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
20
pkg/inject/label_test.go
Normal file
20
pkg/inject/label_test.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package inject
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLabelMatch(t *testing.T) {
|
||||||
|
selector := map[string]string{
|
||||||
|
"app": "universer",
|
||||||
|
"app.kubernetes.io/name": "universer",
|
||||||
|
}
|
||||||
|
podLabels := map[string]string{
|
||||||
|
"app": "universer",
|
||||||
|
"app.kubernetes.io/name": "universer",
|
||||||
|
"version": "ai-chat-flow",
|
||||||
|
}
|
||||||
|
t.Log(labels.SelectorFromSet(selector).Matches(labels.Set(podLabels)))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user