Skip to content

Commit 68d1ace

Browse files
committed
minor docs changes
1 parent 9e79181 commit 68d1ace

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

README.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ The following diagram illustrates the flow of a network packet from the kernel t
1919

2020
The key components of the architecture are:
2121

22-
* **Dataplane Controller**: The dataplane/controller.go file contains the main controller that sets up NFQUEUE, intercepts packets, and orchestrates the policy evaluation process. It is responsible for creating the necessary nftables rules to redirect traffic. To avoid the performance penalty of sending all packets to userspace, the controller includes logic to only capture packets for pods that are targeted by at least one network policy.
23-
* **Policy Engine**: The networkpolicy/engine.go file defines the PolicyEngine, which manages a pipeline of PolicyEvaluator plugins. The engine is responsible for running each packet through the pipeline and making a final decision based on the verdicts returned by the evaluators.
24-
* **Pod Info Provider**: The podinfo/podinfo.go file provides an interface for retrieving pod information. It resolves a packet's IP address to a PodInfo protobuf type (pkg/api/kubenetworkpolicies.proto). This PodInfo object contains all the necessary information for evaluators to match policies, including the pod's name, labels, namespace, and associated node information.
22+
* **Dataplane Controller**: The `dataplane/controller.go` file contains the main controller that sets up NFQUEUE, intercepts packets, and orchestrates the policy evaluation process. It is responsible for creating the necessary nftables rules to redirect traffic. To avoid the performance penalty of sending all packets to userspace, the controller includes logic to only capture packets for pods that are targeted by at least one network policy.
23+
* **Policy Engine**: The `networkpolicy/engine.go` file defines the `PolicyEngine`, which manages a pipeline of `PolicyEvaluator` plugins. The engine is responsible for running each packet through the pipeline and making a final decision based on the verdicts returned by the evaluators.
24+
* **Pod Info Provider**: The `podinfo/podinfo.go` file provides an interface for retrieving pod information. It resolves a packet's IP address to a PodInfo protobuf type (`pkg/api/kubenetworkpolicies.proto`). This `PodInfo` object contains all the necessary information for evaluators to match policies, including the pod's name, labels, namespace, and associated node information.
2525
* **Policy Evaluators**: These are plugins that implement the PolicyEvaluator interface and contain the logic for a specific type of network policy. The project currently includes evaluators for AdminNetworkPolicy, BaselineAdminNetworkPolicy, and the standard Kubernetes NetworkPolicy.
2626

2727
Here is a diagram illustrating the interaction between these components:
@@ -32,7 +32,7 @@ Here is a diagram illustrating the interaction between these components:
3232

3333
The PolicyEvaluator interface is the core of the policy evaluation pipeline. Each evaluator is responsible for determining whether a packet should be allowed, denied, or passed to the next evaluator in the pipeline.
3434

35-
The interface is defined in pkg/networkpolicy/engine.go as follows:
35+
The interface is defined in `pkg/networkpolicy/engine.go` as follows:
3636

