-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (124 loc) · 6.05 KB
/
Makefile
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
# Current Operator version
VERSION ?= 0.0.1
# Default bundle image tag
BUNDLE_IMG ?= controller-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)
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
#all: docker-build
# Run against the configured Kubernetes cluster in ~/.kube/config
run: ansible-operator
$(ANSIBLE_OPERATOR) run
# Install CRDs into a cluster
install: kustomize
$(KUSTOMIZE) build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall: kustomize
$(KUSTOMIZE) build config/crd | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy-k8s: kustomize
cd config/manager-k8s && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/kubernetes | kubectl apply -f -
# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
undeploy-k8s: kustomize
$(KUSTOMIZE) build config/kubernetes | kubectl delete -f -
# Deploy controller in the configured Openshift cluster in ~/.kube/config
deploy-openshift: kustomize
cd config/manager-openshift && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/openshift | oc apply -f -
# Undeploy controller in the configured Opnshift cluster in ~/.kube/config
undeploy-openshift: kustomize
$(KUSTOMIZE) build config/openshift | oc delete -f -
# Build the docker image
docker-build:
docker build . -t ${IMG}
# Push the docker image
docker-push:
docker push ${IMG}
# Make Kubernetes Installer and Manifests
k8s-installer: kustomize
$(KUSTOMIZE) build config/crd > manifests/acinamespaces-crd.yaml && \
$(KUSTOMIZE) build config/rbac-k8s > manifests/acinamespaces-rbac-k8s.yaml && \
$(KUSTOMIZE) build config/manager-k8s > manifests/acinamespaces-controller-k8s.yaml && \
echo "kubectl apply -f ../manifests/acinamespaces-rbac-k8s.yaml" > installers/acins-kube-installer.sh && \
echo "kubectl apply -f ../manifests/acinamespaces-crd.yaml" >> installers/acins-kube-installer.sh && \
echo "kubectl apply -f ../manifests/acinamespaces-controller-k8s.yaml" >> installers/acins-kube-installer.sh
chmod +x installers/acins-kube-installer.sh
# Make Kubernetes Uninstaller (TODO FIX ORDER)
k8s-uninstaller: kustomize
$(KUSTOMIZE) build config/crd > manifests/acinamespaces-crd.yaml && \
$(KUSTOMIZE) build config/rbac-k8s > manifests/acinamespaces-rbac-k8s.yaml && \
$(KUSTOMIZE) build config/manager-k8s > manifests/acinamespaces-controller-k8s.yaml && \
echo "kubectl delete -f ../manifests/acinamespaces-crd.yaml" > installers/acins-kube-uninstaller.sh && \
echo "kubectl delete -f ../manifests/acinamespaces-controller-k8s.yaml" >> installers/acins-kube-uninstaller.sh && \
echo "kubectl delete -f ../manifests/acinamespaces-rbac-k8s" >> installers/acins-kube-uninstaller.sh
chmod +x installers/acins-kube-uninstaller.sh
# Make Openshift Installer and Manifests
ocp-installer: kustomize
$(KUSTOMIZE) build config/crd > manifests/acinamespaces-crd.yaml && \
$(KUSTOMIZE) build config/rbac-openshift > manifests/acinamespaces-rbac-openshift.yaml && \
$(KUSTOMIZE) build config/manager-openshift > manifests/acinamespaces-controller-openshift.yaml && \
echo "ocp apply -f ../manifests/acinamespaces-rbac-openshift.yaml" > installers/acins-ocp-installer.sh && \
echo "ocp apply -f ../manifests/acinamespaces-crd.yaml" >> installers/acins-ocp-installer.sh && \
echo "ocp apply -f ../manifests/acinamespaces-controller-openshift.yaml" >> installers/acins-ocp-installer.sh
chmod +x installers/acins-ocp-installer.sh
# Make Openshift Uninstaller (TODO FIX ORDER)
ocp-uninstaller: kustomize
$(KUSTOMIZE) build config/crd > manifests/acinamespaces-crd.yaml && \
$(KUSTOMIZE) build config/rbac-openshift > manifests/acinamespaces-rbac-openshift.yaml && \
$(KUSTOMIZE) build config/manager-openshift > manifests/acinamespaces-controller-openshift.yaml && \
echo "ocp delete -f ../manifests/acinamespaces-crd.yaml" > installers/acins-ocp-uninstaller.sh && \
echo "ocp delete -f ../manifests/acinamespaces-controller-openshift.yaml" >> installers/acins-ocp-uninstaller.sh && \
echo "ocp delete -f ../manifests/acinamespaces-rbac-openshift.yaml" >> installers/acins-ocp-uninstaller.sh
chmod +x installers/acins-ocp-uninstaller.sh
# Dummy test
test: kustomize
echo "This is a test"
PATH := $(PATH):$(PWD)/bin
#SHELL := env PATH=$(PATH) /bin/sh
OS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH = $(shell uname -m | sed 's/x86_64/amd64/')
OSOPER = $(shell uname -s | tr '[:upper:]' '[:lower:]' | sed 's/darwin/apple-darwin/' | sed 's/linux/linux-gnu/')
ARCHOPER = $(shell uname -m )
kustomize:
ifeq (, $(shell which kustomize 2>/dev/null))
@{ \
set -e ;\
mkdir -p bin ;\
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | tar xzf - -C bin/ ;\
}
KUSTOMIZE=$(realpath ./bin/kustomize)
else
KUSTOMIZE=$(shell which kustomize)
endif
ansible-operator:
ifeq (, $(shell which ansible-operator 2>/dev/null))
@{ \
set -e ;\
mkdir -p bin ;\
curl -LO https://github.com/operator-framework/operator-sdk/releases/download/v1.0.0/ansible-operator-v1.0.0-$(ARCHOPER)-$(OSOPER) ;\
mv ansible-operator-v1.0.0-$(ARCHOPER)-$(OSOPER) ./bin/ansible-operator ;\
chmod +x ./bin/ansible-operator ;\
}
ANSIBLE_OPERATOR=$(realpath ./bin/ansible-operator)
else
ANSIBLE_OPERATOR=$(shell which ansible-operator)
endif
# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: kustomize
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(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) .