mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 12:47:28 +08:00
feat: Support only watching key resources in one namespace (#1821)
This commit is contained in:
@@ -15,15 +15,14 @@
|
||||
package secret
|
||||
|
||||
import (
|
||||
"github.com/alibaba/higress/pkg/ingress/kube/common"
|
||||
"github.com/alibaba/higress/pkg/ingress/kube/controller"
|
||||
"istio.io/istio/pkg/cluster"
|
||||
"istio.io/istio/pkg/config/schema/gvr"
|
||||
schemakubeclient "istio.io/istio/pkg/config/schema/kubeclient"
|
||||
kubeclient "istio.io/istio/pkg/kube"
|
||||
"istio.io/istio/pkg/kube/controllers"
|
||||
ktypes "istio.io/istio/pkg/kube/kubetypes"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
listersv1 "k8s.io/client-go/listers/core/v1"
|
||||
@@ -31,17 +30,17 @@ import (
|
||||
|
||||
type SecretController controller.Controller[listersv1.SecretLister]
|
||||
|
||||
func NewController(client kubeclient.Client, clusterId cluster.ID) SecretController {
|
||||
func NewController(client kubeclient.Client, options common.Options) SecretController {
|
||||
opts := ktypes.InformerOptions{
|
||||
Namespace: metav1.NamespaceAll,
|
||||
Cluster: clusterId,
|
||||
Namespace: options.WatchNamespace,
|
||||
Cluster: options.ClusterId,
|
||||
FieldSelector: fields.AndSelectors(
|
||||
fields.OneTermNotEqualSelector("type", "helm.sh/release.v1"),
|
||||
fields.OneTermNotEqualSelector("type", string(v1.SecretTypeServiceAccountToken)),
|
||||
).String(),
|
||||
}
|
||||
informer := schemakubeclient.GetInformerFilteredFromGVR(client, opts, gvr.Secret)
|
||||
return controller.NewCommonController("secret", listersv1.NewSecretLister(informer.Informer.GetIndexer()), informer.Informer, GetSecret, clusterId)
|
||||
return controller.NewCommonController("secret", listersv1.NewSecretLister(informer.Informer.GetIndexer()), informer.Informer, GetSecret, options.ClusterId)
|
||||
}
|
||||
|
||||
func GetSecret(lister listersv1.SecretLister, namespacedName types.NamespacedName) (controllers.Object, error) {
|
||||
|
||||
@@ -16,6 +16,7 @@ package secret
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/alibaba/higress/pkg/ingress/kube/common"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -43,7 +44,7 @@ var period = time.Second
|
||||
|
||||
func TestController(t *testing.T) {
|
||||
client := kubeclient.NewFakeClient()
|
||||
ctrl := NewController(client, "fake-cluster")
|
||||
ctrl := NewController(client, common.Options{ClusterId: "fake-cluster"})
|
||||
|
||||
stop := make(chan struct{})
|
||||
t.Cleanup(func() {
|
||||
|
||||
Reference in New Issue
Block a user