-
Couldn't load subscription status.
- Fork 259
ci: add fqdn with cilium local redirect policy test #3543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits Select commit Hold shift + click to select a range
a2d0a20 refactor lrp setup
QxBytes dc603d9 create lrp test case func
QxBytes 1231468 add k8 boilerplate for cnp
QxBytes eee637a add lrp fqdn test and yaml
QxBytes fe3aea4 address linter issue
QxBytes e7fa7d8 address feedback
QxBytes 3591a97 address feedback
QxBytes 4f6b97c add case without explicit dns server
QxBytes 9230d52 improve debug message
QxBytes f9dd905 adjust test domain name
QxBytes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| //go:build lrp | ||
| | ||
| package lrp | ||
| | ||
| import ( | ||
| "context" | ||
| "testing" | ||
| | ||
| "github.com/Azure/azure-container-networking/test/internal/kubernetes" | ||
| ciliumClientset "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
| | ||
| var ( | ||
| fqdnCNPPath = ciliumManifestsDir + "fqdn-cnp.yaml" | ||
| enableFQDNFlag = "enable-l7-proxy" | ||
| ) | ||
| | ||
| // TestLRPFQDN tests if the local redirect policy in a cilium cluster is functioning with a | ||
| // FQDN Cilium Network Policy. As such, enable-l7-proxy should be enabled in the config | ||
| // The test assumes the current kubeconfig points to a cluster with cilium, cns, | ||
| // and kube-dns already installed. The lrp feature flag should also be enabled in the cilium config | ||
| // Does not check if cluster is in a stable state | ||
| // Resources created are automatically cleaned up | ||
| // From the lrp folder, run: go test ./ -v -tags "lrp" -run ^TestLRPFQDN$ | ||
| func TestLRPFQDN(t *testing.T) { | ||
| ctx := context.Background() | ||
| | ||
| selectedPod, cleanupFn := setupLRP(t, ctx) | ||
| defer cleanupFn() | ||
| require.NotNil(t, selectedPod) | ||
| | ||
| cs := kubernetes.MustGetClientset() | ||
| config := kubernetes.MustGetRestConfig() | ||
| ciliumCS, err := ciliumClientset.NewForConfig(config) | ||
| require.NoError(t, err) | ||
| | ||
| // ensure enable l7 proxy flag is enabled | ||
| ciliumCM, err := kubernetes.GetConfigmap(ctx, cs, kubeSystemNamespace, ciliumConfigmapName) | ||
| require.NoError(t, err) | ||
| require.Equal(t, "true", ciliumCM.Data[enableFQDNFlag], "enable-l7-proxy not set to true in cilium-config") | ||
vipul-21 marked this conversation as resolved. Show resolved Hide resolved | ||
| | ||
| _, cleanupCNP := kubernetes.MustSetupCNP(ctx, ciliumCS, fqdnCNPPath) | ||
| defer cleanupCNP() | ||
| | ||
| tests := []struct { | ||
| name string | ||
| command []string | ||
| expectedMsgContains string | ||
| expectedErrMsgContains string | ||
| shouldError bool | ||
| countIncreases bool | ||
| }{ | ||
| { | ||
| name: "nslookup google succeeds", | ||
| command: []string{"nslookup", "www.google.com", "10.0.0.10"}, | ||
| countIncreases: true, | ||
| shouldError: false, | ||
| }, | ||
| { | ||
| name: "nslookup google succeeds without explicit dns server", | ||
| command: []string{"nslookup", "www.google.com"}, | ||
| countIncreases: true, | ||
| shouldError: false, | ||
| }, | ||
| { | ||
| name: "wget google succeeds", | ||
| command: []string{"wget", "-O", "index.html", "www.google.com", "--timeout=5"}, | ||
| expectedErrMsgContains: "saved", | ||
| countIncreases: true, | ||
| shouldError: false, | ||
| }, | ||
| { | ||
| name: "nslookup cloudflare succeeds", | ||
| command: []string{"nslookup", "www.cloudflare.com", "10.0.0.10"}, | ||
| countIncreases: true, | ||
| shouldError: false, | ||
| }, | ||
| { | ||
| name: "wget cloudflare fails but dns succeeds", | ||
| command: []string{"wget", "-O", "index.html", "www.cloudflare.com", "--timeout=5"}, | ||
| expectedErrMsgContains: "timed out", | ||
| countIncreases: true, | ||
| shouldError: true, | ||
| }, | ||
| { | ||
| name: "nslookup example fails", | ||
| command: []string{"nslookup", "www.example.com", "10.0.0.10"}, | ||
| expectedMsgContains: "REFUSED", | ||
| countIncreases: false, | ||
| shouldError: true, | ||
| }, | ||
| { | ||
| // won't be able to nslookup, let alone query the website | ||
| name: "wget example fails", | ||
| command: []string{"wget", "-O", "index.html", "www.example.com", "--timeout=5"}, | ||
| expectedErrMsgContains: "bad address", | ||
vipul-21 marked this conversation as resolved. Show resolved Hide resolved | ||
| countIncreases: false, | ||
| shouldError: true, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| tt := tt | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| testLRPCase(t, ctx, *selectedPod, tt.command, tt.expectedMsgContains, tt.expectedErrMsgContains, tt.shouldError, tt.countIncreases) | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| apiVersion: "cilium.io/v2" | ||
| kind: CiliumNetworkPolicy | ||
| metadata: | ||
| name: "to-fqdn" | ||
| namespace: "default" | ||
| spec: | ||
| endpointSelector: | ||
| matchLabels: | ||
| lrp-test: "true" | ||
| egress: | ||
| - toEndpoints: | ||
| - matchLabels: | ||
| "k8s:io.kubernetes.pod.namespace": kube-system | ||
| "k8s:k8s-app": node-local-dns | ||
| toPorts: | ||
| - ports: | ||
| - port: "53" | ||
| protocol: UDP | ||
| rules: | ||
| dns: | ||
| - matchPattern: "*.google.com" | ||
| - matchPattern: "*.cloudflare.com" | ||
| - toFQDNs: | ||
| - matchPattern: "*.google.com" |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.