Skip to content

ucloud/uk8s-cni-vpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UCloud K8s CNI-VPC Plugin

This is a CNI plugin to implement the underlay container networking based on UCloud VPC 2.0.

Install

The uk8s-cni-vpc will be installed in the uk8s cluster by default, and you do not need to perform additional installation operations.

You can login to any machine in the uk8s cluster and confirm the plugin version with the following command:

/opt/cni/bin/cnivpc version

The ipamd is an independent component of the plugin that manages the IP addresses of Pods. It is deployed in the form of DaemonSet, and you can check the version of ipamd through the following command:

kubectl get -n kube-system ds cni-vpc-ipamd -oyaml

For more information, please refer to our documentation.

Documentation

You can find complete documentation about the UK8S cluster network here.

Contribution

Generate grpc code

If you modify the file rpc/ipamd.proto, the grpc code needs to be regenerated.

The grpc code generation is based on the protoc tool. You have to make sure it is properly installed on your system. You can install it through different ways, such as package managers of different systems:

sudo pacman -S protoc        # For archlinux
brew install protoc          # For macos
sudo apt-get install protoc  # For ubuntu or debain
yum install protoc           # For centos

In addition, protoc-gen-go needs to be installed, which can be done by the following command:

go install github.com/golang/protobuf/protoc-gen-go@latest

Now, you can regenerate the grpc code:

make generate-grpc

View the differences:

git diff rpc/*.go

Generate kubernetes code

uk8s-cni-vpc needs to use some Kubernetes Custom Resources. These Custom Resources are defined in the kubernetes/apis directory.

If you modify the types.go file, the code needs to be regenerated, you can run the following command:

make generate-k8s

If you want to create a new Custom Resource, you need to create the corresponding files under the kubernetes/apis directory. You can use the Custom Resource has already been created as example, such as kubernetes/apis/ipamd.

The new Custom Resource also needs to be added in hack/update-codegen.sh.

There are two places that need to be changed. First, find the bash code-generator/generate-groups.sh command and add your new Custom Resource to the args. Suppose the new Custom Resource is called example and the version is v1beta1, the updated command will be:

bash code-generator/generate-groups.sh "deepcopy,client,informer,lister" \
  github.com/ucloud/uk8s-cni-vpc/kubernetes/generated  github.com/ucloud/uk8s-cni-vpc/kubernetes/apis \
  "ipamd:v1beta1 vipcontroller:v1beta1 example:v1beta1" \ # Add your new CR here
  --output-base generated_tmp \
  --go-header-file hack/boilerplate.go.txt

Then, you also need to add the copy command of the deepcopy file before rm -rf generated_tmp:

cp -r generated_tmp/github.com/ucloud/uk8s-cni-vpc/kubernetes/apis/exmaple/v1beta1/zz_generated.deepcopy.go ./kubernetes/apis/example/v1beta1

Don't forget to replace exmaple and v1beta1 with your own Custom Resource name and version.

Finally, use make generate-k8s, the new Custom Resource code will be generated.

In addition, Custom Resource's yaml needs to be written manually, which is generally defined under deploy directory, you can refer to the following example:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: ipamds.vpc.uk8s.ucloud.cn
spec:
  group: vpc.uk8s.ucloud.cn
  versions:
    - name: v1beta1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
              # TODO: change spec fields here.
            status:
              type: object
              properties:
              # TODO: change status fields here.
  scope: Namespaced
  names:
    plural: ipamds
    singular: ipamd
    kind: Ipamd

Build

Requires your machine to have Docker and Golang to build cnivpc. Please use the following command to build:

make cnivpc-bin     # Build cnivpc binary files only
make cnivpc         # Build cnivpc binary files and docker image
make ipamd          # Build ipamd binary file and docker image
make vip-controller # Build vip-controller binary file and docker image

Release

As long as you create a tag, all docker images will be automatically built and published through Github Action. See: release workflow.