github.com/kiali/kiali@v1.84.0/kubernetes/kubetest/mock_istio.go (about) 1 package kubetest 2 3 import ( 4 "context" 5 6 networking_v1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1" 7 istio "istio.io/client-go/pkg/clientset/versioned" 8 istio_fake "istio.io/client-go/pkg/clientset/versioned/fake" 9 v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 "k8s.io/apimachinery/pkg/runtime" 11 gatewayapiclient "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned" 12 gatewayapifake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake" 13 14 "github.com/kiali/kiali/kubernetes" 15 "github.com/kiali/kiali/log" 16 ) 17 18 func (o *K8SClientMock) MockIstio(objects ...runtime.Object) { 19 o.istioClientset = istio_fake.NewSimpleClientset(objects...) 20 // Istio Fake client has a problem with Gateways 21 // Invoking a NewSimpleClientset() stores a wrong "gatewais" entry, that logic is not even the istio.io but 22 // in the k8s.io/apimachinery, so the workaround is to invoke "Create" for those objects with problems 23 for _, ob := range objects { 24 if gw, ok := ob.(*networking_v1beta1.Gateway); ok { 25 _, err := o.istioClientset.NetworkingV1beta1().Gateways(gw.Namespace).Create(context.TODO(), gw, v1.CreateOptions{}) 26 if err != nil { 27 log.Errorf("Error initializing Gateways in MockIstio: %s", err) 28 } 29 } 30 } 31 } 32 33 func (o *K8SClientMock) MockGatewayApi(objects ...runtime.Object) { 34 o.gatewayapiClientSet = gatewayapifake.NewSimpleClientset(objects...) 35 } 36 37 func (o *K8SClientMock) Istio() istio.Interface { 38 return o.istioClientset 39 } 40 41 func (o *K8SClientMock) GatewayAPI() gatewayapiclient.Interface { 42 return o.gatewayapiClientSet 43 } 44 45 func (o *K8SClientMock) CanConnectToIstiod() (kubernetes.IstioComponentStatus, error) { 46 args := o.Called() 47 return args.Get(0).(kubernetes.IstioComponentStatus), args.Error(1) 48 } 49 50 func (o *K8SClientMock) GetProxyStatus() ([]*kubernetes.ProxyStatus, error) { 51 args := o.Called() 52 return args.Get(0).([]*kubernetes.ProxyStatus), args.Error(1) 53 } 54 55 func (o *K8SClientMock) GetConfigDump(namespace string, podName string) (*kubernetes.ConfigDump, error) { 56 args := o.Called(namespace, podName) 57 return args.Get(0).(*kubernetes.ConfigDump), args.Error(1) 58 } 59 60 func (o *K8SClientMock) GetRegistryServices() ([]*kubernetes.RegistryService, error) { 61 args := o.Called() 62 return args.Get(0).([]*kubernetes.RegistryService), args.Error(1) 63 } 64 65 func (o *K8SClientMock) SetProxyLogLevel(namespace, podName, level string) error { 66 args := o.Called() 67 return args.Error(0) 68 }