...
1 package kclient
2
3 import (
4 fakeServiceCatalogClientSet "github.com/kubernetes-sigs/service-catalog/pkg/client/clientset_generated/clientset/fake"
5 fakeAppsClientset "github.com/openshift/client-go/apps/clientset/versioned/fake"
6 fakeProjClientset "github.com/openshift/client-go/project/clientset/versioned/fake"
7 fakeRouteClientset "github.com/openshift/client-go/route/clientset/versioned/fake"
8 odoFake "github.com/redhat-developer/odo/pkg/kclient/fake"
9 corev1 "k8s.io/api/core/v1"
10 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11 "k8s.io/client-go/discovery/cached/memory"
12 fakediscovery "k8s.io/client-go/discovery/fake"
13 fakeKubeClientset "k8s.io/client-go/kubernetes/fake"
14 )
15
16
17
18 type FakeClientset struct {
19 Kubernetes *fakeKubeClientset.Clientset
20 ServiceCatalogClientSet *fakeServiceCatalogClientSet.Clientset
21 ProjClientset *fakeProjClientset.Clientset
22 RouteClientset *fakeRouteClientset.Clientset
23 AppsClientset *fakeAppsClientset.Clientset
24 }
25
26
27
28
29
30 func FakeNew() (*Client, *FakeClientset) {
31 return FakeNewWithIngressSupports(false, true)
32 }
33
34
35
36
37 func FakeNewWithIngressSupports(networkingv1Supported, extensionV1Supported bool) (*Client, *FakeClientset) {
38 var client Client
39 var fkclientset FakeClientset
40
41 fkclientset.Kubernetes = fakeKubeClientset.NewSimpleClientset()
42 client.KubeClient = fkclientset.Kubernetes
43
44 fkclientset.ServiceCatalogClientSet = fakeServiceCatalogClientSet.NewSimpleClientset()
45 client.serviceCatalogClient = fkclientset.ServiceCatalogClientSet.ServicecatalogV1beta1()
46
47 fkclientset.AppsClientset = fakeAppsClientset.NewSimpleClientset()
48 client.appsClient = fkclientset.Kubernetes.AppsV1()
49 client.isExtensionV1Beta1IngressSupported = extensionV1Supported
50 client.isNetworkingV1IngressSupported = networkingv1Supported
51 client.checkIngressSupports = false
52 client.discoveryClient = fkclientset.Kubernetes.Discovery().(*fakediscovery.FakeDiscovery)
53 client.cachedDiscoveryClient = memory.NewMemCacheClient(client.discoveryClient)
54
55 fkclientset.ProjClientset = fakeProjClientset.NewSimpleClientset()
56 client.projectClient = fkclientset.ProjClientset.ProjectV1()
57
58 fkclientset.RouteClientset = fakeRouteClientset.NewSimpleClientset()
59 client.routeClient = fkclientset.RouteClientset.RouteV1()
60
61 return &client, &fkclientset
62 }
63
64
65 func FakePodStatus(status corev1.PodPhase, podName string) *corev1.Pod {
66 return &corev1.Pod{
67 ObjectMeta: metav1.ObjectMeta{
68 Name: podName,
69 Labels: map[string]string{},
70 },
71 Status: corev1.PodStatus{
72 Phase: status,
73 },
74 }
75 }
76
77 func NewKubernetesFakedDiscovery(extv1b1supported, nwv1suppored bool) *odoFake.FakeDiscovery {
78 fd := odoFake.NewFakeDiscovery()
79 extingress := metav1.GroupVersionResource{
80 Group: "extensions",
81 Version: "v1beta1",
82 Resource: "ingress",
83 }
84 netv1ingress := metav1.GroupVersionResource{
85 Group: "networking.k8s.io",
86 Version: "v1",
87 Resource: "ingress",
88 }
89 if extv1b1supported {
90 fd.AddResourceList(extingress.String(), &metav1.APIResourceList{
91 GroupVersion: "extensions/v1beta1",
92 APIResources: []metav1.APIResource{{
93 Name: "ingress",
94 SingularName: "ingress",
95 Namespaced: true,
96 Kind: "ingress",
97 }},
98 })
99 }
100
101 if nwv1suppored {
102 fd.AddResourceList(netv1ingress.String(), &metav1.APIResourceList{
103 GroupVersion: "networking.k8s.io/v1",
104 APIResources: []metav1.APIResource{{
105 Name: "ingress",
106 SingularName: "ingress",
107 Namespaced: true,
108 Kind: "ingress",
109 }},
110 })
111 }
112 return fd
113 }
114
View as plain text