Skip to content

Commit

Permalink
Merge pull request #853 from aramase/update-filtered-watch
Browse files Browse the repository at this point in the history
refactor: use NewSharedInformerFactoryWithOptions for new shared informer
  • Loading branch information
k8s-ci-robot committed Feb 4, 2022
2 parents 7ac887a + b0af2b9 commit 40a6806
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/k8s/token.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Kubernetes Authors.
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,6 @@ import (
"time"

authenticationv1 "k8s.io/api/authentication/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -46,13 +45,14 @@ type TokenClient struct {
// NewTokenClient creates a new TokenClient
// The client will be used to request a token for token requests configured in the CSIDriver.
func NewTokenClient(kubeClient kubernetes.Interface, driverName string, resyncPeriod time.Duration) *TokenClient {
kubeInformerFactory := kubeinformers.NewFilteredSharedInformerFactory(
kubeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(
kubeClient,
resyncPeriod,
corev1.NamespaceAll,
func(options *metav1.ListOptions) {
options.FieldSelector = fmt.Sprintf("metadata.name=%s", driverName)
},
kubeinformers.WithTweakListOptions(
func(options *metav1.ListOptions) {
options.FieldSelector = fmt.Sprintf("metadata.name=%s", driverName)
},
),
)

csiDriverInformer := kubeInformerFactory.Storage().V1().CSIDrivers()
Expand Down
16 changes: 16 additions & 0 deletions pkg/k8s/token_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package k8s

import (
Expand Down

0 comments on commit 40a6806

Please sign in to comment.