Skip to content

Commit

Permalink
Restructured multus to use Go standard project layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Simha authored and dougbtv committed Dec 15, 2020
1 parent 24386ab commit e14032a
Show file tree
Hide file tree
Showing 43 changed files with 326 additions and 155 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/docker-build-push-master.yml
Expand Up @@ -18,16 +18,16 @@ jobs:
uses: actions/checkout@v2

- name: Build latest-amd64
run: docker build -t ${REPOSITORY}:latest-amd64 .
run: docker build -t ${REPOSITORY}:latest-amd64 -f deployments/Dockerfile .

- name: Build latest-ppc64le
run: docker build -t ${REPOSITORY}:latest-ppc64le -f Dockerfile.ppc64le .
run: docker build -t ${REPOSITORY}:latest-ppc64le -f deployments/Dockerfile.ppc64le .

- name: Build latest-arm64v8
run: docker build -t ${REPOSITORY}:latest-arm64v8 -f Dockerfile.arm64 .
run: docker build -t ${REPOSITORY}:latest-arm64v8 -f deployments/Dockerfile.arm64 .

- name: Build latest-origin
run: docker build -t ${REPOSITORY}:latest-origin -f Dockerfile.openshift .
run: docker build -t ${REPOSITORY}:latest-origin -f deployments/Dockerfile.openshift .

- name: Tag snapshot
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/docker-build-push-release.yml
Expand Up @@ -18,16 +18,16 @@ jobs:
uses: actions/checkout@v2

- name: Build latest-amd64
run: docker build -t ${REPOSITORY}:latest-amd64 .
run: docker build -t ${REPOSITORY}:latest-amd64 -f deployments/Dockerfile .

- name: Build latest-ppc64le
run: docker build -t ${REPOSITORY}:latest-ppc64le -f Dockerfile.ppc64le .
run: docker build -t ${REPOSITORY}:latest-ppc64le -f deployments/Dockerfile.ppc64le .

- name: Build latest-arm64v8
run: docker build -t ${REPOSITORY}:latest-arm64v8 -f Dockerfile.arm64 .
run: docker build -t ${REPOSITORY}:latest-arm64v8 -f deployments/Dockerfile.arm64 .

- name: Build latest-origin
run: docker build -t ${REPOSITORY}:latest-origin -f Dockerfile.openshift .
run: docker build -t ${REPOSITORY}:latest-origin -f deployments/Dockerfile.openshift .

- name: Tag stable
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docker-build.yml
Expand Up @@ -13,10 +13,10 @@ jobs:
uses: actions/checkout@v2

- name: Build latest-amd64
run: docker build -t ${REPOSITORY}:latest-amd64 .
run: docker build -t ${REPOSITORY}:latest-amd64 -f deployments/Dockerfile .

- name: Build latest-ppc64le
run: docker build -t ${REPOSITORY}:latest-ppc64le -f Dockerfile.ppc64le .
run: docker build -t ${REPOSITORY}:latest-ppc64le -f deployments/Dockerfile.ppc64le .

- name: Build latest-origin
run: docker build -t ${REPOSITORY}:latest-origin -f Dockerfile.openshift .
run: docker build -t ${REPOSITORY}:latest-origin -f deployments/Dockerfile.openshift .
2 changes: 1 addition & 1 deletion .github/workflows/go-build-arm64.yml
Expand Up @@ -22,4 +22,4 @@ jobs:
uses: actions/checkout@v2

- name: Build
run: GOARCH="${TARGET}" ./build
run: GOARCH="${TARGET}" ./hack/build-go.sh
2 changes: 1 addition & 1 deletion .github/workflows/go-build-ppc64.yml
Expand Up @@ -22,4 +22,4 @@ jobs:
uses: actions/checkout@v2

- name: Build
run: GOARCH="${TARGET}" ./build
run: GOARCH="${TARGET}" ./hack/build-go.sh
4 changes: 2 additions & 2 deletions .github/workflows/go-build-test-amd64.yml
Expand Up @@ -37,10 +37,10 @@ jobs:
run: go vet ./...

