Skip to content

Commit 51e0d16

Browse files
committed
added readme, go mod, go sum, and comments saying why target port will never be undefined
1 parent c72b33c commit 51e0d16

File tree

5 files changed

+677
-0
lines changed

5 files changed

+677
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Azure NPM to Cilium Validator
2+
3+
This tool validates the migration from Azure NPM to Cilium.
4+
5+
## Prerequisites
6+
7+
- Go 1.16 or later
8+
- A Kubernetes cluster with Azure NPM installed
9+
10+
## Installation
11+
12+
Clone the repository and navigate to the tool directory:
13+
14+
```bash
15+
git clone https://github.com/Azure/azure-container-networking.git
16+
cd azure-container-networking/tools/azure-npm-to-cilium-validator
17+
```
18+
19+
## Setting Up Dependencies
20+
21+
Initialize the Go module and download dependencies:
22+
23+
```bash
24+
go mod tidy
25+
go mod vendor
26+
```
27+
28+
## Running the Tool
29+
30+
Run the following command with the path to your kube config file with the cluster you want to validate.
31+
32+
```bash
33+
go run azure-npm-to-cilium-validator.go --kubeconfig ~/.kube/config
34+
```
35+
36+
This will execute the validator and print the migration summary.
37+
38+
## Running Tests
39+
40+
To run the tests for the Azure NPM to Cilium Validator, use the following command in the azure-npm-to-cilium-validator directory:
41+
42+
```bash
43+
go test .
44+
```
45+
46+
This will execute all the test files in the directory and provide a summary of the test results.

tools/azure-npm-to-cilium-validator/azure-npm-to-cilium-validator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ func checkServiceTargetPortMatchPolicyPorts(servicePorts []corev1.ServicePort, p
317317
if int(policyPort.Port.IntVal) == 0 {
318318
return false
319319
}
320+
// Check if the service target port and protocol matches the policy port and protocol
321+
// Note that the service target port will never been undefined as it defaults to port which is a required field when Ports is defined
320322
if servicePort.TargetPort.IntValue() == int(policyPort.Port.IntVal) && string(servicePort.Protocol) == string(*policyPort.Protocol) {
321323
matchedserviceTargetPortToPolicyPort = true
322324
break

tools/azure-npm-to-cilium-validator/azure-npm-to-cilium-validator_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,7 @@ func TestGetExternalTrafficPolicyClusterServices(t *testing.T) {
15671567
},
15681568
// add ut where target port is nil
15691569
// add a ut where target port matches to portocol
1570+
// add a ut where the port is 0
15701571

15711572
// Scenarios where there are LoadBalancer or NodePort services with externalTrafficPolicy=Cluster and there are multiple policies
15721573

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module azure-npm-to-cilium-validator
2+
3+
go 1.16
4+
5+
require (
6+
k8s.io/api v0.23.0
7+
k8s.io/apimachinery v0.23.0
8+
k8s.io/client-go v0.23.0
9+
)

0 commit comments

Comments
 (0)