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

Update operator-sdk to 1.3.0 #86

Merged
merged 3 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin
testbin/*

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
build/_output/

# Kubernetes Generated files - skip generated files, except for vendored files

!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- "1.13"
- "1.15"

env:
- IMAGE_NAME=mellanox/network-operator
Expand All @@ -22,13 +22,13 @@ deploy:
# Push image to Dockerhub on merge to master
- provider: script
skip_cleanup: true
script: bash scripts/deploy.sh $IMAGE_NAME latest $TRAVIS_CPU_ARCH
script: bash scripts/docker-push.sh $IMAGE_NAME latest $TRAVIS_CPU_ARCH
on:
branch: master
# Push image to Dockerhub on tag
- provider: script
skip_cleanup: true
script: bash scripts/deploy.sh $IMAGE_NAME $TRAVIS_TAG $TRAVIS_CPU_ARCH
script: bash scripts/docker-push.sh $IMAGE_NAME $TRAVIS_TAG $TRAVIS_CPU_ARCH
on:
tags: true
all_branches: true
Expand Down
File renamed without changes.
102 changes: 92 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 NVIDIA
# Copyright 2021 NVIDIA
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,7 @@ LDFLAGS="-X github.com/Mellanox/network-operator/version.Version=$(VERSION) -X g
# Docker
IMAGE_BUILDER?=@docker
IMAGEDIR=$(BASE)/images
DOCKERFILE?=$(CURDIR)/build/Dockerfile
DOCKERFILE?=$(CURDIR)/Dockerfile
TAG?=mellanox/network-operator
IMAGE_BUILD_OPTS?=
# Accept proxy settings for docker
Expand All @@ -61,6 +61,25 @@ GOLANGCI_LINT_VER = v1.23.8
TIMEOUT = 15
Q = $(if $(filter 1,$V),,@)

## Options for 'bundle-build'
#ifneq ($(origin CHANNELS), undefined)
#BUNDLE_CHANNELS := --channels=$(CHANNELS)
#endif
#ifneq ($(origin DEFAULT_CHANNEL), undefined)
#BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
#endif
#BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

.PHONY: all
all: lint build

Expand All @@ -74,11 +93,11 @@ $(GOBIN):
$(BUILDDIR): | $(BASE) ; $(info Creating build directory...)
@cd $(BASE) && mkdir -p $@

build: $(BUILDDIR)/$(BINARY_NAME) ; $(info Building $(BINARY_NAME)...) @ ## Build executable file
build: generate $(BUILDDIR)/$(BINARY_NAME) ; $(info Building $(BINARY_NAME)...) @ ## Build executable file
$(info Done!)

$(BUILDDIR)/$(BINARY_NAME): $(GOFILES) | $(BUILDDIR)
@cd $(BASE)/cmd/manager && CGO_ENABLED=0 $(GO) build -o $(BUILDDIR)/$(BINARY_NAME) -tags no_openssl -v -ldflags=$(LDFLAGS)
@cd $(BASE) && CGO_ENABLED=0 $(GO) build -o $(BUILDDIR)/$(BINARY_NAME) -tags no_openssl -v -ldflags=$(LDFLAGS)

# Tools

Expand Down Expand Up @@ -107,19 +126,28 @@ test-verbose: ARGS=-v ## Run tests in verbose mode with coverage repo
test-race: ARGS=-race ## Run tests with race detector
$(TEST_TARGETS): NAME=$(MAKECMDGOALS:test-%=%)
$(TEST_TARGETS): test
check test tests: lint | $(BASE) ; $(info running $(NAME:%=% )tests...) @ ## Run tests
$Q cd $(BASE) && $(GO) test -timeout $(TIMEOUT)s $(ARGS) $(TESTPKGS)

test-xml: lint | $(BASE) $(GO2XUNIT) ; $(info running $(NAME:%=% )tests...) @ ## Run tests with xUnit output
$Q cd $(BASE) && 2>&1 $(GO) test -timeout 20s -v $(TESTPKGS) | tee test/tests.output
check test tests test-xml test-coverage: SHELL:=/bin/bash
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
check test tests: generate lint manifests | $(BASE) ; $(info running $(NAME:%=% )tests...) @ ## Run tests
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh
. ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); cd $(BASE) && $(GO) test -timeout $(TIMEOUT)s $(ARGS) $(TESTPKGS)

test-xml: generate lint manifests | $(BASE) $(GO2XUNIT) ; $(info running $(NAME:%=% )tests...) @ ## Run tests with xUnit output
mkdir test
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh
. ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); cd $(BASE) && 2>&1 $(GO) test -timeout 20s -v $(TESTPKGS) | tee test/tests.output
$(GO2XUNIT) -fail -input test/tests.output -output test/tests.xml

COVERAGE_MODE = count
.PHONY: test-coverage test-coverage-tools
test-coverage-tools: | $(GOVERALLS)
test-coverage: COVERAGE_DIR := $(CURDIR)/test
test-coverage: test-coverage-tools | $(BASE) ; $(info running coverage tests...) @ ## Run coverage tests
$Q cd $(BASE); $(GO) test -covermode=$(COVERAGE_MODE) -coverprofile=network-operator.cover ./...
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh
. ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); cd $(BASE); $(GO) test -covermode=$(COVERAGE_MODE) -coverprofile=network-operator.cover ./...

# Container image
.PHONY: image
Expand All @@ -135,8 +163,62 @@ clean: ; $(info Cleaning...) @ ## Cleanup everything
@rm -rf $(GOPATH)
@rm -rf $(BUILDDIR)
@rm -rf test
@rm -rf bin

.PHONY: help
help: ## Show this message
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

run: generate manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
go run ./main.go

install: manifests ## Install CRDs into a cluster
kubectl apply -f config/crd/bases

uninstall: manifests ## Uninstall CRDs from a cluster
kubectl delete -f config/crd/bases

.PHONY: deploy
deploy: manifests ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
@scripts/deploy-operator.sh

.PHONY: undeploy
undeploy: manifests ## UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
@scripts/delete-operator.sh

.PHONY: manifests
manifests: controller-gen ## Generate manifests e.g. CRD, RBAC etc.
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

generate: controller-gen ## Generate code
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)

#KUSTOMIZE = $(shell pwd)/bin/kustomize
#kustomize: ## Download kustomize locally if necessary
# $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef

#.PHONY: bundle
#bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
# operator-sdk generate kustomize manifests -q
# cd config/manager && $(KUSTOMIZE) edit set image controller=$(TAG)
# $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
# operator-sdk bundle validate ./bundle
15 changes: 15 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
domain: mellanox.com
layout: go.kubebuilder.io/v3
projectName: network-operator
repo: github.com/Mellanox/network-operator
resources:
- crdVersion: v1
kind: NicClusterPolicy
version: v1alpha1
- crdVersion: v1
kind: MacvlanNetwork
version: v1alpha1
version: 3-alpha
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ spec:
version: v0.3.0
```

Can be found at: `example/deploy/crds/mellanox.com_v1alpha1_nicclusterpolicy_cr.yaml`
Can be found at: `example/crs/mellanox.com_v1alpha1_nicclusterpolicy_cr.yaml`

#### NICClusterPolicy status
NICClusterPolicy `status` field reflects the current state of the system.
Expand Down Expand Up @@ -209,7 +209,7 @@ spec:
}
```

Can be found at: `example/deploy/crds/mellanox.com_v1alpha1_macvlannetwork_cr.yaml`
Can be found at: `example/crs/mellanox.com_v1alpha1_macvlannetwork_cr.yaml`

## System Requirements
* RDMA capable hardware: Mellanox ConnectX-4 NIC or newer.
Expand All @@ -221,16 +221,16 @@ Can be found at: `example/deploy/crds/mellanox.com_v1alpha1_macvlannetwork_cr.ya

## Deployment Example
Deployment of network-operator consists of:
* Deploying network-operator CRDs found under `./deploy/crds/`:
* Deploying network-operator CRDs found under `./config/crd/bases`:
* mellanox.com_nicclusterpolicies_crd.yaml
* mellanox.com_macvlan_crds.yaml
* k8s.cni.cncf.io-networkattachmentdefinitions-crd.yaml
* Deploying network operator resources found under `./deploy/` e.g operator namespace,
role, role binding, service account and the network-operator daemonset
* Defining and deploying a NICClusterPolicy custom resource.
Template can be found under `./deploy/crds/mellanox.com_v1alpha1_nicclusterpolicy_cr.yaml`
Example can be found under `./example/crs/mellanox.com_v1alpha1_nicclusterpolicy_cr.yaml`
* Defining and deploying a MacvlanNetwork custom resource.
Template can be found under `./deploy/crds/mellanox.com_v1alpha1_macvlannetwork_cr.yaml`
Example can be found under `./example/crs/mellanox.com_v1alpha1_macvlannetwork_cr.yaml`

A deployment example can be found under `example` folder [here](https://github.com/Mellanox/network-operator/example/README.md).

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 NVIDIA
Copyright 2021 NVIDIA

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,10 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// NOTE: Boilerplate only. Ignore this file.

// Package v1alpha1 contains API Schema definitions for the mellanox v1alpha1 API group
// +k8s:deepcopy-gen=package,register
// Package v1alpha1 contains API Schema definitions for the v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=mellanox.com
package v1alpha1

Expand All @@ -27,9 +25,12 @@ import (
)

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "mellanox.com", Version: "v1alpha1"}
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "mellanox.com", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 NVIDIA
Copyright 2021 NVIDIA

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,9 +20,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

const (
MacvlanNetworkCRDName = "MacvlanNetwork"
)
Expand Down Expand Up @@ -54,11 +51,12 @@ type MacvlanNetworkStatus struct {
Reason string `json:"reason,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// kubebuilder:object:generate
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster

// MacvlanNetwork is the Schema for the macvlannetworks API
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=macvlannetworks,scope=Cluster
type MacvlanNetwork struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -67,7 +65,8 @@ type MacvlanNetwork struct {
Status MacvlanNetworkStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// kubebuilder:object:generate

// MacvlanNetworkList contains a list of MacvlanNetwork
type MacvlanNetworkList struct {
Expand Down
Loading