- name: Build
run: GOARCH="${TARGET}" ./build
run: GOARCH="${TARGET}" ./hack/build-go.sh

- name: Go test
run: sudo ./test.sh
run: sudo ./hack/test-go.sh

- name: goveralls
uses: shogo82148/actions-goveralls@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/kind-e2e.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
run: docker run -d --restart=always -p "5000:5000" --name "kind-registry" registry:2

- name: Build latest-amd64
run: docker build -t localhost:5000/multus:e2e .
run: docker build -t localhost:5000/multus:e2e -f deployments/Dockerfile .

- name: Push to local registry
run: docker push localhost:5000/multus:e2e
Expand Down
116 changes: 116 additions & 0 deletions .travis.yml
@@ -0,0 +1,116 @@
os: linux
language: go
# see https://docs.travis-ci.com/user/reference/overview/#Virtualization-environments
# for the detail
# sudo: requried
dist: bionic

services:
- docker

go:
- 1.13.x

env:
global:
- GO111MODULE=on
- REGISTRY_USER=${REGISTRY_USER:-nfvpe}
- REGISTRY_PASS=${REGISTRY_PASS}
- REPOSITORY_NAME=${REPOSITORY_NAME}
- REPOSITORY_USER=${REPOSITORY_USER}
- DOCKER_CLI_EXPERIMENTAL="enabled"
- secure: "${REGISTRY_SECURE}"
jobs:
- TARGET=amd64
- TARGET=ppc64le

before_install:
- if [ "${REPOSITORY_NAME}" = "" ]; then export REPOSITORY_NAME=multus; fi
- sudo apt-get update -qq
- go get github.com/mattn/goveralls

install:
- go get -u golang.org/x/lint/golint

before_script:
# Make gopath... to run golint/go fmt/go vet
# Suppress golint for fixing lint later.
- golint ./... | grep -v vendor | grep -v ALL_CAPS | xargs -r false
- go fmt ./...
- go vet ./...
# - gocyclo -over 15 ./multus

script:
- GOARCH="${TARGET}" ./hack/build-go.sh
- |
if [ "${TARGET}" == "amd64" ]; then
sudo env PATH=${PATH} ./scripts/test.sh
goveralls -coverprofile=coverage.out -service=travis-ci
docker build -t ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64 .
docker build -t ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-ppc64le -f Dockerfile.ppc64le .
docker build -t ${REPOSITORY_USER}/${REPOSITORY_NAME}-origin:latest -f Dockerfile.openshift .
fi
deploy:
# Release on versioned tag (e.g. v1.0)
- provider: script
#cleanup: false
script: curl -sL https://git.io/goreleaser
on:
tags: true
all_branches: true
condition: "$TARGET = amd64 && $TRAVIS_TAG =~ ^v[0-9].*$ && ! -z $GITHUB_TOKEN && $TRAVIS_OS_NAME = linux"
# Push images to Dockerhub on tag
- provider: script
cleanup: false
script: >
bash -c '
docker tag ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64 ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest;
docker tag ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64 ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable;
docker tag ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64 ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable-amd64;
docker tag ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64 ${REPOSITORY_USER}/${REPOSITORY_NAME}:$TRAVIS_TAG;
docker tag ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-ppc64le ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable-ppc64le;
docker login -u "$REGISTRY_USER" -p "$REGISTRY_PASS";
docker push ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64;
docker push ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-ppc64le;
docker push ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable-amd64;
docker push ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable-ppc64le;
docker push ${REPOSITORY_USER}/${REPOSITORY_NAME}:$TRAVIS_TAG;
export DOCKER_CLI_EXPERIMENTAL="enabled";
docker manifest create ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64 ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-ppc64le;
docker manifest annotate ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64 --arch amd64;
docker manifest annotate ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-ppc64le --arch ppc64le;
docker manifest push ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest;
docker manifest create ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable-amd64 ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable-ppc64le;
docker manifest annotate ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable-amd64 --arch amd64;
docker manifest annotate ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable-ppc64le --arch ppc64le;
docker manifest push ${REPOSITORY_USER}/${REPOSITORY_NAME}:stable;
echo done'
on:
tags: true
all_branches: true
condition: "$TRAVIS_TAG =~ ^v[0-9].*$ && -n $REGISTRY_USER && -n $REGISTRY_PASS && -n $REPOSITORY_NAME && -n $REPOSITORY_USER"
# Push images to Dockerhub on merge to master
- provider: script
on:
branch: master
condition: "-n $REGISTRY_USER && -n $REGISTRY_PASS && -n $REPOSITORY_NAME && -n $REPOSITORY_USER"
script: >
bash -c '
docker tag ${REPOSITORY_USER}/:latest-amd64 ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot;
docker tag ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64 ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot-amd64;
docker tag ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-ppc64le ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot-ppc64le;
docker login -u "$REGISTRY_USER" -p "$REGISTRY_PASS";
docker push ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot-amd64;
docker push ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot-ppc64le;
docker push ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64;
docker push ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-ppc64le;
docker manifest create ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot-amd64 ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot-ppc64le;
docker manifest annotate ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot-amd64 --arch amd64;
docker manifest annotate ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot-ppc64le --arch ppc64le;
docker manifest push ${REPOSITORY_USER}/${REPOSITORY_NAME}:snapshot;
docker manifest create ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64 ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-ppc64le;
docker manifest annotate ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-amd64 --arch amd64;
docker manifest annotate ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest-ppc64le --arch ppc64le;
docker manifest push ${REPOSITORY_USER}/${REPOSITORY_NAME}:latest;
echo done'
60 changes: 60 additions & 0 deletions cmd/main.go
@@ -0,0 +1,60 @@
// Copyright (c) 2017 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This is a "Multi-plugin".The delegate concept refered from CNI project
// It reads other plugin netconf, and then invoke them, e.g.
// flannel or sriov plugin.