3737
```go
3838
type PolicyEvaluator interface {
@@ -44,23 +44,23 @@ type PolicyEvaluator interface {
4444

4545
The Verdict returned by each evaluator can be one of the following:
4646

47-
* VerdictAccept: The packet is allowed, and no further evaluators are consulted.
48-
* VerdictDeny: The packet is denied, and no further evaluators are consulted.
49-
* VerdictNext: The packet is passed to the next evaluator in the pipeline.
47+
* `VerdictAccept`: The packet is allowed, and no further evaluators are consulted.
48+
* `VerdictDeny`: The packet is denied, and no further evaluators are consulted.
49+
* `VerdictNext`: The packet is passed to the next evaluator in the pipeline.
5050

5151
### How to Add a New PolicyEvaluator
5252

53-
Adding a new PolicyEvaluator is straightforward and involves the following steps:
53+
Adding a new `PolicyEvaluator` is straightforward and involves the following steps:
5454

55-
1. **Create a new file** for your evaluator in the pkg/networkpolicy directory.
56-
2. **Define a struct** for your evaluator that implements the PolicyEvaluator interface.
57-
3. **Implement the Name method** to return a unique name for your evaluator.
58-
4. **Implement the EvaluateIngress and EvaluateEgress methods** to define the logic for your policy.
59-
5. **Register your new evaluator** in the PolicyEngine in cmd/main.go.
55+
1. **Create a new file** for your evaluator in the `pkg/networkpolicy` directory.
56+
2. **Define a struct** for your evaluator that implements the `PolicyEvaluator` interface.
57+
3. **Implement the Name method** to return a unique name for your evaluator.
58+
4. **Implement the EvaluateIngress and EvaluateEgress methods** to define the logic for your policy.
59+
5. **Register your new evaluator** in the PolicyEngine in `cmd/main.go`.
6060

6161
#### Example: Creating an AllowListPolicy
6262

63-
Let's create a simple AllowListPolicy that only allows traffic from a predefined list of IP addresses.
63+
Let's create a simple `AllowListPolicy` that only allows traffic from a predefined list of IP addresses.
6464

6565
1. **Create the file** pkg/networkpolicy/allowlistpolicy.go:
6666

@@ -76,36 +76,36 @@ Let's create a simple AllowListPolicy that only allows traffic from a predefined
7676

7777
// AllowListPolicy is a simple policy that allows traffic only from a predefined list of IP addresses.
7878
type AllowListPolicy struct {
79-
allowedIPs \[\]net.IP
79+
allowedIPs []net.IP
8080
}
8181

8282
// NewAllowListPolicy creates a new AllowListPolicy.
83-
func NewAllowListPolicy(allowedIPs \[\]net.IP) \*AllowListPolicy {
84-
return \&AllowListPolicy{
83+
func NewAllowListPolicy(allowedIPs []net.IP) *AllowListPolicy {
84+
return &AllowListPolicy{
8585
allowedIPs: allowedIPs,
8686
}
8787
}
8888

89-
func (a \*AllowListPolicy) Name() string {
90-
return "AllowListPolicy"
89+
func (a *AllowListPolicy) Name() string {
90+
return "AllowListPolicy"
9191
}
9292

93-
func (a \*AllowListPolicy) EvaluateIngress(ctx context.Context, p \*network.Packet, srcPod, dstPod \*api.PodInfo) (Verdict, error) {
94-
for \_, ip := range a.allowedIPs {
93+
func (a *AllowListPolicy) EvaluateIngress(ctx context.Context, p *network.Packet, srcPod, dstPod *api.PodInfo) (Verdict, error) {
94+
for \_, ip := range a.allowedIPs {
9595
if ip.Equal(p.SrcIP) {
9696
return VerdictAccept, nil
9797
}
9898
}
9999
return VerdictDeny, nil
100100
}
101101

102-
func (a \*AllowListPolicy) EvaluateEgress(ctx context.Context, p \*network.Packet, srcPod, dstPod \*api.PodInfo) (Verdict, error) {
103-
// This policy only applies to ingress traffic.
104-
return VerdictNext, nil
102+
func (a *AllowListPolicy) EvaluateEgress(ctx context.Context, p *network.Packet, srcPod, dstPod *api.PodInfo) (Verdict, error) {
103+
// This policy only applies to ingress traffic.
104+
return VerdictNext, nil
105105
}
106106
```
107107

108-
2. **Register the new evaluator** in cmd/main.go:
108+
2. **Register the new evaluator** in `cmd/main.go`:
109109

110110
```go
111111
// ... (imports)
@@ -116,11 +116,11 @@ Let's create a simple AllowListPolicy that only allows traffic from a predefined
116116
// Create the evaluators for the Pipeline to process the packets
117117
// and take a network policy action. The evaluators are processed
118118
// by the order in the array.
119-
evaluators := \[\]networkpolicy.PolicyEvaluator{}
119+
evaluators := []networkpolicy.PolicyEvaluator{}
120120

121-
// Add the new AllowListPolicy evaluator
122-
allowedIPs := \[\]net.IP{net.ParseIP("10.0.0.1"), net.ParseIP("10.0.0.2")}
123-
evaluators \= append(evaluators, networkpolicy.NewAllowListPolicy(allowedIPs))
121+
// Add the new AllowListPolicy evaluator
122+
allowedIPs := []net.IP{net.ParseIP("10.0.0.1"), net.ParseIP("10.0.0.2")}
123+
evaluators = append(evaluators, networkpolicy.NewAllowListPolicy(allowedIPs))
124124

125125
// ... (rest of the evaluators)
126126

@@ -179,7 +179,7 @@ helm install kube-network-policies -n kube-system charts/kube-network-policies
179179

180180
Admin Network Policies and Baseline Admin Network Policies features are controlled by `Values.adminNetworkPolicy` and
181181
they are enabled by default. Disable them if needed in values.yaml or use `--set adminNetworkPolicy=false` when running
182-
`helm install` command.
182+
`helm install` command.
183183

184184
NOTE: the corresponding CRDs must be installed first.
185185

@@ -229,7 +229,7 @@ Current implemented metrics are:
229229

230230
## Testing
231231

232-
See [TESTING](docs/testing/README.md)
232+
See [TESTING](docs/testing/README.md)
233233

234234
There are two github workflows that runs e2e tests aginst the Kubernetes/Kubernetes Network Policy tests and the Network Policy API Working Group conformance tests.
235235

0 commit comments

Comments
 (0)