This repository has been archived by the owner on Nov 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
/
gen-helm-memcached.sh
executable file
·98 lines (77 loc) · 3.63 KB
/
gen-helm-memcached.sh
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
#!/usr/bin/env bash
# Copyright 2019 The Operator-SDK Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Before run this script ensure that you have helm installed locally
# with the stable repo as well. The helm sample will use the memcached chart
# from helm repository.
# To install: https://helm.sh/docs/intro/install/
# To add the repo run `helm repo add stable https://charts.helm.sh/stable`
set -o errexit
set -o pipefail
# Turn colors in this script off by setting the NO_COLOR variable in your
# environment to any value:
#
# $ NO_COLOR=1 test.sh
NO_COLOR=${NO_COLOR:-""}
if [ -z "$NO_COLOR" ]; then
header=$'\e[1;33m'
reset=$'\e[0m'
else
header=''
reset=''
fi
operatorName="memcached-operator"
function header_text {
echo "$header$*$reset"
}
function gen_helm_sample {
# When operator-sdk scaffolds Helm projects, it tries to use the discovery API of a Kubernetes
# cluster to intelligently build the RBAC rules that the operator will require based on the
# content of the helm chart.
#
# Here, we intentionally set KUBECONFIG to a broken value to ensure that operator-sdk will be
# unable to reach a real cluster, and thus will generate a default RBAC rule set. This is
# required to make Helm project generation idempotent because contributors and CI environments
# can all have slightly different environments that can affect the content of the generated
# role and cause sanity testing to fail.
export KUBECONFIG="broken_so_we_generate_static_default_rules"
local operIMG="quay.io/example-inc/memcached-operator:v0.0.1"
local bundleIMG="quay.io/example-inc/memcached-operator-bundle:v0.0.1"
header_text "starting to generate the sample ..."
header_text "removing memcached-operator ..."
cd ..
rm -rf $operatorName
header_text "creating $operatorName"
header_text "creating memcached-operator ..."
mkdir $operatorName
cd $operatorName
operator-sdk init --plugins=helm --domain=example.com
operator-sdk create api --version=v1alpha1 --group=cache --kind=Memcached --helm-chart=stable/memcached
header_text "customizing sample project ..."
header_text "updating config/samples/cache_v1alpha1_memcached.yaml ..."
sed -i".bak" -E -e 's/AntiAffinity: hard/AntiAffinity: soft/g' config/samples/cache_v1alpha1_memcached.yaml; rm -f config/samples/cache_v1alpha1_memcached.yaml.bak
header_text "adding policy rbac roles ..."
sed -i".bak" -E -e '/kubebuilder:scaffold:rules/d' config/rbac/role.yaml; rm -f config/rbac/role.yaml.bak
cat ../.generate/policy-role.yaml >> config/rbac/role.yaml
header_text "enabling prometheus metrics..."
sed -i".bak" -E -e 's/(#- ..\/prometheus)/- ..\/prometheus/g' config/default/kustomization.yaml; rm -f config/default/kustomization.yaml.bak
header_text "bulding the project ..."
make docker-build IMG=$operIMG
header_text "integrating with OLM ..."
sed -i".bak" -E -e 's/operator-sdk generate kustomize manifests/operator-sdk generate kustomize manifests --interactive=false/g' Makefile; rm -f Makefile.bak
header_text "generating bundle and building the image $bundleIMG ..."
make bundle IMG=$operIMG
make bundle-build BUNDLE_IMG=$bundleIMG
}
gen_helm_sample