This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 279
/
connectivity_pod_to_pod.go
87 lines (78 loc) · 2.7 KB
/
connectivity_pod_to_pod.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package verifier
import (
"fmt"
"io"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
configv1alpha2 "github.com/openservicemesh/osm/pkg/apis/config/v1alpha2"
)
// TrafficAttribute describes the attributes of the traffic
type TrafficAttribute struct {
SrcPod *types.NamespacedName
SrcService *types.NamespacedName
DstPod *types.NamespacedName
DstService *types.NamespacedName
IngressBackend *types.NamespacedName
DstPort uint16
ExternalHost string
ExternalPort uint16
AppProtocol string
IsIngress bool
}
// PodConnectivityVerifier implements the Verifier interface for pod connectivity
type PodConnectivityVerifier struct {
stdout io.Writer
stderr io.Writer
kubeClient kubernetes.Interface
meshConfig *configv1alpha2.MeshConfig
trafficAttr TrafficAttribute
srcPodConfigGetter ConfigGetter
dstPodConfigGetter ConfigGetter
meshName string
}
// NewPodConnectivityVerifier implements verification for pod connectivity
func NewPodConnectivityVerifier(stdout io.Writer, stderr io.Writer, restConfig *rest.Config, kubeClient kubernetes.Interface,
meshConfig *configv1alpha2.MeshConfig, trafficAttr TrafficAttribute,
meshName string) Verifier {
return &PodConnectivityVerifier{
stdout: stdout,
stderr: stderr,
kubeClient: kubeClient,
meshConfig: meshConfig,
trafficAttr: trafficAttr,
srcPodConfigGetter: &PodConfigGetter{
restConfig: restConfig,
kubeClient: kubeClient,
pod: *trafficAttr.SrcPod,
},
dstPodConfigGetter: &PodConfigGetter{
restConfig: restConfig,
kubeClient: kubeClient,
pod: *trafficAttr.DstPod,
},
meshName: meshName,
}
}
// Run executes the pod connectivity verifier
func (v *PodConnectivityVerifier) Run() Result {
ctx := fmt.Sprintf("Verify if pod %q can access pod %q for service %q", v.trafficAttr.SrcPod, v.trafficAttr.DstPod, v.trafficAttr.DstService)
verifiers := Set{
//
// Namespace monitor verification
NewNamespaceMonitorVerifier(v.stdout, v.stderr, v.kubeClient, v.trafficAttr.SrcPod.Namespace, v.meshName),
NewNamespaceMonitorVerifier(v.stdout, v.stderr, v.kubeClient, v.trafficAttr.DstPod.Namespace, v.meshName),
//
// Envoy sidecar verification
NewSidecarVerifier(v.stdout, v.stderr, v.kubeClient, *v.trafficAttr.SrcPod),
NewSidecarVerifier(v.stdout, v.stderr, v.kubeClient, *v.trafficAttr.DstPod),
//
// Envoy config verification
NewEnvoyConfigVerifier(v.stdout, v.stderr, v.kubeClient, v.meshConfig, configAttribute{
trafficAttr: v.trafficAttr,
srcConfigGetter: v.srcPodConfigGetter,
dstConfigGetter: v.dstPodConfigGetter,
}),
}
return verifiers.Run(ctx)
}