Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit bfdfc9b

Browse files
committed
address comments
Signed-off-by: Sean Teeling <[email protected]>
1 parent 1a63975 commit bfdfc9b

20 files changed

+72
-92
lines changed

pkg/catalog/endpoint_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ func TestListAllowedUpstreamEndpointsForService(t *testing.T) {
192192
}
193193
pod.Status.PodIPs = podIps
194194
pod.Spec.ServiceAccountName = sa.Name
195-
_, err := kubeClient.CoreV1().Pods(tests.Namespace).Create(context.TODO(), &pod, metav1.CreateOptions{})
195+
_, err := kubeClient.CoreV1().Pods(tests.Namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
196196
assert.Nil(err)
197-
pods = append(pods, &pod)
197+
pods = append(pods, pod)
198198
}
199199
}
200200
mockKubeController.EXPECT().ListPods().Return(pods).AnyTimes()

pkg/catalog/helpers_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ func newFakeMeshCatalogForRoutes(t *testing.T, testParams testParams) *MeshCatal
5757

5858
// Create a bookstoreV1 pod
5959
bookstoreV1Pod := tests.NewPodFixture(tests.BookstoreV1Service.Namespace, tests.BookstoreV1Service.Name, tests.BookstoreServiceAccountName, tests.PodLabels)
60-
if _, err := kubeClient.CoreV1().Pods(tests.BookstoreV1Service.Namespace).Create(context.TODO(), &bookstoreV1Pod, metav1.CreateOptions{}); err != nil {
60+
if _, err := kubeClient.CoreV1().Pods(tests.BookstoreV1Service.Namespace).Create(context.TODO(), bookstoreV1Pod, metav1.CreateOptions{}); err != nil {
6161
t.Fatalf("Error creating new pod: %s", err.Error())
6262
}
6363

6464
// Create a bookstoreV2 pod
6565
bookstoreV2Pod := tests.NewPodFixture(tests.BookstoreV2Service.Namespace, tests.BookstoreV2Service.Name, tests.BookstoreV2ServiceAccountName, tests.PodLabels)
66-
if _, err := kubeClient.CoreV1().Pods(tests.BookstoreV2Service.Namespace).Create(context.TODO(), &bookstoreV2Pod, metav1.CreateOptions{}); err != nil {
66+
if _, err := kubeClient.CoreV1().Pods(tests.BookstoreV2Service.Namespace).Create(context.TODO(), bookstoreV2Pod, metav1.CreateOptions{}); err != nil {
6767
t.Fatalf("Error creating new pod: %s", err.Error())
6868
}
6969

7070
// Create a bookbuyer pod
7171
bookbuyerPod := tests.NewPodFixture(tests.BookbuyerService.Namespace, tests.BookbuyerService.Name, tests.BookbuyerServiceAccountName, tests.PodLabels)
72-
if _, err := kubeClient.CoreV1().Pods(tests.BookbuyerService.Namespace).Create(context.TODO(), &bookbuyerPod, metav1.CreateOptions{}); err != nil {
72+
if _, err := kubeClient.CoreV1().Pods(tests.BookbuyerService.Namespace).Create(context.TODO(), bookbuyerPod, metav1.CreateOptions{}); err != nil {
7373
t.Fatalf("Error creating new pod: %s", err.Error())
7474
}
7575

pkg/debugger/proxy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ func (ds DebugConfig) getConfigDump(uuid string, w http.ResponseWriter) {
8282
}
8383

8484
func (ds DebugConfig) getProxy(uuid string, w http.ResponseWriter) {
85-
proxy, ok := ds.proxyRegistry.GetConnectedProxy(uuid)
86-
if !ok {
85+
proxy := ds.proxyRegistry.GetConnectedProxy(uuid)
86+
if proxy == nil {
8787
msg := fmt.Sprintf("Proxy for UUID %s not found, may have been disconnected", uuid)
8888
log.Error().Msg(msg)
8989
if _, err := w.Write([]byte(msg)); err != nil {

pkg/envoy/ads/response_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var _ = Describe("Test ADS response functions", func() {
6969
// Create a Pod
7070
pod := tests.NewPodFixture(namespace, fmt.Sprintf("pod-0-%s", uuid.New()), tests.BookstoreServiceAccountName, tests.PodLabels)
7171
pod.Labels[constants.EnvoyUniqueIDLabelName] = proxyUUID.String()
72-
_, err = kubeClient.CoreV1().Pods(namespace).Create(context.TODO(), &pod, metav1.CreateOptions{})
72+
_, err = kubeClient.CoreV1().Pods(namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
7373
It("should have created a pod", func() {
7474
Expect(err).ToNot(HaveOccurred())
7575
})

pkg/envoy/cds/response_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func TestNewResponse(t *testing.T) {
116116
newPod1.Annotations = map[string]string{
117117
constants.PrometheusScrapeAnnotation: "true",
118118
}
119-
_, err := kubeClient.CoreV1().Pods(tests.Namespace).Create(context.TODO(), &newPod1, metav1.CreateOptions{})
119+
_, err := kubeClient.CoreV1().Pods(tests.Namespace).Create(context.TODO(), newPod1, metav1.CreateOptions{})
120120
assert.Nil(err)
121121

122122
mockKubeController.EXPECT().GetPodForProxy(proxy).Return(&newPod1, nil)
@@ -456,7 +456,7 @@ func TestNewResponseGetEgressTrafficPolicyError(t *testing.T) {
456456
pod := tests.NewPodFixture("ns", "pod-1", "svcacc", map[string]string{
457457
constants.EnvoyUniqueIDLabelName: proxyUUID.String(),
458458
})
459-
mockKubeController.EXPECT().GetPodForProxy(proxy).Return(&pod, nil)
459+
mockKubeController.EXPECT().GetPodForProxy(proxy).Return(pod, nil)
460460

461461
resp, err := NewResponse(meshCatalog, proxy, nil, cfg, nil, proxyRegistry)
462462
tassert.NoError(t, err)
@@ -493,7 +493,7 @@ func TestNewResponseGetEgressTrafficPolicyNotEmpty(t *testing.T) {
493493
pod := tests.NewPodFixture("ns", "pod-1", "svcacc", map[string]string{
494494
constants.EnvoyUniqueIDLabelName: proxyUUID.String(),
495495
})
496-
mockKubeController.EXPECT().GetPodForProxy(proxy).Return(&pod, nil)
496+
mockKubeController.EXPECT().GetPodForProxy(proxy).Return(pod, nil)
497497

498498
resp, err := NewResponse(meshCatalog, proxy, nil, cfg, nil, proxyRegistry)
499499
tassert.NoError(t, err)

pkg/envoy/lds/response_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func getProxy(kubeClient kubernetes.Interface) (*envoy.Proxy, *v1.Pod, error) {
4242
newPod1.Annotations = map[string]string{
4343
constants.PrometheusScrapeAnnotation: "true",
4444
}
45-
if _, err := kubeClient.CoreV1().Pods(tests.Namespace).Create(context.TODO(), &newPod1, metav1.CreateOptions{}); err != nil {
45+
if _, err := kubeClient.CoreV1().Pods(tests.Namespace).Create(context.TODO(), newPod1, metav1.CreateOptions{}); err != nil {
4646
return nil, nil, err
4747
}
4848

@@ -62,7 +62,7 @@ func getProxy(kubeClient kubernetes.Interface) (*envoy.Proxy, *v1.Pod, error) {
6262
}
6363
}
6464

65-
return envoy.NewProxy(envoy.KindSidecar, uuid.MustParse(tests.ProxyUUID), identity.New(tests.BookbuyerServiceAccountName, tests.Namespace), nil), &newPod1, nil
65+
return envoy.NewProxy(envoy.KindSidecar, uuid.MustParse(tests.ProxyUUID), identity.New(tests.BookbuyerServiceAccountName, tests.Namespace), nil), newPod1, nil
6666
}
6767

6868
func TestNewResponse(t *testing.T) {

pkg/envoy/proxy_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var _ = Describe("Test proxy methods", func() {
2525
podUID := uuid.New().String()
2626
proxy := NewProxy(KindSidecar, proxyUUID, identity.New("svc-acc", "namespace"), tests.NewMockAddress("1.2.3.4"))
2727

28-
Context("Proxy is valid", func() {
28+
It("creates a valid proxy", func() {
2929
Expect(proxy).ToNot((BeNil()))
3030
})
3131

pkg/envoy/registry/announcement_handlers.go

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func (pr *ProxyRegistry) ReleaseCertificateHandler(certManager certificateReleas
3838
if proxyIface, ok := pr.connectedProxies.Load(proxyUUID); ok {
3939
proxy := proxyIface.(*envoy.Proxy)
4040
log.Warn().Msgf("Pod with label %s: %s found in proxy registry; releasing certificate for proxy %s", constants.EnvoyUniqueIDLabelName, proxyUUID, proxy.Identity)
41-
// NewXDSCertCommonName
4241
cn := envoy.NewXDSCertCommonName(proxy.UUID, proxy.Kind(), proxy.Identity.ToK8sServiceAccount().Name, proxy.Identity.ToK8sServiceAccount().Namespace)
4342
certManager.ReleaseCertificate(cn)
4443
} else {

pkg/envoy/registry/registry.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ func (pr *ProxyRegistry) RegisterProxy(proxy *envoy.Proxy) {
2020
}
2121

2222
// GetConnectedProxy loads a connected proxy from the registry.
23-
func (pr *ProxyRegistry) GetConnectedProxy(uuid string) (*envoy.Proxy, bool) {
23+
func (pr *ProxyRegistry) GetConnectedProxy(uuid string) *envoy.Proxy {
2424
p, ok := pr.connectedProxies.Load(uuid)
2525
if !ok {
26-
return nil, false
26+
return nil
2727
}
28-
return p.(*envoy.Proxy), true
28+
return p.(*envoy.Proxy)
2929
}
3030

3131
// UnregisterProxy unregisters the given proxy from the catalog.

pkg/envoy/registry/registry_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var _ = Describe("Test catalog proxy register/unregister", func() {
1414
proxyRegistry := NewProxyRegistry(nil, nil)
1515
proxy := envoy.NewProxy(envoy.KindSidecar, uuid.New(), identity.New("foo", "bar"), nil)
1616

17-
Context("Proxy is valid", func() {
17+
It("Proxy is valid", func() {
1818
Expect(proxy).ToNot((BeNil()))
1919
})
2020

pkg/envoy/registry/services.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@ func getCertCommonNameForPod(pod v1.Pod) (certificate.CommonName, error) {
106106
if err != nil {
107107
return "", errors.Wrapf(err, "invalid UID value for %s label", constants.EnvoyUniqueIDLabelName)
108108
}
109-
return certificate.CommonName(fmt.Sprintf("%s.%s.%s.%s.cluster.local", proxyUID, envoy.KindSidecar, pod.Spec.ServiceAccountName, pod.Namespace)), nil
109+
cn := envoy.NewXDSCertCommonName(proxyUID, envoy.KindSidecar, pod.Spec.ServiceAccountName, pod.Namespace)
110+
return cn, nil
110111
}

pkg/envoy/registry/services_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var _ = Describe("Test Proxy-Service mapping", func() {
4545
constants.EnvoyUniqueIDLabelName: proxyUUID.String(),
4646
constants.AppLabel: tests.SelectorValue})
4747
Expect(pod.Spec.ServiceAccountName).To(Equal(tests.BookstoreServiceAccountName))
48-
mockKubeController.EXPECT().ListPods().Return([]*v1.Pod{&pod}).Times(1)
48+
mockKubeController.EXPECT().ListPods().Return([]*v1.Pod{pod}).Times(1)
4949

5050
// Create the SERVICE
5151
svcName := uuid.New().String()
@@ -131,7 +131,7 @@ var _ = Describe("Test Proxy-Service mapping", func() {
131131
newPod := tests.NewPodFixture(namespace, podName, tests.BookstoreServiceAccountName, tests.PodLabels)
132132
newPod.Labels[constants.EnvoyUniqueIDLabelName] = proxyUUID.String()
133133

134-
mockKubeController.EXPECT().ListPods().Return([]*v1.Pod{&newPod}).Times(1)
134+
mockKubeController.EXPECT().ListPods().Return([]*v1.Pod{newPod}).Times(1)
135135

136136
// Create the SERVICE
137137
svcName := uuid.New().String()
@@ -221,7 +221,7 @@ var _ = Describe("Test Proxy-Service mapping", func() {
221221
},
222222
},
223223
}, nil).Times(1)
224-
actualSvcs := listServicesForPod(&pod, mockKubeController)
224+
actualSvcs := listServicesForPod(pod, mockKubeController)
225225
Expect(len(actualSvcs)).To(Equal(2))
226226

227227
actualNames := []string{actualSvcs[0].Name, actualSvcs[1].Name}
@@ -240,7 +240,7 @@ var _ = Describe("Test Proxy-Service mapping", func() {
240240

241241
mockKubeController.EXPECT().ListServices().Return([]*v1.Service{service})
242242
pod := tests.NewPodFixture(namespace, "pod-name", tests.BookstoreServiceAccountName, tests.PodLabels)
243-
actualSvcs := listServicesForPod(&pod, mockKubeController)
243+
actualSvcs := listServicesForPod(pod, mockKubeController)
244244
Expect(len(actualSvcs)).To(Equal(0))
245245
})
246246

@@ -263,7 +263,7 @@ var _ = Describe("Test Proxy-Service mapping", func() {
263263

264264
mockKubeController.EXPECT().ListServices().Return([]*v1.Service{service})
265265
pod := tests.NewPodFixture(namespace, "pod-name", tests.BookstoreServiceAccountName, tests.PodLabels)
266-
actualSvcs := listServicesForPod(&pod, mockKubeController)
266+
actualSvcs := listServicesForPod(pod, mockKubeController)
267267
Expect(len(actualSvcs)).To(Equal(0))
268268
})
269269
})

pkg/errcode/errcode.go

-9
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,6 @@ const (
203203
// ErrStartingADSServer indicates the gPRC service failed to start
204204
ErrStartingADSServer
205205

206-
// ERRInitializingProxy indicates an instance of the Envoy proxy that connected to the XDS server could not be
207-
// initialized
208-
ErrInitializingProxy
209-
210206
// ErrMismatchedServiceAccount inicates the ServiceAccount referenced in the NodeID does not match the
211207
// ServiceAccount specified in the proxy certificate
212208
ErrMismatchedServiceAccount
@@ -648,11 +644,6 @@ a new snapshot in the Envoy xDS Aggregate Discovery Services cache.
648644

649645
ErrStartingADSServer: `
650646
The Aggregate Discovery Server (ADS) created by the OSM controller failed to start.
651-
`,
652-
653-
ErrInitializingProxy: `
654-
An Envoy proxy data structure representing a newly connected envoy proxy to the XDS
655-
server could not be initialized.
656647
`,
657648

658649
ErrMismatchedServiceAccount: `

pkg/injector/patch_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func TestCreatePatch(t *testing.T) {
164164
Object: runtime.RawExtension{Raw: raw},
165165
DryRun: &tc.dryRun,
166166
}
167-
rawPatches, err := wh.createPatch(&pod, req, proxyUUID)
167+
rawPatches, err := wh.createPatch(pod, req, proxyUUID)
168168
assert.NoError(err)
169169
patches := string(rawPatches)
170170

@@ -200,7 +200,7 @@ func TestCreatePatch(t *testing.T) {
200200
}
201201

202202
newUUID := uuid.New()
203-
rawPatches, err = wh.createPatch(&pod, req, newUUID)
203+
rawPatches, err = wh.createPatch(pod, req, newUUID)
204204
assert.NoError(err)
205205

206206
patches = string(rawPatches)
@@ -259,7 +259,7 @@ func TestCreatePatch(t *testing.T) {
259259
Namespace: namespace,
260260
Object: runtime.RawExtension{Raw: raw},
261261
}
262-
_, err = wh.createPatch(&pod, req, proxyUUID)
262+
_, err = wh.createPatch(pod, req, proxyUUID)
263263
assert.Error(err)
264264
})
265265
}

pkg/k8s/client.go

+10-22
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,6 @@ import (
3030
"github.com/openservicemesh/osm/pkg/service"
3131
)
3232

33-
var (
34-
// ErrMoreThanOnePodForUUID is an error for when OSM finds more than one pod for a given xDS certificate. There should always be exactly one Pod for a given xDS certificate.
35-
ErrMoreThanOnePodForUUID = errors.New("found more than one pod for xDS uuid")
36-
37-
// ErrDidNotFindPodForUUID is an error for when OSM cannot not find a pod for the given xDS certificate.
38-
ErrDidNotFindPodForUUID = errors.New("did not find pod for uuid")
39-
40-
// ErrServiceAccountDoesNotMatchProxy is an error for when the service account of a Pod does not match the xDS certificate.
41-
ErrServiceAccountDoesNotMatchProxy = errors.New("service account does not match proxy")
42-
43-
// ErrNamespaceDoesNotMatchProxy is an error for when the namespace of the Pod does not match the xDS certificate.
44-
ErrNamespaceDoesNotMatchProxy = errors.New("namespace does not match proxy")
45-
)
46-
4733
// NewKubernetesController returns a new kubernetes.Controller which means to provide access to locally-cached k8s resources
4834
func NewKubernetesController(kubeClient kubernetes.Interface, policyClient policyv1alpha1Client.Interface, meshName string,
4935
stop <-chan struct{}, msgBroker *messaging.Broker, selectInformers ...InformerKey) (Controller, error) {
@@ -470,7 +456,7 @@ func (c client) GetPodForProxy(proxy *envoy.Proxy) (*v1.Pod, error) {
470456
log.Error().Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrFetchingPodFromCert)).
471457
Msgf("Did not find Pod with label %s = %s in namespace %s",
472458
constants.EnvoyUniqueIDLabelName, proxyUUID, svcAccount.Namespace)
473-
return nil, ErrDidNotFindPodForUUID
459+
return nil, errDidNotFindPodForUUID
474460
}
475461

476462
// Each pod is assigned a unique UUID at the time of sidecar injection.
@@ -482,25 +468,27 @@ func (c client) GetPodForProxy(proxy *envoy.Proxy) (*v1.Pod, error) {
482468
log.Error().Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrPodBelongsToMultipleServices)).
483469
Msgf("Found more than one pod with label %s = %s in namespace %s. There can be only one!",
484470
constants.EnvoyUniqueIDLabelName, proxyUUID, svcAccount.Namespace)
485-
return nil, ErrMoreThanOnePodForUUID
471+
return nil, errMoreThanOnePodForUUID
486472
}
487473

488474
pod := pods[0]
489475
log.Trace().Msgf("Found Pod with UID=%s for proxyID %s", pod.ObjectMeta.UID, proxyUUID)
490476

491477
if pod.Namespace != svcAccount.Namespace {
492-
log.Warn().Msgf("Pod with UID=%s belongs to Namespace %s. The pod's xDS certificate was issued for Namespace %s",
493-
pod.ObjectMeta.UID, pod.Namespace, svcAccount.Namespace)
494-
return nil, ErrNamespaceDoesNotMatchProxy
478+
log.Warn().Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrFetchingPodFromCert)).
479+
Msgf("Pod with UID=%s belongs to Namespace %s. The pod's xDS certificate was issued for Namespace %s",
480+
pod.ObjectMeta.UID, pod.Namespace, svcAccount.Namespace)
481+
return nil, errNamespaceDoesNotMatchProxy
495482
}
496483

497484
// Ensure the Name encoded in the certificate matches that of the Pod
498485
// TODO(draychev): check that the Kind matches too! [https://github.com/openservicemesh/osm/issues/3173]
499486
if pod.Spec.ServiceAccountName != svcAccount.Name {
500487
// Since we search for the pod in the namespace we obtain from the certificate -- these namespaces will always match.
501-
log.Warn().Msgf("Pod with UID=%s belongs to ServiceAccount=%s. The pod's xDS certificate was issued for ServiceAccount=%s",
502-
pod.ObjectMeta.UID, pod.Spec.ServiceAccountName, svcAccount)
503-
return nil, ErrServiceAccountDoesNotMatchProxy
488+
log.Warn().Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrFetchingPodFromCert)).
489+
Msgf("Pod with UID=%s belongs to ServiceAccount=%s. The pod's xDS certificate was issued for ServiceAccount=%s",
490+
pod.ObjectMeta.UID, pod.Spec.ServiceAccountName, svcAccount)
491+
return nil, errServiceAccountDoesNotMatchProxy
504492
}
505493

506494
return &pod, nil

pkg/k8s/client_test.go

+16-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package k8s
22

33
import (
4-
"context"
54
"testing"
65

76
"github.com/golang/mock/gomock"
@@ -1033,12 +1032,8 @@ func TestK8sServicesToMeshServices(t *testing.T) {
10331032

10341033
func TestGetPodForProxy(t *testing.T) {
10351034
assert := tassert.New(t)
1036-
kubeClient := fake.NewSimpleClientset()
10371035
stop := make(chan struct{})
1038-
kubeController, err := NewKubernetesController(kubeClient, nil, testMeshName, stop, messaging.NewBroker(nil))
1039-
assert.Nil(err)
1040-
1041-
ctx := context.Background()
1036+
defer close(stop)
10421037

10431038
proxyUUID := uuid.New()
10441039
someOtherEnvoyUID := uuid.New()
@@ -1052,23 +1047,17 @@ func TestGetPodForProxy(t *testing.T) {
10521047
constants.EnvoyUniqueIDLabelName: someOtherEnvoyUID.String(),
10531048
}
10541049

1055-
newPod0 := tests.NewPodFixture(namespace, "pod-0", tests.BookstoreServiceAccountName, someOthePodLabels)
1056-
_, err = kubeClient.CoreV1().Pods(namespace).Create(ctx, &newPod0, metav1.CreateOptions{})
1057-
assert.NoError(err)
1058-
1059-
newPod1 := tests.NewPodFixture(namespace, "pod-1", tests.BookstoreServiceAccountName, podlabels)
1060-
_, err = kubeClient.CoreV1().Pods(namespace).Create(ctx, &newPod1, metav1.CreateOptions{})
1061-
assert.NoError(err)
1050+
pod := tests.NewPodFixture(namespace, "pod-1", tests.BookstoreServiceAccountName, podlabels)
1051+
kubeClient := fake.NewSimpleClientset(
1052+
monitoredNS(namespace),
1053+
monitoredNS("bad-namespace"),
1054+
tests.NewPodFixture(namespace, "pod-0", tests.BookstoreServiceAccountName, someOthePodLabels),
1055+
pod,
1056+
tests.NewPodFixture(namespace, "pod-2", tests.BookstoreServiceAccountName, someOthePodLabels),
1057+
)
10621058

1063-
newPod2 := tests.NewPodFixture(namespace, "pod-2", tests.BookstoreServiceAccountName, someOthePodLabels)
1064-
_, err = kubeClient.CoreV1().Pods(namespace).Create(ctx, &newPod2, metav1.CreateOptions{})
1065-
assert.NoError(err)
1066-
1067-
_, err = kubeClient.CoreV1().Namespaces().Create(ctx, monitoredNS(namespace), metav1.CreateOptions{})
1068-
assert.NoError(err)
1069-
1070-
_, err = kubeClient.CoreV1().Namespaces().Create(ctx, monitoredNS("bad-namespace"), metav1.CreateOptions{})
1071-
assert.NoError(err)
1059+
kubeController, err := NewKubernetesController(kubeClient, nil, testMeshName, stop, messaging.NewBroker(nil))
1060+
assert.Nil(err)
10721061

10731062
testCases := []struct {
10741063
name string
@@ -1079,26 +1068,26 @@ func TestGetPodForProxy(t *testing.T) {
10791068
{
10801069
name: "fails when UUID does not match",
10811070
proxy: envoy.NewProxy(envoy.KindSidecar, uuid.New(), tests.BookstoreServiceIdentity, nil),
1082-
err: ErrDidNotFindPodForUUID,
1071+
err: errDidNotFindPodForUUID,
10831072
},
10841073
{
10851074
name: "fails when service account does not match certificate",
10861075
proxy: &envoy.Proxy{UUID: proxyUUID, Identity: identity.New("bad-name", namespace)},
1087-
err: ErrServiceAccountDoesNotMatchProxy,
1076+
err: errServiceAccountDoesNotMatchProxy,
10881077
},
10891078
{
10901079
name: "2 pods with same uuid",
10911080
proxy: envoy.NewProxy(envoy.KindSidecar, someOtherEnvoyUID, tests.BookstoreServiceIdentity, nil),
1092-
err: ErrMoreThanOnePodForUUID,
1081+
err: errMoreThanOnePodForUUID,
10931082
},
10941083
{
10951084
name: "fails when namespace does not match certificate",
10961085
proxy: envoy.NewProxy(envoy.KindSidecar, proxyUUID, identity.New(tests.BookstoreServiceAccountName, "bad-namespace"), nil),
1097-
err: ErrNamespaceDoesNotMatchProxy,
1086+
err: errNamespaceDoesNotMatchProxy,
10981087
},
10991088
{
11001089
name: "works as expected",
1101-
pod: &newPod1,
1090+
pod: pod,
11021091
proxy: envoy.NewProxy(envoy.KindSidecar, proxyUUID, tests.BookstoreServiceIdentity, nil),
11031092
},
11041093
}

0 commit comments

Comments
 (0)