This repository has been archived by the owner on Jun 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
k8s-jcasc.sh
executable file
·140 lines (130 loc) · 5.45 KB
/
k8s-jcasc.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
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
#!/usr/bin/env bash
# read configuration
if [[ -f "./config/k8s_jcasc_custom.cnf" ]]; then
source ./config/k8s_jcasc_custom.cnf
if [[ -f "${K8S_MGMT_ALTERNATIVE_CONFIG_FILE}" ]]; then
# if the alternative config file should work as overlay, load the original config first
# and then the alternative to reset the overwritten configuration
echo ""
if [[ -n "${K8S_MGMT_WORK_AS_OVERLAY}" && "${K8S_MGMT_WORK_AS_OVERLAY}" == "true" ]]; then
echo " INFO: loading original config..."
source ./config/k8s_jcasc_mgmt.cnf
fi
echo " INFO: loading overlay config..."
echo ""
# shellcheck source=/dev/null
source "${K8S_MGMT_ALTERNATIVE_CONFIG_FILE}"
else
echo ""
echo " ERROR: Configured alternative config not found! Please check your config/k8s_jcasc_custom.cnf file!"
echo ""
exit 1
fi
else
source ./config/k8s_jcasc_mgmt.cnf
fi
# import subscripts (take care with order!)
# shellcheck source=scripts/arguments_utils.sh
source ./scripts/arguments_utils.sh
# shellcheck source=scripts/cleanup_k8s_utils.sh
source ./scripts/cleanup_k8s_utils.sh
# shellcheck source=scripts/cloud_templates.sh
source ./scripts/cloud_templates.sh
# spellcheck source=scripts/filedir_utils.sh
source ./scripts/filedir_utils.sh
# spellcheck source=scripts/ipconfig_utils.sh
source ./scripts/ipconfig_utils.sh
# spellcheck source=scripts/install_controller.sh
source ./scripts/install_controller.sh
# spellcheck source=scripts/project_wizard_controller.sh
source ./scripts/project_wizard_controller.sh
# spellcheck source=scripts/secrets_controller.sh
source ./scripts/secrets_controller.sh
# spellcheck source=scripts/sed_utils.sh
source ./scripts/sed_utils.sh
# spellcheck source=scripts/validator_utils.sh
source ./scripts/validator_utils.sh
# spellcheck source=scripts/version_utils.sh
source ./scripts/version_utils.sh
# first check version
checkVersion
# start the script
processArguments "$@"
# import the dialog depending on installed tool "dialog" or on argument --nodialog
if [[ -x "$(command -v whiptail)" && "${K8S_MGMT_NO_DIALOG}" == "false" ]]; then
# spellcheck source=scripts/dialogs_whiptail.sh
source ./scripts/dialogs_whiptail.sh
elif [[ -x "$(command -v dialog)" && "${K8S_MGMT_NO_DIALOG}" == "false" ]]; then
# spellcheck source=scripts/dialogs_dialog.sh
source ./scripts/dialogs_dialog.sh
else
# spellcheck source=scripts/dialogs.sh
source ./scripts/dialogs.sh
fi
# if no valid argument was given let the user select one
selectInstallationTypeDialog
# validate, that command exists and nothing went wrong
if [[ -z "${K8S_MGMT_COMMAND}" ]]; then
echo ""
echo " Something went wrong. Was not able to find a valid command."
echo ""
exit 1
fi
##########
# Delegate the command to the right actions
#
function run() {
# delegate command to methods
if [[ "${_K8S_MGMT_COMMAND_CREATE_PROJECT}" == "${K8S_MGMT_COMMAND}" ]]; then
## Create new project
projectWizard
elif [[ "${_K8S_MGMT_COMMAND_CREATE_DEPLOYMENT_ONLY_PROJECT}" == "${K8S_MGMT_COMMAND}" ]]; then
createDeploymentOnlyWizard
elif [[ "${_K8S_MGMT_COMMAND_SECRETS_ENCRYPT}" == "${K8S_MGMT_COMMAND}" ]]; then
## encrypt secrets
encryptSecrets
elif [[ "${_K8S_MGMT_COMMAND_SECRETS_DECRYPT}" == "${K8S_MGMT_COMMAND}" ]]; then
## decrypt secrets
decryptSecrets
elif [[ "${_K8S_MGMT_COMMAND_SECRETS_APPLY}" == "${K8S_MGMT_COMMAND}" ]]; then
## apply secrets
applySecrets
elif [[ "${_K8S_MGMT_COMMAND_SECRETS_APPLY_TO_ALL_NAMESPACES}" == "${K8S_MGMT_COMMAND}" ]]; then
## apply secrets to all namespaces
applyGlobalSecretsToAllNamespaces
elif [[ "${_K8S_MGMT_COMMAND_SECRETS_APPLY}" == "${K8S_MGMT_COMMAND}" ]]; then
## apply secrets
# resolve namespace from global variable or ask for it
local __INTERNAL_NAMESPACE
dialogAskForNamespace __INTERNAL_NAMESPACE
# check if something was found
if [[ -n "${__INTERNAL_NAMESPACE}" ]]; then
K8S_MGMT_NAMESPACE="${__INTERNAL_NAMESPACE}"
applySecrets "${K8S_MGMT_NAMESPACE}"
else
echo ""
echo " ERROR: Unable to get name of the namespace. Please use the -n= | --namespace= argument or type the right namespace into the dialog."
echo ""
exit 1
fi
elif [[ "${_K8S_MGMT_COMMAND_INSTALL}" == "${K8S_MGMT_COMMAND}" ]]; then
## install Jenkins
local __K8S_MGMT_INSTALL_JENKINS_HELM_EXISTING
installOrUpgradeJenkins "${_K8S_MGMT_COMMAND_INSTALL}" __K8S_MGMT_INSTALL_JENKINS_HELM_EXISTING
installIngressControllerToNamespace "${__K8S_MGMT_INSTALL_JENKINS_HELM_EXISTING}"
elif [[ "${_K8S_MGMT_COMMAND_UPGRADE}" == "${K8S_MGMT_COMMAND}" ]]; then
## upgrade Jenkins
local __K8S_MGMT_INSTALL_JENKINS_HELM_EXISTING
installOrUpgradeJenkins "${_K8S_MGMT_COMMAND_UPGRADE}" __K8S_MGMT_INSTALL_JENKINS_HELM_EXISTING
elif [[ "${_K8S_MGMT_COMMAND_UNINSTALL}" == "${K8S_MGMT_COMMAND}" ]]; then
## uninstall Jenkins
uninstallJenkins
## uninstall nginx-ingress controller
uninstallIngressControllerFromNamespace
## remove nginx-ingress-controller sa,roles,clusterroes....
cleanupK8sNginxIngressControllerComplete
elif [[ "${_K8S_MGMT_COMMAND_CREATE_JENKINS_USER_PASSWORD}" == "${K8S_MGMT_COMMAND}" ]]; then
dialogAskForPassword
fi
}
run