package main

import (
"flag"
"fmt"
"os"

"gopkg.in/intel/multus-cni.v3/pkg/multus"
"github.com/containernetworking/cni/pkg/skel"
cniversion "github.com/containernetworking/cni/pkg/version"
)


func main() {

// Init command line flags to clear vendored packages' one, especially in init()
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)

// add version flag
versionOpt := false
flag.BoolVar(&versionOpt, "version", false, "Show application version")
flag.BoolVar(&versionOpt, "v", false, "Show application version")
flag.Parse()
if versionOpt == true {
fmt.Printf("%s\n", multus.PrintVersionString())
return
}

skel.PluginMain(
func(args *skel.CmdArgs) error {
result, err := multus.CmdAdd(args, nil, nil)
if err != nil {
return err
}
return result.Print()
},
func(args *skel.CmdArgs) error {
return multus.CmdCheck(args, nil, nil)
},
func(args *skel.CmdArgs) error { return multus.CmdDel(args, nil, nil) },
cniversion.All, "meta-plugin that delegates to other CNI plugins")
}
2 changes: 1 addition & 1 deletion Dockerfile → deployments/Dockerfile
Expand Up @@ -10,7 +10,7 @@ RUN rpm --import https://mirror.go-repo.io/centos/RPM-GPG-KEY-GO-REPO && \
yum install -y $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
cd /usr/src/multus-cni && \
./build
./hack/build-go.sh

FROM centos:centos7
COPY --from=build /usr/src/multus-cni /usr/src/multus-cni
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.arm64 → deployments/Dockerfile.arm64
Expand Up @@ -8,7 +8,7 @@ ENV GOARCH "arm64"
ENV GOOS "linux"

RUN cd /usr/src/multus-cni && \
./build
./hack/build-go.sh

# build arm64 container
FROM arm64v8/centos:7
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.openshift → deployments/Dockerfile.openshift
Expand Up @@ -5,7 +5,7 @@ ADD . /usr/src/multus-cni

WORKDIR /usr/src/multus-cni
ENV GO111MODULE=off
RUN ./build
RUN ./hack/build-go.sh

FROM openshift/origin-base
RUN mkdir -p /usr/src/multus-cni/images && mkdir -p /usr/src/multus-cni/bin
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.ppc64le → deployments/Dockerfile.ppc64le
Expand Up @@ -13,7 +13,7 @@ RUN rpm --import https://mirror.go-repo.io/centos/RPM-GPG-KEY-GO-REPO && \
yum install -y $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
cd /usr/src/multus-cni && \
./build
./hack/build-go.sh

