-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from liornoy/fix-open-issues
Fix open issues
- Loading branch information
Showing
11 changed files
with
733 additions
and
777 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
e2etest/artifacts/* | ||
!e2etest/artifacts/.gitkeep | ||
communication-matrix/* | ||
commatrix-gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,56 @@ | ||
## commatrix | ||
|
||
This go library provide tools to produce k8s node communication matrix, i.e. | ||
a file that describes what ports the cluster listens to. | ||
This project allows to automatically generate an accurate and up-to-date communication | ||
flows matrix that can be delivered to customers as part of product documentation for all | ||
ingress flows of OpenShift (multi-node and single-node deployments). | ||
|
||
We produce this matrix from the existing EndpointSlieces, and in order to fetch | ||
the relevant ones, the `endpointslices` package provide various querying methods. | ||
### Usage of the EndpointSlice Resource | ||
|
||
This library leverages the EndpointSlice resource to identify the ports the | ||
cluster uses for ingress traffic. Relevant EndpointSlices include those | ||
referencing host-networked pods, Node Port services, and LoadBalancer services. | ||
|
||
### e2etest: | ||
To invoke the e2etest, start by exporting the "KUBECONFIG" variable, and then run 'make e2etest.' This test will generate two matrices: | ||
One from the EndpointSlices when the host services are manually produced using the 'customEndpointSlices.json' file. | ||
The other matrix is generated by running 'ss' on the nodes. | ||
The test is expected to fail. You can find the output of the 'ss' command for each node and protocol, | ||
as well as the raw communication matrices in the 'e2etest/artifacts' directory, and the diff will be printed as part of the test output. | ||
|
||
### Communication Matrix Creation Guide | ||
|
||
The Communication Matrix is a structured list of Communication Details, | ||
with each `ComDetails` entry representing a port. The fields for each entry | ||
include `Direction` (currently "ingress" only), `Protocol` ("TCP" or "UDP"), | ||
`Port` (number), `NodeRole` ("master" or "worker"), `ServiceName`, | ||
and `Required` (false if optional). | ||
|
||
Struct Definitions: | ||
### Creating Custom ComDetails with ss Command | ||
|
||
The `ss` command, a Linux utility, lists listening ports on | ||
the host with `ss -anplt` for TCP or `ss -anplu` for UDP. | ||
For example, consider the following ss entry: | ||
``` | ||
type ComMatrix struct { | ||
Matrix []ComDetails | ||
} | ||
type ComDetails struct { | ||
Direction string `json:"direction"` | ||
Protocol string `json:"protocol"` | ||
Port string `json:"port"` | ||
NodeRole string `json:"nodeRole"` | ||
ServiceName string `json:"serviceName"` | ||
Required bool `json:"required"` | ||
} | ||
LISTEN 0 4096 127.0.0.1:10248 0.0.0.0:* users:(("kubelet",pid=6187,fd=20)) | ||
``` | ||
|
||
#### Usage of EndpointSlice Resource | ||
|
||
This library leverages the EndpointSlice resource to identify the ports the | ||
cluster uses for ingress traffic. Relevant EndpointSlices include those | ||
referencing host-networked pods, Node Port services, LoadBalancer services, | ||
or any custom EndpointSlice labeled with `"ingress":""`. | ||
The `ss` package provides the `CreateComDetailsFromNode` function that runs | ||
the `ss` command on each node, and converts the output into a corresponding ComDetails list. | ||
|
||
Explore the example in `/examples/query_endpointslices/main.go`. | ||
|
||
#### Creating Custom ComDetails with ss Command | ||
|
||
To encompass all ports Kubernetes nodes are listening to, querying existing | ||
EndpointSlices may be insufficient. Not all services, like the SSH service, | ||
are represented. The `ss` command, a Linux utility, lists listening ports on | ||
the host with `ss -anplt` for TCP or `ss -anplu` for UDP. | ||
### Communication Matrix Creation Guide | ||
|
||
The `ss` package provides the `ToComDetails` function, converting `ss` command | ||
output into a corresponding ComDetails list. Use the `ToEndpointSlice` method | ||
to create an EndpointSlice object from this list. | ||
Use the `generate` Makefile target to create the matrix. | ||
The following environment variables are used to configure: | ||
``` | ||
FORMAT (csv/json/yaml) | ||
CLUSTER_ENV (baremetal/aws) | ||
DEST_DIR (path to the directory containing the artifacts) | ||
DEPLOYMENT (mno/sno) | ||
``` | ||
|
||
As a convention, EndpointSlices referencing non-critical services are labeled with `"optional": ""`. | ||
The generated artifcats are: | ||
``` | ||
communication-matrix - The generated communication matrix. | ||
ss-generated-matrix - The communication matrix that generated by the `ss` command. | ||
matrix-diff-ss - Shows the variance between two matrices. Entries present in the communication matrix but absent in the ss matrix are marked with '+', while entries present in the ss matrix but not in the communication matrix are marked with '-'. | ||
raw-ss-tcp - The raw `ss` output for TCP. | ||
raw-ss-udp - The raw `ss` output for UDP. | ||
``` | ||
|
||
Check the example in `/examples/create_custom_endpointslices/main.go` for a practical demonstration. | ||
Each record describes a flow with the following information: | ||
``` | ||
direction Data flow direction (currently ingress only) | ||
protocol IP protocol (TCP/UDP/SCTP/etc) | ||
port Flow port number | ||
namespace EndpointSlice Namespace | ||
service EndpointSlice owner Service name | ||
pod EndpointSlice target Pod name | ||
container Port owner Container name | ||
nodeRole Service node host role (master/worker/master&worker[for SNO]) | ||
optional Optional or mandatory flow for OpenShift | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.