Skip to content
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

Implement FromCIDR ingress tests #1494

Merged
merged 9 commits into from
Apr 17, 2023
Merged

Conversation

christarazi
Copy link
Member

@christarazi christarazi commented Apr 8, 2023

Requires #1498 and I pulled out #1501 to a separate PR because it broke CI on cilium/cilium.

Review commit by commit.

  • connectivity/check: Deploy host-netns daemonset by default
  • internal/cli/cmd: Clarify --nodes-without-cilium
  • .github/workflows: Label nodes for --nodes-without-cilium
  • .github/workflows: Install static routes for nodes without Cilium
  • connectivity/check: Validate --external-from-cidrs
  • Rename current CIDR tests to to-cidr.go
  • connectivity: Refactor scenarios passed to tests
  • connectivity: Implement FromCIDR tests
  • .github: Prepare workflows for tests with a 3rd node

Providing commit msg of the most important commit for convenience:

connectivity: Implement FromCIDR tests

These should cover the tests from the Cilium (github.com/cilium/cilium)
Ginkgo suite for FromCIDRs, see 1.

@christarazi christarazi temporarily deployed to ci April 8, 2023 01:00 — with GitHub Actions Inactive
@christarazi christarazi changed the title pr/christarazi/from cidr Implement FromCIDR ingress tests Apr 8, 2023
@christarazi christarazi temporarily deployed to ci April 8, 2023 01:05 — with GitHub Actions Inactive
@christarazi christarazi temporarily deployed to ci April 8, 2023 01:12 — with GitHub Actions Inactive
@christarazi christarazi temporarily deployed to ci April 10, 2023 18:32 — with GitHub Actions Inactive
@christarazi christarazi temporarily deployed to ci April 10, 2023 18:56 — with GitHub Actions Inactive
@christarazi christarazi temporarily deployed to ci April 10, 2023 19:17 — with GitHub Actions Inactive
@christarazi christarazi temporarily deployed to ci April 10, 2023 19:42 — with GitHub Actions Inactive
@christarazi christarazi temporarily deployed to ci April 10, 2023 22:26 — with GitHub Actions Inactive
@christarazi christarazi temporarily deployed to ci April 10, 2023 23:35 — with GitHub Actions Inactive
@christarazi christarazi temporarily deployed to ci April 11, 2023 06:18 — with GitHub Actions Inactive
@christarazi christarazi temporarily deployed to ci April 11, 2023 07:11 — with GitHub Actions Inactive
@christarazi christarazi marked this pull request as ready for review April 11, 2023 07:20
@christarazi christarazi requested review from a team as code owners April 11, 2023 07:20
Copy link
Contributor

@michi-covalent michi-covalent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm on 23a8dc8. extra credit if you add a unit test.