# build ppc container
FROM ppc64le/centos:latest
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions doc/development.md → docs/development.md
Expand Up @@ -22,20 +22,20 @@ If an issue is closed that you don't feel is sufficiently resolved, please feel

## How do I build multus-cni?

You can use the built in `./build` script!
You can use the built in `./hack/build-go.sh` script!

```
git clone https://github.com/intel/multus-cni.git
cd multus-cni
./build
./hack/build-go.sh
```

## How do I run CI tests?

Multus has go unit tests (based on ginkgo framework).The following commands drive CI tests manually in your environment:

```
sudo ./test.sh
sudo ./scripts/test.sh
```

## What are the best practices for logging?
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions build → hack/build-go.sh
Expand Up @@ -40,7 +40,7 @@ if [ "$GO111MODULE" == "off" ]; then
export GO15VENDOREXPERIMENT=1
export GOBIN=${PWD}/bin
export GOPATH=${PWD}/gopath
go install -tags no_openssl -ldflags "${LDFLAGS}" "$@" ${REPO_PATH}/multus
go build -o ${PWD}/bin/multus -tags no_openssl -ldflags "${LDFLAGS}" "$@" ${REPO_PATH}/cmd
else
# build with go modules
export GO111MODULE=on
Expand All @@ -50,5 +50,5 @@ else
fi

echo "Building plugins"
go build ${BUILD_ARGS[*]} -ldflags "${LDFLAGS}" "$@" ./multus
go build ${BUILD_ARGS[*]} -ldflags "${LDFLAGS}" "$@" ./cmd
fi
File renamed without changes.
4 changes: 2 additions & 2 deletions checkpoint/checkpoint.go → pkg/checkpoint/checkpoint.go
Expand Up @@ -19,8 +19,8 @@ import (
"encoding/json"
"io/ioutil"

"gopkg.in/intel/multus-cni.v3/logging"
"gopkg.in/intel/multus-cni.v3/types"
"gopkg.in/intel/multus-cni.v3/pkg/logging"
"gopkg.in/intel/multus-cni.v3/pkg/types"
v1 "k8s.io/api/core/v1"
)

Expand Down
Expand Up @@ -10,7 +10,7 @@ import (
"io/ioutil"
"testing"

"gopkg.in/intel/multus-cni.v3/types"
"gopkg.in/intel/multus-cni.v3/pkg/types"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sTypes "k8s.io/apimachinery/pkg/types"
Expand Down
6 changes: 3 additions & 3 deletions k8sclient/k8sclient.go → pkg/k8sclient/k8sclient.go
Expand Up @@ -38,12 +38,12 @@ import (
"github.com/containernetworking/cni/libcni"
"github.com/containernetworking/cni/pkg/skel"
cnitypes "github.com/containernetworking/cni/pkg/types"
"gopkg.in/intel/multus-cni.v3/pkg/kubeletclient"
"gopkg.in/intel/multus-cni.v3/pkg/logging"
"gopkg.in/intel/multus-cni.v3/pkg/types"
nettypes "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
netclient "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/clientset/versioned/typed/k8s.cni.cncf.io/v1"
netutils "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/utils"
"gopkg.in/intel/multus-cni.v3/kubeletclient"
"gopkg.in/intel/multus-cni.v3/logging"
"gopkg.in/intel/multus-cni.v3/types"
)

const (
Expand Down
Expand Up @@ -23,10 +23,10 @@ import (
"testing"

types020 "github.com/containernetworking/cni/pkg/types/020"
testutils "gopkg.in/intel/multus-cni.v3/testing"
testutils "gopkg.in/intel/multus-cni.v3/pkg/testing"

"github.com/containernetworking/cni/pkg/skel"
"gopkg.in/intel/multus-cni.v3/types"
"gopkg.in/intel/multus-cni.v3/pkg/types"

nettypes "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
netfake "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/clientset/versioned/fake"
Expand Down

0 comments on commit e14032a

Please sign in to comment.