-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate project to Operator SDK v1.2.0 (#10)
* Migrate project to Operator SDK v1.2.0 Migrate project to Operator SDK v1.2.0 following the doc: https://sdk.operatorframework.io/docs/building-operators/golang/migration/ Two new make targets are added to help generate bundle and package manifests: - Bundle format make bundle - Package manifests format make make packagemanifests Fixes: #8 Signed-off-by: rcao <[email protected]>
- Loading branch information
Showing
82 changed files
with
2,817 additions
and
610 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
# go options | ||
GO ?= go | ||
LDFLAGS := | ||
GOFLAGS := | ||
BINDIR ?= $(CURDIR)/build/_output/bin | ||
GO_FILES := $(shell find . -type d -name '.cache' -prune -o -type f -name '*.go' -print) | ||
GOPATH ?= $$($(GO) env GOPATH) | ||
SHELL := /bin/bash | ||
# Current Operator version | ||
VERSION ?= latest | ||
# Default bundle image tag | ||
BUNDLE_IMG ?= antrea-operator-bundle:$(VERSION) | ||
# 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) | ||
|
||
.PHONY: all | ||
all: build | ||
# Image URL to use all building/pushing image targets | ||
IMG ?= antrea-operator:latest | ||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
CRD_OPTIONS ?= "crd:trivialVersions=true" | ||
|
||
LDFLAGS += $(VERSION_LDFLAGS) | ||
OPERATOR_NAME = antrea-operator | ||
# 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: build | ||
build: | ||
@echo "===> Building antrea-operator Docker image <===" | ||
docker build -f build/Dockerfile . -t $(OPERATOR_NAME) | ||
# Options for "packagemanifests". | ||
ifneq ($(origin FROM_VERSION), undefined) | ||
PKG_FROM_VERSION := --from-version=$(FROM_VERSION) | ||
endif | ||
ifneq ($(origin CHANNEL), undefined) | ||
PKG_CHANNELS := --channel=$(CHANNEL) | ||
endif | ||
ifeq ($(IS_CHANNEL_DEFAULT), 1) | ||
PKG_IS_DEFAULT_CHANNEL := --default-channel | ||
endif | ||
PKG_MAN_OPTS ?= $(FROM_VERSION) $(PKG_CHANNELS) $(PKG_IS_DEFAULT_CHANNEL) | ||
|
||
.PHONY: bin | ||
bin: | ||
@echo "===> Building antrea-operator binary <===" | ||
GOOS=linux $(GO) build -o $(BINDIR)/$(OPERATOR_NAME) $(GOFLAGS) -ldflags '$(LDFLAGS)' ./cmd/manager | ||
|
||
.PHONY: test-unit | ||
test-unit: | ||
@echo "===> Running unit tests <===" | ||
GOOS=linux $(GO) test -race -cover github.com/vmware/antrea-operator-for-kubernetes/pkg... | ||
all: manager | ||
|
||
.golangci-bin: | ||
@echo "===> Installing Golangci-lint <===" | ||
|
@@ -35,6 +46,101 @@ test-unit: | |
golangci: .golangci-bin | ||
@GOOS=linux CGO_ENABLED=1 .golangci-bin/golangci-lint run -c .golangci.yml | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f $(BINDIR)/$(OPERATOR_NAME) | ||
# Run tests | ||
ENVTEST_ASSETS_DIR = $(shell pwd)/testbin | ||
test: generate golangci manifests | ||
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.6.3/hack/setup-envtest.sh | ||
source $(ENVTEST_ASSETS_DIR)/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out | ||
|
||
# Build manager binary | ||
manager: generate golangci | ||
@echo "===> Building antrea-operator binary <===" | ||
go build -o bin/manager main.go | ||
|
||
# Run against the configured Kubernetes cluster in ~/.kube/config | ||
run: generate golangci manifests | ||
go run ./main.go | ||
|
||
# Install CRDs into a cluster | ||
install: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl apply -f - | ||
|
||
# Uninstall CRDs from a cluster | ||
uninstall: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl delete -f - | ||
|
||
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
deploy: manifests kustomize | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} | ||
$(KUSTOMIZE) build config/default | kubectl apply -f - | ||
|
||
# Generate manifests e.g. CRD, RBAC etc. | ||
manifests: controller-gen | ||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=antrea-operator webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
|
||
# Generate code | ||
generate: controller-gen | ||
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
||
# Build the docker image | ||
docker-build: test | ||
docker build -f build/Dockerfile . -t ${IMG} | ||
|
||
# Push the docker image | ||
docker-push: | ||
docker push ${IMG} | ||
|
||
# find or download controller-gen | ||
# download controller-gen if necessary | ||
controller-gen: | ||
ifeq (, $(shell which controller-gen)) | ||
@{ \ | ||
set -e ;\ | ||
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$CONTROLLER_GEN_TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\ | ||
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ | ||
} | ||
CONTROLLER_GEN=$(GOBIN)/controller-gen | ||
else | ||
CONTROLLER_GEN=$(shell which controller-gen) | ||
endif | ||
|
||
kustomize: | ||
ifeq (, $(shell which kustomize)) | ||
@{ \ | ||
set -e ;\ | ||
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\ | ||
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
} | ||
KUSTOMIZE=$(GOBIN)/kustomize | ||
else | ||
KUSTOMIZE=$(shell which kustomize) | ||
endif | ||
|
||
# Generate bundle manifests and metadata, then validate generated files. | ||
.PHONY: bundle | ||
bundle: manifests kustomize | ||
operator-sdk generate kustomize manifests -q | ||
cd config/manager && $(KUSTOMIZE) edit set image antrea-operator=$(IMG) | ||
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) | ||
operator-sdk bundle validate ./bundle | ||
|
||
# Build the bundle image. | ||
.PHONY: bundle-build | ||
bundle-build: | ||
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . | ||
|
||
# Generate package manifests. | ||
packagemanifests: kustomize manifests | ||
operator-sdk generate kustomize manifests -q | ||
cd config/manager && $(KUSTOMIZE) edit set image antrea-operator=$(IMG) | ||
$(KUSTOMIZE) build config/manifests | operator-sdk generate packagemanifests -q --version $(VERSION) $(PKG_MAN_OPTS) | ||
|
||
.PHONY: bin | ||
bin: manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
domain: vmware.com | ||
layout: go.kubebuilder.io/v2 | ||
projectName: antrea-operator-for-kubernetes | ||
repo: github.com/vmware/antrea-operator-for-kubernetes | ||
resources: | ||
- group: operator.antrea | ||
kind: AntreaInstall | ||
version: v1 | ||
version: 3-alpha | ||
plugins: | ||
go.sdk.operatorframework.io/v2-alpha: {} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Copyright © 2020 VMware, Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
// Package v1 contains API Schema definitions for the operator v1 API group | ||
// +kubebuilder:object:generate=true | ||
// +groupName=operator.antrea.vmware.com | ||
package v1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects | ||
GroupVersion = schema.GroupVersion{Group: "operator.antrea.vmware.com", Version: "v1"} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) |
12 changes: 4 additions & 8 deletions
12
...apis/operator/v1/zz_generated.deepcopy.go → api/v1/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.