2020-07-26 21:47:24 +00:00
# Current Operator version
VERSION ?= 0.0.1
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$( VERSION)
# Options for 'bundle-build'
i f n e q ( $( origin CHANNELS ) , u n d e f i n e d )
BUNDLE_CHANNELS := --channels= $( CHANNELS)
e n d i f
i f n e q ( $( origin DEFAULT_CHANNEL ) , u n d e f i n e d )
BUNDLE_DEFAULT_CHANNEL := --default-channel= $( DEFAULT_CHANNEL)
e n d i f
BUNDLE_METADATA_OPTS ?= $( BUNDLE_CHANNELS) $( BUNDLE_DEFAULT_CHANNEL)
# Image URL to use all building/pushing image targets
2020-10-15 04:45:53 +00:00
IMG ?= seaweedfs/operator:latest
2020-07-26 21:47:24 +00:00
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
i f e q ( , $( shell go env GOBIN ) )
GOBIN = $( shell go env GOPATH) /bin
e l s e
GOBIN = $( shell go env GOBIN)
e n d i f
all : manager
# Run tests
2020-10-15 04:45:53 +00:00
ENVTEST_ASSETS_DIR = $( shell pwd ) /testbin
2020-07-26 21:47:24 +00:00
test : generate fmt vet manifests
2020-10-15 04:45:53 +00:00
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/master/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
2020-07-26 21:47:24 +00:00
# Build manager binary
manager : generate fmt vet
go build -o bin/manager main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run : generate fmt vet 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= manager-role webhook paths = "./..." output:crd:artifacts:config= config/crd/bases
# Run go fmt against code
fmt :
go fmt ./...
# Run go vet against code
vet :
go vet ./...
# Generate code
generate : controller -gen
$( CONTROLLER_GEN) object:headerFile= "hack/boilerplate.go.txt" paths = "./..."
# Build the docker image
docker-build : test
docker build . -t ${ IMG }
# Push the docker image
docker-push :
docker push ${ IMG }
# find or download controller-gen
# download controller-gen if necessary
controller-gen :
i f e q ( , $( 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/controller-gen@v0.3.0 ; \
rm -rf $$ CONTROLLER_GEN_TMP_DIR ; \
}
CONTROLLER_GEN = $( GOBIN) /controller-gen
e l s e
CONTROLLER_GEN = $( shell which controller-gen)
e n d i f
kustomize :
i f e q ( , $( 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/v3@v3.5.4 ; \
rm -rf $$ KUSTOMIZE_GEN_TMP_DIR ; \
}
KUSTOMIZE = $( GOBIN) /kustomize
e l s e
KUSTOMIZE = $( shell which kustomize)
e n d i f
# Generate bundle manifests and metadata, then validate generated files.
bundle : manifests
operator-sdk generate kustomize manifests -q
2020-08-02 06:27:46 +00:00
kustomize build config/manifests | operator-sdk generate bundle -q --overwrite --version $( VERSION) $( BUNDLE_METADATA_OPTS)
2020-07-26 21:47:24 +00:00
operator-sdk bundle validate ./bundle
# Build the bundle image.
bundle-build :
docker build -f bundle.Dockerfile -t $( BUNDLE_IMG) .