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

feat(compose): Add basic networking support #1044

Merged
merged 10 commits into from
Feb 29, 2024

Conversation

LucaSeri
Copy link
Contributor

@LucaSeri LucaSeri commented Nov 29, 2023

Prerequisite checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Ran make fmt on your commit series before opening this PR;
  • Updated relevant documentation.

Description of changes

This PR introduces networking support for compose projects. Currently, because networks have to be "fully" specified, the syntax is quite verbose:

services:
  ping:
    build: ./ping
    networks:
     ping-pong-net: # Allocate any IP
  pong:
    build: ./pong
    networks: 
      ping-pong-net:
        ipv4_address: 172.200.0.5

networks:
  ping-pong-net:
    name: ping-pong
    driver: bridge
    ipam:
      config:
        - subnet: 172.200.0.1/24 
      # equivalent to:
      # - subnet: 172.200.0.0/24
      # - gateway: 172.200.0.1

This could be improved on by introducing a way to automatically allocate networks.

Additionally, this PR introduces a commit that makes networking thread-safe: running multiple kernels in parallel would result in the network controller not being updated properly.

You can find an example of a working application here:
https://github.com/LucaSeri/kraft-compose-examples/tree/main/ping-pong

Depends on: #1042, #1024

@LucaSeri LucaSeri marked this pull request as ready for review December 8, 2023 12:43
compose/project.go Outdated Show resolved Hide resolved
@LucaSeri LucaSeri marked this pull request as draft February 3, 2024 17:25
@LucaSeri LucaSeri force-pushed the compose-networking branch 2 times, most recently from 5e28428 to e493076 Compare February 21, 2024 09:39
@LucaSeri LucaSeri marked this pull request as ready for review February 21, 2024 09:42
LucaSeri and others added 9 commits February 29, 2024 14:10
This check should be done by the other internals in
kraft (build, pkg, run, etc.) so we have a predictable
behaviour.

Signed-off-by: Luca Seritan <luca.seritan@gmail.com>
This allows us to be aware of the networks that
belong to the project.

Signed-off-by: Luca Seritan <luca.seritan@gmail.com>
Introduce checks related to networks as well as
a way to assign IPs to services within their networks.

Signed-off-by: Luca Seritan <luca.seritan@gmail.com>
Signed-off-by: Luca Seritan <luca.seritan@gmail.com>
Signed-off-by: Luca Seritan <luca.seritan@gmail.com>
These functions are general purpose util functions that are meant to
be used outside of the bridge package. This is particularly useful
since importing the bridge package prevents kraftkit from building
natively on MacOS.

Signed-off-by: Luca Seritan <luca.seritan@gmail.com>
Co-authored-by: Alexander Jung <alex@unikraft.io>
Signed-off-by: Luca Seritan <luca.seritan@gmail.com>
This allows to only instantiate the machine and network
controllers once, which is more efficient and makes
handling races easier.

Signed-off-by: Luca Seritan <luca.seritan@gmail.com>
Signed-off-by: Luca Seritan <luca.seritan@gmail.com>
Prior to this, running something like:
kraft run --network name:: (with no IP)

would cause the mask of the network to be appended to
the empty IP, which in turn would prevent the driver
from allocating an address.

Signed-off-by: Luca Seritan <luca.seritan@gmail.com>
Copy link
Member

@nderjung nderjung left a comment

Choose a reason for hiding this comment

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

Great work! Thanks so much!

@nderjung nderjung merged commit ef41ba4 into unikraft:staging Feb 29, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🚀 Done
Development

Successfully merging this pull request may close these issues.

3 participants