-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·205 lines (159 loc) · 5.41 KB
/
install.sh
File metadata and controls
executable file
·205 lines (159 loc) · 5.41 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
# Copyright 2025 Deutsche Telekom IT GmbH
#
# SPDX-License-Identifier: Apache-2.0
set -eo pipefail
ACTIVE_KUBE_CONTEXT=$(kubectl config current-context)
REPO_NAME="telekom/controlplane"
CONTROLPLANE_VERSION="latest"
CONTROLPLANE_NAMESPACE="controlplane-system"
CERT_MANAGER_VERSION="v1.18.2"
TRUST_MANAGER_VERSION="v0.19.0"
PROM_OPERATOR_CRDS_VERSION="v23.0.0"
WITH_CERT_MANAGER=false
WITH_TRUST_MANAGER=false
WITH_MONITORING_CRDS=false
function print_help() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --with-cert-manager Install Cert-Manager"
echo " --with-trust-manager Install Trust-Manager"
echo " --with-monitoring-crds Install Prometheus Operator CRDs"
echo " -h, --help Show this help message and exit"
echo ""
echo "Example:"
echo " $0 --with-cert-manager --with-monitoring-crds"
}
while [[ $# -gt 0 ]]; do
case "$1" in
--with-cert-manager)
WITH_CERT_MANAGER=true
shift
;;
--with-trust-manager)
WITH_TRUST_MANAGER=true
shift
;;
--with-monitoring-crds)
WITH_MONITORING_CRDS=true
shift
;;
-h|--help)
print_help
exit 0
;;
*)
shift
;;
esac
done
function check_github_token() {
if [ -z "$GITHUB_TOKEN" ]; then
echo "⚠️ GITHUB_TOKEN environment variable is not set. This may be required due to GitHub API rate limits."
echo ""
fi
}
function request_user_input() {
local prompt="$1"
local default_value="$2"
read -p "$prompt [$default_value]: " input
if [ -z "$input" ]; then
echo "$default_value"
else
echo "$input"
fi
}
function check_binary_exists() {
local binary="$1"
if ! command -v "$binary" &> /dev/null; then
echo "$binary is not installed. Please install it first."
exit 1
fi
}
function get_latest_release() {
local repo="$1"
LATEST_RELEASE_INFO_URL="https://api.github.com/repos/${repo}/releases/latest"
LATEST_RELEASE_JSON_FILE=$(mktemp)
curl -sSL -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" -o "${LATEST_RELEASE_JSON_FILE}" "${LATEST_RELEASE_INFO_URL}"
TAG_NAME=$(jq -r .tag_name "${LATEST_RELEASE_JSON_FILE}")
echo "$TAG_NAME"
}
function install_cert_manager() {
local version="$1"
echo "Installing Cert-Manager version $version..."
helm repo add jetstack https://charts.jetstack.io --force-update
helm --kube-context "$ACTIVE_KUBE_CONTEXT" \
upgrade cert-manager jetstack/cert-manager \
--install \
--namespace cert-manager \
--create-namespace \
--version $version \
--set crds.enabled=true \
--wait
}
function install_trust_manager() {
local version="$1"
echo "Installing Trust-Manager version $version..."
helm repo add jetstack https://charts.jetstack.io --force-update
helm --kube-context "$ACTIVE_KUBE_CONTEXT" \
upgrade trust-manager jetstack/trust-manager \
--install \
--namespace cert-manager \
--version $version \
--set app.trust.namespace=$CONTROLPLANE_NAMESPACE \
--wait
}
function install_monitoring_crds() {
local version="$1"
echo "Installing Prometheus Operator CRDs version $version..."
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts --force-update
helm --kube-context "$ACTIVE_KUBE_CONTEXT" \
upgrade prometheus-operator-crds prometheus-community/prometheus-operator-crds \
--install \
--namespace monitoring \
--create-namespace \
--version $version \
--wait
}
function install_controlplane() {
local version="$1"
if [ "$version" == "latest" ]; then
version=$(get_latest_release $REPO_NAME)
fi
if [ -z "$version" ] || [ "$version" == "null" ]; then
echo "Failed to get the latest version of controlplane."
exit 1
fi
echo "Installing ControlPlane version $version..."
ROOT_KUSTOMIZE_FILE="kustomization.yaml"
KUSTOMIZE_FILE_URL="https://raw.githubusercontent.com/${REPO_NAME}/${version}/install/kustomization.yaml"
curl -sSL -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/yaml" -o "${ROOT_KUSTOMIZE_FILE}" "${KUSTOMIZE_FILE_URL}"
}
function main() {
check_github_token
check_binary_exists "kubectl"
check_binary_exists "helm"
check_binary_exists "jq"
ACTIVE_KUBE_CONTEXT=$(request_user_input "Install on which Kubernetes context?" "$ACTIVE_KUBE_CONTEXT")
echo "ℹ️ Using Kubernetes context: $ACTIVE_KUBE_CONTEXT"
if [ "$WITH_NAMESPACE" = true ]; then
echo "Creating namespace $CONTROLPLANE_NAMESPACE..."
kubectl --context "$ACTIVE_KUBE_CONTEXT" create namespace "$CONTROLPLANE_NAMESPACE" || true
fi
# Install Cert-Manager
if [ "$WITH_CERT_MANAGER" = true ]; then
install_cert_manager "$CERT_MANAGER_VERSION"
fi
# Install Trust-Manager
if [ "$WITH_TRUST_MANAGER" = true ]; then
install_trust_manager "$TRUST_MANAGER_VERSION"
fi
# Install Prometheus Operator
if [ "$WITH_MONITORING_CRDS" = true ]; then
install_monitoring_crds "$PROM_OPERATOR_CRDS_VERSION"
fi
# Install ControlPlane
install_controlplane "$CONTROLPLANE_VERSION"
}
main "$@"