@@ -11,9 +11,11 @@ import (
1111 "github.com/stretchr/testify/require"
1212 api_v1 "k8s.io/api/core/v1"
1313 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+ "k8s.io/apimachinery/pkg/runtime"
1415 "k8s.io/apimachinery/pkg/runtime/schema"
1516 "k8s.io/apimachinery/pkg/selection"
1617 clientmeta "k8s.io/client-go/metadata"
18+ clientmetafake "k8s.io/client-go/metadata/fake"
1719 "k8s.io/client-go/tools/cache"
1820
1921 "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
@@ -171,7 +173,7 @@ func Test_fakeNamespaceInformer(t *testing.T) {
171173}
172174
173175func Test_replicasetListFuncWithSelectors (t * testing.T ) {
174- mc := newTestMetadataClient (t )
176+ mc := newTestMetadataClient ()
175177 gvr := schema.GroupVersionResource {Group : "apps" , Version : "v1" , Resource : "replicasets" }
176178 listFunc := replicaSetListFuncWithSelectors (mc , gvr , "test-ns" )
177179 opts := metav1.ListOptions {}
@@ -181,7 +183,7 @@ func Test_replicasetListFuncWithSelectors(t *testing.T) {
181183}
182184
183185func Test_replicasetWatchFuncWithSelectors (t * testing.T ) {
184- mc := newTestMetadataClient (t )
186+ mc := newTestMetadataClient ()
185187 gvr := schema.GroupVersionResource {Group : "apps" , Version : "v1" , Resource : "replicasets" }
186188 watchFunc := replicaSetWatchFuncWithSelectors (mc , gvr , "test-ns" )
187189 opts := metav1.ListOptions {}
@@ -191,29 +193,16 @@ func Test_replicasetWatchFuncWithSelectors(t *testing.T) {
191193}
192194
193195func Test_newReplicaSetsharedInformer (t * testing.T ) {
194- mc := newTestMetadataClient (t )
196+ mc := newTestMetadataClient ()
195197 informer := newReplicaSetSharedInformer (mc , "test-ns" )
196198 if informer == nil {
197199 t .Fatalf ("Expected informer to be non-nil, but got nil. Check logs for details." )
198200 }
199201 assert .NotNil (t , informer )
200202}
201203
202- func newTestMetadataClient (t * testing.T ) clientmeta.Interface {
203- t .Setenv ("KUBERNETES_SERVICE_HOST" , "127.0.0.1" )
204- t .Setenv ("KUBERNETES_SERVICE_PORT" , "6443" )
205-
206- apiCfg := k8sconfig.APIConfig {
207- AuthType : "none" ,
208- }
209-
210- // Create rest.Config from apiCfg
211- restCfg , err := k8sconfig .CreateRestConfig (apiCfg )
212- require .NoError (t , err )
213-
214- // Create metadata client from rest.Config
215- mc , err := clientmeta .NewForConfig (restCfg )
216- require .NoError (t , err )
204+ func newTestMetadataClient () clientmeta.Interface {
205+ mc := clientmetafake .NewSimpleMetadataClient (runtime .NewScheme ()) // or NewSimpleClientset for older versions
217206 return mc
218207}
219208
0 commit comments