forked from openshift-psap/special-resource-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
162 lines (125 loc) · 5.53 KB
/
Makefile
File metadata and controls
162 lines (125 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
SHELL = /bin/bash
SPECIALRESOURCE ?= driver-container-base
NAMESPACE ?= openshift-special-resource-operator
PULLPOLICY ?= IfNotPresent
TAG ?= $(shell git branch --show-current)
IMAGE ?= quay.io/openshift-psap/special-resource-operator:$(TAG)
CSPLIT ?= csplit - --prefix="" --suppress-matched --suffix-format="%04d.yaml" /---/ '{*}' --silent
YAMLFILES ?= $(shell find manifests${SUFFIX} charts -name "*.yaml" -not \( -path "charts/lustre/lustre-aws-fsx-0.0.1/csi-driver/*" -prune \) -not \( -path "charts/*/shipwright-*/*" -prune \) -not \( -path "charts/experimental/*" -prune \) )
PLATFORM ?= ""
SUFFIX ?= $(shell if [ ${PLATFORM} == "k8s" ]; then echo "-${PLATFORM}"; fi)
export PATH := go/bin:$(PATH)
include Makefile.specialresource.mk
include Makefile.helm.mk
include Makefile.helper.mk
patch:
cp .patches/options.patch.go vendor/github.com/google/go-containerregistry/pkg/crane/.
cp .patches/getter.patch.go vendor/helm.sh/helm/v3/pkg/getter/.
cp .patches/action.patch.go vendor/helm.sh/helm/v3/pkg/action/.
cp .patches/install.patch.go vendor/helm.sh/helm/v3/pkg/action/.
kube-lint: kube-linter
$(KUBELINTER) lint $(YAMLFILES)
lint: golangci-lint
$(GOLANGCILINT) run -v --timeout 5m0s
verify: fmt vet
unit:
@echo "TODO UNIT TEST"
go-deploy-manifests: manifests$(SUFFIX)
go run test/deploy/deploy.go -path ./manifests$(SUFFIX)
go-undeploy-manifests:
go run test/undeploy/undeploy.go -path ./manifests$(SUFFIX)
test-e2e-upgrade: go-deploy-manifests
test-e2e:
for d in basic; do \
KUBERNETES_CONFIG="$(KUBECONFIG)" go test -v -timeout 40m ./test/e2e/$$d -ginkgo.v -ginkgo.noColor -ginkgo.failFast || exit; \
done
# Current Operator version
VERSION ?= 0.0.1
CHANNELS="4.9"
# Default bundle image tag
BUNDLE_IMG ?= quay.io/openshift-psap/special-resource-operator-bundle:$(VERSION)
# Options for 'bundle-build'
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
DEFAULT_CHANNEL="4.9"
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:crdVersions=v1,trivialVersions=true"
# 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
# GENERATED all: manager
all: $(SPECIALRESOURCE)
# Run tests
test: # generate fmt vet manifests-gen
go test ./... -coverprofile cover.out
# Build manager binary
manager: patch generate fmt vet
go build -mod=vendor -o /tmp/bin/manager main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests-gen
go run -mod=vendor ./main.go
configure:
# TODO kustomize cannot set name of namespace according to settings, hack TODO
cd config/namespace && sed -i 's/name: .*/name: $(NAMESPACE)/g' namespace.yaml
cd config/namespace && $(KUSTOMIZE) edit set namespace $(NAMESPACE)
cd config/default && $(KUSTOMIZE) edit set namespace $(NAMESPACE)
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMAGE)
namespace: patch manifests$(SUFFIX)
$(KUSTOMIZE) build config/namespace | kubectl apply -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: namespace
$(KUSTOMIZE) build config/default$(SUFFIX) | kubectl apply -f -
$(shell sleep 5)
$(KUSTOMIZE) build config/cr | kubectl apply -f -
# If the CRD is deleted before the CRs the CRD finalizer will hang forever
# The specialresource finalizer will not execute either
undeploy: kustomize
if [ ! -z "$$(kubectl get crd | grep specialresource)" ]; then \
kubectl delete --ignore-not-found sr --all; \
fi;
# Give SRO time to reconcile
sleep 10
$(KUSTOMIZE) build config/namespace | kubectl delete --ignore-not-found -f -
$(KUSTOMIZE) build config/default$(SUFFIX) | kubectl delete --ignore-not-found -f -
# Generate manifests-gen e.g. CRD, RBAC etc.
manifests-gen: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
manifests$(SUFFIX): manifests-gen kustomize configure
cd $@; rm -f *.yaml
cd $@; ( $(KUSTOMIZE) build ../config/namespace && echo "---" && $(KUSTOMIZE) build ../config/default$(SUFFIX) ) | $(CSPLIT)
cd $@; bash ../scripts/rename.sh
cd $@; $(KUSTOMIZE) build ../config/cr > 0016_specialresource_special-resource-preamble.yaml
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet --mod=vendor ./...
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the docker image
local-image-build: patch helm-lint helm-repo-index test generate manifests-gen
podman build -f Dockerfile.ubi8 --no-cache . -t $(IMAGE)
# Push the docker image
local-image-push:
podman push $(IMAGE)
# Generate bundle manifests-gen and metadata, then validate generated files.
.PHONY: bundle
bundle: manifests-gen
operator-sdk generate kustomize manifests$(SUFFIX) -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMAGE)
$(KUSTOMIZE) build config/manifests$(SUFFIX) | operator-sdk generate bundle -q --overwrite --verbose --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle
# Build the bundle image.
.PHONY: bundle-build
bundle-build:
podman build -f bundle.Dockerfile -t $(BUNDLE_IMG) .