.github/workflows/kind.yaml Outdated Show resolved Hide resolved
@christarazi christarazi temporarily deployed to ci April 14, 2023 00:10 — with GitHub Actions Inactive
.github/workflows/kind.yaml Outdated Show resolved Hide resolved
.github/workflows/kind.yaml Outdated Show resolved Hide resolved
@@ -236,7 +236,7 @@ func addCommonInstallFlags(cmd *cobra.Command, params *install.Parameters) {
cmd.Flags().BoolVar(&params.ListVersions, "list-versions", false, "List all the available versions without actually installing")
cmd.Flags().BoolVar(&params.Wait, "wait", false, "Wait for helm install to finish")
cmd.Flags().DurationVar(&params.WaitDuration, "wait-duration", defaults.StatusWaitDuration, "Maximum time to wait for status")
cmd.Flags().StringSliceVar(&params.NodesWithoutCilium, "nodes-without-cilium", []string{}, "List of node names on which Cilium will not be installed. In Helm installation mode, it's assumed that the no-schedule node labels are present.")
cmd.Flags().StringSliceVar(&params.NodesWithoutCilium, "nodes-without-cilium", []string{}, "List of node names on which Cilium will not be installed. In Helm installation mode, it's assumed that the no-schedule node labels are present and that the infastructure has set up routing on these nodes to provide connectivity within the Cilium cluster.")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this out as an FYI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appreciating the call-out almost one year later 🙏

.github/workflows/kind.yaml Outdated Show resolved Hide resolved
Copy link
Member

@asauber asauber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, commits made the review easy

@christarazi christarazi marked this pull request as ready for review April 14, 2023 03:12
Copy link
Contributor

@brlbil brlbil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fond of this much bash magic in the workflow. It makes it hard to follow along with what is going on.
But I do not know a better way to do it myself 😄 so for workflow parts 👍

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Apr 14, 2023
The daemonset will now be deployed when we detect that the cluster
contains a node that is running without Cilium.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
Signed-off-by: Chris Tarazi <chris@isovalent.com>
In Helm mode, we want to avoid changing any resource that's not part of
the chart itself. This includes adding labels to the Node resource.
Therefore, we add steps in the workflow to do this instead.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
This is crucial for FromCIDR policy tests where a node that is outside
of the cluster (running without Cilium) initiates traffic towards pods
within the cluster.

In order to allow this, we need to install routes on these nodes which
point to the pod CIDR of each node in the cluster, via the node IP.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
This commit ensures that --external-from-cidrs is not empty when
--nodes-without-cilium was passed when installing Cilium. Otherwise,
FromCIDR policy connectivity tests won't work properly.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
Preparation for from-cidr.go to be added in subsequent commits.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
Refactoring to pass the scenarios as a slice allows us to conditionally
add to the slice in the future. Subsequent commits will add scenarios
for fromCIDR tests, which will leverage this refactor.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
These should cover the tests from the Cilium (github.com/cilium/cilium)
Ginkgo suite for FromCIDRs, see [1].

[1]:
https://github.com/cilium/cilium/blob/8f9daa8c4e9ccf17c4badaa28aa6c1b0b51924a8/test/k8s/net_policies.go#L488-L557.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
The 3rd node does not run Cilium and will be used in the connectivity
tests with `--nodes-without-cilium=kind-worker2`.

This activates the new tests added in the previous commit.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
@christarazi christarazi temporarily deployed to ci April 14, 2023 17:22 — with GitHub Actions Inactive
@christarazi
Copy link
Member Author

Pushed to fix up an error msg and code comments, so the push had no functional impact. The CI was already green given MLH marked it as ready to merge.

Copy link
Member

@joestringer joestringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that architecturally the environment configuration stuff belongs in the setup, though I do agree with Birol that embedding bash like this makes the workflows more complicated and difficult to grok. Maybe at some point we'll just reinvent the workflows as a github action with the relevant logic in it (better code reuse for cilium/cilium that way too). Anyway, now that we're not expanding the security footprint of the deployments this LGTM. I stared at the bash for a while and nothing jumped out.

EXTERNAL_NODE_IPS=() # Nodes IPs are collected to be passed to the Cilium CLI later on.

# Loop over each pod CIDR from all nodes.
for i in "${!EXTERNAL_FROM_CIDRS[@]}"; do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about getting keys with the ! syntax, TIL.

Comment on lines +85 to +87
if [[ $EXTERNAL_FROM_CIDR =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/[0-9]+$ ]]; then
IP_FAMILY="v4"
elif [[ $EXTERNAL_FROM_CIDR =~ ^[0-9a-fA-F:]+/[0-9]+$ ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not perfect checks for IP address formats but good enough especially in a workflow where I presume we're controlling the inputs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm aware they aren't perfect and went for just good enough to be usable. I wanted to avoid complicating the bash code further with super long regexes, but definitely an item for followup if we can also find a way to make it more readable, i.e. using a variable instead and hide the definition of it.

@maintainer-s-little-helper maintainer-s-little-helper bot removed the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Apr 14, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Apr 17, 2023
@christarazi christarazi merged commit 65f85a7 into master Apr 17, 2023
12 checks passed
@christarazi christarazi deleted the pr/christarazi/from-cidr branch April 17, 2023 20:01
christarazi added a commit to cilium/cilium that referenced this pull request May 1, 2023
The 3rd node does not run Cilium and will be used in the connectivity
tests with `--nodes-without-cilium=kind-worker2`.

The same was done in the cilium/cilium-cli repo, see
cilium/cilium-cli#1494.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants