@leverege/build-tools 2.80.1-beta.2 → 2.81.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +22 -0
- package/package.json +5 -4
- package/src/Utils.mjs +2 -2
- package/src/helm-charts/argocd/.nohelm +0 -0
- package/src/helm-charts/argocd/.nohelmdn +0 -0
- package/src/helm-charts/argocd/helmup.bootstrap +3 -0
- package/src/helm-charts/argocd/helmup.plugin +3 -0
- package/src/helm-charts/cnpg-db-pgbench/helmup.bootstrap +11 -0
- package/src/helm-charts/cnpg-db-psql-stack/helmup.bootstrap +11 -0
- package/src/helm-charts/cnpg-db-psql-stack/helmup.plugin +1 -1
- package/src/helm-charts/cnpg-db-recovery/helmup.bootstrap +11 -0
- package/src/helm-charts/cnpg-db-recovery/helmup.plugin +1 -1
- package/src/helm-charts/cnpg-db-tsdb-basic/helmup.bootstrap +11 -0
- package/src/helm-charts/cnpg-db-tsdb-basic/helmup.plugin +1 -1
- package/src/helm-charts/cnpg-db-tsdb-dense/helmup.bootstrap +11 -0
- package/src/helm-charts/cnpg-db-tsdb-dense/helmup.plugin +1 -1
- package/src/helm-charts/cnpg-operator/helmdn.plugin +1 -1
- package/src/helm-charts/cnpg-operator/helmup.bootstrap +201 -0
- package/src/helm-charts/cnpg-operator/helmup.plugin +1 -1
- package/src/helm-charts/cnpg-operator/operand.bootstrap +41 -0
- package/src/helm-charts/pgbouncer/helmup.bootstrap +24 -0
- package/src/helm-charts/prom-operator/helmup.bootstrap +47 -0
- package/src/helm-charts/prom-operator/rules/traefik-rules.yaml +2 -2
- package/src/helm-charts/traefik/values-local.yaml +1 -1
- package/src/helm-charts/velero/helmup.bootstrap +104 -0
- package/src/helmdn.sh +2 -1
- package/src/helmup.sh +36 -582
- package/src/init-my-chart.mjs +18 -0
- package/.vscode/settings.json +0 -3
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2.0",
|
|
3
|
+
"configurations": [
|
|
4
|
+
{
|
|
5
|
+
"type": "node",
|
|
6
|
+
"request": "launch",
|
|
7
|
+
"name": "Test",
|
|
8
|
+
"runtimeExecutable": "npm",
|
|
9
|
+
"runtimeArgs": [
|
|
10
|
+
"run",
|
|
11
|
+
"testNoTimeout"
|
|
12
|
+
],
|
|
13
|
+
"resolveSourceMapLocations": [
|
|
14
|
+
"${workspaceFolder}/**",
|
|
15
|
+
"!**/node_modules/**"
|
|
16
|
+
],
|
|
17
|
+
"env": {
|
|
18
|
+
},
|
|
19
|
+
"outputCapture": "std"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leverege/build-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.81.1",
|
|
4
4
|
"description": "A collection of build / support tools for Leverege developers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"helminit": "src/helmup.sh",
|
|
43
43
|
"helmwhat": "src/helmup.sh",
|
|
44
44
|
"hook-and-release": "src/hook-and-release.mjs",
|
|
45
|
+
"init-my-chart": "src/init-my-chart.mjs",
|
|
45
46
|
"k8scale": "src/k8scale.sh",
|
|
46
47
|
"k8x": "src/k8x.sh",
|
|
47
48
|
"klog": "src/klog.sh",
|
|
@@ -74,7 +75,7 @@
|
|
|
74
75
|
"glob": "^11.0.3",
|
|
75
76
|
"handlebars": "^4.7.8",
|
|
76
77
|
"ignore": "^7.0.5",
|
|
77
|
-
"inquirer": "^12.
|
|
78
|
+
"inquirer": "^12.9.0",
|
|
78
79
|
"js-yaml": "^4.1.0",
|
|
79
80
|
"jsdoc": "^4.0.4",
|
|
80
81
|
"ms": "^2.1.3",
|
|
@@ -88,10 +89,10 @@
|
|
|
88
89
|
"simple-git": "^3.28.0",
|
|
89
90
|
"sloc": "^0.3.2",
|
|
90
91
|
"toml": "^3.0.0",
|
|
91
|
-
"zx": "^8.7.
|
|
92
|
+
"zx": "^8.7.2"
|
|
92
93
|
},
|
|
93
94
|
"devDependencies": {
|
|
94
95
|
"@leverege/eslint-config-leverege": "^5.0.1",
|
|
95
|
-
"npm": "^11.
|
|
96
|
+
"npm": "^11.5.1"
|
|
96
97
|
}
|
|
97
98
|
}
|
package/src/Utils.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import YAML from 'js-yaml'
|
|
|
14
14
|
|
|
15
15
|
// __dirname goes away with ESM so we take this approach instead and
|
|
16
16
|
// this assumes this file lives in the src dir of the build-tools repo
|
|
17
|
-
export const BUILD_TOOLS_ROOT = path.dirname( url.fileURLToPath( import.meta.url ) )
|
|
17
|
+
export const BUILD_TOOLS_ROOT = process.env.BUILD_TOOLS_ROOT || path.dirname( url.fileURLToPath( import.meta.url ) )
|
|
18
18
|
|
|
19
19
|
let debugEnabled = process.env.BUILD_TOOLS_DEBUG === '1'
|
|
20
20
|
|
|
@@ -565,7 +565,7 @@ export const analyzeRepository = async ( giveGuidance ) => {
|
|
|
565
565
|
// if the build tools version is still undefined then assume we are using a globally installed bt
|
|
566
566
|
if ( buildToolsVersion === undefined ) {
|
|
567
567
|
const fromBuildTools = await shellCmd( 'build-tools --version' )
|
|
568
|
-
buildToolsVersion = fromBuildTools.match( /\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/ )[0]
|
|
568
|
+
buildToolsVersion = fromBuildTools.match( /\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/ )[0] // eslint-disable-line security/detect-unsafe-regex
|
|
569
569
|
}
|
|
570
570
|
|
|
571
571
|
const containerName = closestPackageJson?.name.replace( /^@[^/]+\//, '' ) || rootPyProjectToml?.project.name
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# lifted from helmup.sh
|
|
4
|
+
#
|
|
5
|
+
function installCnpgOperatorEnvironment() {
|
|
6
|
+
# See => https://github.com/cloudnative-pg/charts
|
|
7
|
+
|
|
8
|
+
gcloud config set project $GCP_PROJECT_ID
|
|
9
|
+
|
|
10
|
+
# create an SA in the cnpg namespace for the operands to bind to
|
|
11
|
+
CNPG_NAMESPACE="cnpg-operands"
|
|
12
|
+
CNPG_SVC_ACCT="$CNPG_NAMESPACE-sa"
|
|
13
|
+
CNPG_SVC_EMAIL="$CNPG_SVC_ACCT@$GCP_PROJECT_ID.iam.gserviceaccount.com"
|
|
14
|
+
|
|
15
|
+
# We used to delete the SA when we were doing clean installs but that bit
|
|
16
|
+
# me in the ass the time I moved the operator dir out of the way to run
|
|
17
|
+
# helmwhat to populate with latest operator version. The result? The SA
|
|
18
|
+
# was deleted and recreated and the existing system lost the ability to
|
|
19
|
+
# write to GCS which resulted in WAL failures. The deletion / recreation
|
|
20
|
+
# logic was only useful in the early days of creating / deleting for
|
|
21
|
+
# initial development.
|
|
22
|
+
#
|
|
23
|
+
# Synopsis: deleting an SA from an actual non-test system is BAD NEWS
|
|
24
|
+
# and if it happens then you will need to rebind the SA to
|
|
25
|
+
# workload identity by hand.
|
|
26
|
+
#
|
|
27
|
+
# kubectl delete serviceaccounts -n $CNPG_NAMESPACE $CNPG_SVC_ACCT &> $DEVNULL
|
|
28
|
+
# gcloud --quiet iam service-accounts delete $CNPG_SVC_EMAIL --project $GCP_PROJECT_ID&> $DEVNULL
|
|
29
|
+
kubectl describe serviceaccounts -n $CNPG_NAMESPACE $CNPG_SVC_ACCT &> $DEVNULL
|
|
30
|
+
if [ $? -eq 0 ];
|
|
31
|
+
then
|
|
32
|
+
cat<<SKIP_CNPG_SA_CREATION
|
|
33
|
+
|
|
34
|
+
$YELO_WARN The CNPG SA $CNPG_SVC_ACCT already exists
|
|
35
|
+
|
|
36
|
+
Deleting the SA for the purposes of upgrading the operator is going to
|
|
37
|
+
wreck someone's day (probably yours) if the desire is to simply upgrade
|
|
38
|
+
in place. To force a clean reinstall, delete both the k8s and gcp SA for
|
|
39
|
+
CNPG and try again. (see comments in helmup for more info)
|
|
40
|
+
|
|
41
|
+
SKIP_CNPG_SA_CREATION
|
|
42
|
+
return
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
# Create the operands namespace and annotate to allow redis access
|
|
46
|
+
createNamespaceIfNeeded $CNPG_NAMESPACE
|
|
47
|
+
|
|
48
|
+
# Create GCP SA and bind policies
|
|
49
|
+
printf "\nCreating the gcloud `color g $CNPG_SVC_ACCT` service account (SA)\n"
|
|
50
|
+
gcloud iam service-accounts create $CNPG_SVC_ACCT \
|
|
51
|
+
--project "$GCP_PROJECT_ID" \
|
|
52
|
+
--description "CNPG Operands SA" \
|
|
53
|
+
--display-name "CNPG Operands SA" &> $DEVNULL
|
|
54
|
+
warnOnError $? "the GCP SA `color y $CNPG_SVC_ACCT` may already exist"
|
|
55
|
+
|
|
56
|
+
CNPG_OPS_ROLE="cnpg.operands"
|
|
57
|
+
printf "\nCreating the `color g $CNPG_OPS_ROLE` IAM role\n"
|
|
58
|
+
## Attach roles
|
|
59
|
+
ROLE_PERMISSIONS=(
|
|
60
|
+
iam.serviceAccounts.actAs
|
|
61
|
+
iam.serviceAccounts.get
|
|
62
|
+
iam.serviceAccounts.getAccessToken
|
|
63
|
+
iam.serviceAccounts.getOpenIdToken
|
|
64
|
+
iam.serviceAccounts.implicitDelegation
|
|
65
|
+
iam.serviceAccounts.list
|
|
66
|
+
iam.serviceAccounts.signBlob
|
|
67
|
+
iam.serviceAccounts.signJwt
|
|
68
|
+
resourcemanager.projects.get
|
|
69
|
+
storage.buckets.create
|
|
70
|
+
storage.buckets.get
|
|
71
|
+
storage.buckets.getIamPolicy
|
|
72
|
+
storage.buckets.list
|
|
73
|
+
storage.buckets.update
|
|
74
|
+
storage.objects.create
|
|
75
|
+
storage.objects.delete
|
|
76
|
+
storage.objects.get
|
|
77
|
+
storage.objects.getIamPolicy
|
|
78
|
+
storage.objects.list
|
|
79
|
+
)
|
|
80
|
+
gcloud iam roles create $CNPG_OPS_ROLE \
|
|
81
|
+
--project $GCP_PROJECT_ID \
|
|
82
|
+
--title "CNPG Operands" \
|
|
83
|
+
--description "CNPG Operands" \
|
|
84
|
+
--permissions "$(IFS=","; echo "${ROLE_PERMISSIONS[*]}")" &> $DEVNULL
|
|
85
|
+
if [ $? -ne 0 ];
|
|
86
|
+
then
|
|
87
|
+
# assume error is that role exists so try updating instead
|
|
88
|
+
printf "\nUpdating the permissions on the `color g $CNPG_OPS_ROLE` IAM role\n"
|
|
89
|
+
gcloud iam roles update $CNPG_OPS_ROLE \
|
|
90
|
+
--project $GCP_PROJECT_ID \
|
|
91
|
+
--title "CNPG Operands" \
|
|
92
|
+
--permissions "$(IFS=","; echo "${ROLE_PERMISSIONS[*]}")" &> $DEVNULL
|
|
93
|
+
fi
|
|
94
|
+
warnOnError $? "Failed to add roles to $CNPG_OPS_ROLE - perhaps they already exist?"
|
|
95
|
+
|
|
96
|
+
printf "\nBinding IAM role to the SA `color g $CNPG_SVC_EMAIL`\n"
|
|
97
|
+
gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
|
|
98
|
+
--member="serviceAccount:$CNPG_SVC_EMAIL" \
|
|
99
|
+
--role "roles/storage.admin" &> $DEVNULL
|
|
100
|
+
# --role projects/$GCP_PROJECT_ID/roles/$CNPG_OPS_ROLE &> $DEVNULL
|
|
101
|
+
# --role "roles/storage.admin" &> $DEVNULL
|
|
102
|
+
warnOnError $? "gcloud problem binding IAM policy"
|
|
103
|
+
|
|
104
|
+
printf "\nBinding IAM the Token Creator role to the SA `color g $CNPG_SVC_EMAIL`\n"
|
|
105
|
+
gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
|
|
106
|
+
--member="serviceAccount:$CNPG_SVC_EMAIL" \
|
|
107
|
+
--role="roles/iam.serviceAccountTokenCreator"
|
|
108
|
+
|
|
109
|
+
# workload binding will be performed by each cnpg operand on startup
|
|
110
|
+
|
|
111
|
+
BARMAN_BUCKET="gs://$GCP_PROJECT_ID-barman"
|
|
112
|
+
gsutil ls -p $GCP_PROJECT_ID -b $BARMAN_BUCKET &> $DEVNULL
|
|
113
|
+
if [ "$?" -eq 0 ];
|
|
114
|
+
then
|
|
115
|
+
printf "\nBarman bucket `color g "$BARMAN_BUCKET"` already exists - skipping recreation\n"
|
|
116
|
+
else
|
|
117
|
+
printf "\nCreating a bucket for barman backups: `color g $BARMAN_BUCKET`\n"
|
|
118
|
+
gsutil mb -l $GCE_REGION $BARMAN_BUCKET &> $DEVNULL
|
|
119
|
+
gsutil iam ch serviceAccount:$CNPG_SVC_EMAIL:objectAdmin $BARMAN_BUCKET
|
|
120
|
+
gsutil ubla set on $BARMAN_BUCKET # uniform bucket access
|
|
121
|
+
fi
|
|
122
|
+
|
|
123
|
+
# define the snapshot storage class
|
|
124
|
+
printf "\nApplying the CNPG VolumeSnapshotClass `color g cnpg-snapshotclass` definition\n"
|
|
125
|
+
cat<<EOSNAPSC | kubectl apply -f -
|
|
126
|
+
apiVersion: snapshot.storage.k8s.io/v1
|
|
127
|
+
kind: VolumeSnapshotClass
|
|
128
|
+
metadata:
|
|
129
|
+
name: cnpg-snapshotclass
|
|
130
|
+
driver: pd.csi.storage.gke.io
|
|
131
|
+
deletionPolicy: Retain
|
|
132
|
+
EOSNAPSC
|
|
133
|
+
|
|
134
|
+
sleep 2 # hold up processing for a moment to allow IAM mods to propagate
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# this function is a little convoluted in the way it attempts to install the
|
|
138
|
+
# scripts and yaml necessary for the CNPG cleanup activities - the idea is to
|
|
139
|
+
# be able to update the scripts without touching anything else since the target
|
|
140
|
+
# directory is the cnpg-operator setup
|
|
141
|
+
function installCnpgCleanupCronjob() {
|
|
142
|
+
CNPG_OPERATOR_DIR="cnpg-operator"
|
|
143
|
+
if [ ! -d "$CNPG_OPERATOR_DIR" ];
|
|
144
|
+
then
|
|
145
|
+
cat<<CNPG_OPERATOR_MISSING
|
|
146
|
+
`color r "The cnpg-operator must be installed before proceeding"`
|
|
147
|
+
|
|
148
|
+
CNPG_OPERATOR_MISSING
|
|
149
|
+
exit 1
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
# create the destination bucket for k8s cronjob scripts
|
|
153
|
+
BUCKET_SUFFIX="k8s-cronjobs"
|
|
154
|
+
makeUniformBucketWithCors $BUCKET_SUFFIX
|
|
155
|
+
|
|
156
|
+
CNPG_CLEANUP_CRONJOB_OVH="cnpg-cleanup-cronjob.yaml.ovh"
|
|
157
|
+
CNPG_CLEANUP_CRONJOB="$CNPG_OPERATOR_DIR/$CNPG_CLEANUP_CRONJOB_OVH"
|
|
158
|
+
CNPG_CLEANUP_SCRIPT_BASH="cnpg-cleanup-script.sh"
|
|
159
|
+
CNPG_CLEANUP_SCRIPT="$CNPG_OPERATOR_DIR/$CNPG_CLEANUP_SCRIPT_BASH"
|
|
160
|
+
if [ ! -f "$CNPG_CLEANUP_SCRIPT" ];
|
|
161
|
+
then
|
|
162
|
+
cat<<CNPG_FETCH_CLEANUP_CRONJOB_YAML
|
|
163
|
+
`color y "Missing $CNPG_CLEANUP_SCRIPT_BASH - updating local cron setup scripts"`
|
|
164
|
+
|
|
165
|
+
CNPG_FETCH_CLEANUP_CRONJOB_YAML
|
|
166
|
+
CNPG_OP_ROOT="$(build-tools --reporoot)/src/helm-charts/cnpg-operator"
|
|
167
|
+
cp $CNPG_OP_ROOT/$CNPG_CLEANUP_CRONJOB_OVH $CNPG_CLEANUP_CRONJOB
|
|
168
|
+
cp $CNPG_OP_ROOT/$CNPG_CLEANUP_SCRIPT_BASH $CNPG_CLEANUP_SCRIPT
|
|
169
|
+
fi
|
|
170
|
+
|
|
171
|
+
# copy / update the script in the bucket referenced in the cronjob
|
|
172
|
+
printf "\ngsutil cp $CNPG_CLEANUP_SCRIPT gs://$GCP_PROJECT_ID-$BUCKET_SUFFIX\n"
|
|
173
|
+
gsutil cp $CNPG_CLEANUP_SCRIPT gs://$GCP_PROJECT_ID-$BUCKET_SUFFIX
|
|
174
|
+
|
|
175
|
+
local CNPG_NAMESPACE="cnpg-operands"
|
|
176
|
+
local CNPG_CLEANUP_SA="cnpg-cleanup-sa"
|
|
177
|
+
|
|
178
|
+
gcloud iam service-accounts create "$CNPG_CLEANUP_SA" \
|
|
179
|
+
--project="$GCP_PROJECT_ID" \
|
|
180
|
+
--description="Used for cronjob cleanup with Workload Identity" \
|
|
181
|
+
--display-name="CNPG Cleanup SA" &> $DEVNULL
|
|
182
|
+
warnOnError $? "the GCP SA $CNPG_CLEANUP_SA may already exist"
|
|
183
|
+
|
|
184
|
+
gcloud projects add-iam-policy-binding "$GCP_PROJECT_ID" \
|
|
185
|
+
--project="$GCP_PROJECT_ID" \
|
|
186
|
+
--member="serviceAccount:$CNPG_CLEANUP_SA@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
|
|
187
|
+
--role="roles/storage.objectViewer"
|
|
188
|
+
|
|
189
|
+
bindWorkloadIdentity "$CNPG_CLEANUP_SA" "$CNPG_NAMESPACE"
|
|
190
|
+
|
|
191
|
+
CNPG_CLEANUP_CRONJOB_YAML="$CNPG_OPERATOR_DIR/$(basename $CNPG_CLEANUP_CRONJOB_OVH .ovh)"
|
|
192
|
+
overwhelm -g # allow ovh -> yaml to occur
|
|
193
|
+
cat<<CNPG_CLEANUP_CRONJOB_APPLY
|
|
194
|
+
`color g "Creating cronjob =>"``color y " kubectl apply -f $CNPG_CLEANUP_CRONJOB_YAML"`
|
|
195
|
+
|
|
196
|
+
CNPG_CLEANUP_CRONJOB_APPLY
|
|
197
|
+
kubectl apply -f $CNPG_CLEANUP_CRONJOB_YAML
|
|
198
|
+
}
|
|
199
|
+
# Run it!
|
|
200
|
+
installCnpgOperatorEnvironment
|
|
201
|
+
installCnpgCleanupCronjob
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# Lifted from helmup.sh
|
|
4
|
+
#
|
|
5
|
+
# This function is used to randomly generate the postgresql database passwords
|
|
6
|
+
# for the postgres and imagine users in a cnpg operator configuration. Since
|
|
7
|
+
# the resultant passwords will live in the cnpg-operands namespace they will
|
|
8
|
+
# be mirrored to the default namespace via the reflector service. Lastly, the
|
|
9
|
+
# service account will have workload identity bound to it in the cnpg-operands
|
|
10
|
+
# namespace.
|
|
11
|
+
function initializeCnpgOperand() {
|
|
12
|
+
local CNPG_SERVICE="$1"
|
|
13
|
+
local CNPG_NAMESPACE="cnpg-operands"
|
|
14
|
+
local CNPG_SVC_ACCT="$CNPG_NAMESPACE-sa"
|
|
15
|
+
local IMAGINE_PW_NAME="$CNPG_SERVICE-imagine-pw"
|
|
16
|
+
local POSTGRES_PW_NAME="$CNPG_SERVICE-postgres-pw"
|
|
17
|
+
|
|
18
|
+
# TODO: we use postgres root password for access - that is bad - fix it?
|
|
19
|
+
# printf "\nCreating imagine db password for `color g $CNPG_SERVICE`\n"
|
|
20
|
+
# kubectl create secret generic -n $CNPG_NAMESPACE "$IMAGINE_PW_NAME" \
|
|
21
|
+
# --from-literal=username="imagine" \
|
|
22
|
+
# --from-literal=password="$(generatePassword)" &> $DEVNULL
|
|
23
|
+
# warnOnError $? "the `color y $IMAGINE_PW_NAME` secret may already exist"
|
|
24
|
+
|
|
25
|
+
# # reflect the secret to default namespace
|
|
26
|
+
# reflectSecretIntoNamespaces $IMAGINE_PW_NAME $CNPG_NAMESPACE "default"
|
|
27
|
+
|
|
28
|
+
printf "\nCreating postgres db password for `color g $CNPG_SERVICE`\n"
|
|
29
|
+
kubectl create secret generic -n $CNPG_NAMESPACE "$POSTGRES_PW_NAME" \
|
|
30
|
+
--from-literal=username="postgres" \
|
|
31
|
+
--from-literal=password="$(generatePassword)" &> $DEVNULL
|
|
32
|
+
warnOnError $? "the `color y $POSTGRES_PW_NAME` secret may already exist"
|
|
33
|
+
|
|
34
|
+
# reflect the secret to default namespace
|
|
35
|
+
reflectSecretIntoNamespaces $POSTGRES_PW_NAME $CNPG_NAMESPACE "default"
|
|
36
|
+
|
|
37
|
+
printf "\nBinding `color g $CNPG_SERVICE` to the `color y "$CNPG_SVC_ACCT"` SA\n"
|
|
38
|
+
bindWorkloadIdentity $CNPG_SVC_ACCT $CNPG_NAMESPACE $CNPG_SERVICE
|
|
39
|
+
}
|
|
40
|
+
# Run It!
|
|
41
|
+
initializeCnpgOperand "$SERVICE" # $SERVICE from helmup.sh
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
function setupPgbouncerSecret() {
|
|
4
|
+
# pgbouncer uses a k8s secret for the user access list which is in the form
|
|
5
|
+
# of => "user" "password" - this function will create the pgbouncer secret
|
|
6
|
+
# if it does not exist by pulling the password from the PG_PASSWORD secret
|
|
7
|
+
# managed by the Google Secret Manager service.
|
|
8
|
+
USERLIST_SECRET='pgbouncer-userlist-secret'
|
|
9
|
+
kubectl get secret $USERLIST_SECRET &> $DEVNULL
|
|
10
|
+
[[ $? -eq 0 ]] && return # already exists - bail
|
|
11
|
+
|
|
12
|
+
cat<<PGB_SECRET
|
|
13
|
+
|
|
14
|
+
`color y "Creatng $USERLIST_SECRET k8s secret from secret manager PG_PASSWORD secret..."`
|
|
15
|
+
|
|
16
|
+
PGB_SECRET
|
|
17
|
+
DECODED_PSQL_PASSWORD=$(gcloud secrets versions access latest --secret=PG_PASSWORD --project $GCP_PROJECT_ID)
|
|
18
|
+
exitOnError $? "Failed to fetch PG_PASSWORD from the secret manager"
|
|
19
|
+
|
|
20
|
+
kubectl create secret generic $USERLIST_SECRET --from-literal=userlist.txt="\"postgres\" \"$DECODED_PSQL_PASSWORD\""
|
|
21
|
+
exitOnError $? "Failed to create the $USERLIST_SECRET k8s secret"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
setupPgbouncerSecret
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# This function came from the helmup.sh script and is used to install the
|
|
4
|
+
# stackdriver exporter in the prometheus or monitoring (legacy) namespace.
|
|
5
|
+
# This function only needs to execute once, at initial setup / configuration.
|
|
6
|
+
function installStackdriverExporterEnvironment() {
|
|
7
|
+
showInstalling "Stackdriver Exporter Service Account Binding"
|
|
8
|
+
|
|
9
|
+
# Add necessary helm repositories - note that stable is deprecated
|
|
10
|
+
addHelmRepo prometheus-community https://prometheus-community.github.io/helm-charts
|
|
11
|
+
|
|
12
|
+
local SDEXP_NS=${1:-prometheus}
|
|
13
|
+
local SDEXP_SA="stackdriver-exporter"
|
|
14
|
+
local SDEXP_EM="$SDEXP_SA@$GCP_PROJECT_ID.iam.gserviceaccount.com"
|
|
15
|
+
|
|
16
|
+
createNamespaceIfNeeded $SDEXP_NS
|
|
17
|
+
|
|
18
|
+
# guarantee any previous remnants of the exporter are gone
|
|
19
|
+
printf "\n*** Removing the previous $SDEXP_SA installation...\n"
|
|
20
|
+
helm uninstall -n $SDEXP_NS $SDEXP_SA &> $DEVNULL
|
|
21
|
+
kubectl delete serviceaccounts -n $SDEXP_NS $SDEXP_SA &> $DEVNULL
|
|
22
|
+
printf "!!! Skipping deletion of the gcloud SA $SDEXP_EM\n"
|
|
23
|
+
# gcloud --quiet iam service-accounts delete $SDEXP_EM &> $DEVNULL
|
|
24
|
+
|
|
25
|
+
# NOTE: The k8s SA != GCP SA - the former is created by the helm chart
|
|
26
|
+
# that installs the stackdriver-exporter, the latter is handled here in
|
|
27
|
+
# order to provide the proper IAM permissions to the exporter.
|
|
28
|
+
|
|
29
|
+
# Create GCP SA and bind policies
|
|
30
|
+
printf "\n*** Creating GCP SA with $SDEXP_NS/viewer ***\n"
|
|
31
|
+
gcloud iam service-accounts create $SDEXP_SA \
|
|
32
|
+
--project "$GCP_PROJECT_ID" \
|
|
33
|
+
--display-name "Prometheus Stackdriver Exporter" &> $DEVNULL
|
|
34
|
+
warnOnError $? "the GCP SA $SDEXP_SA may already exist"
|
|
35
|
+
|
|
36
|
+
printf "\n*** Binding IAM role of $SDEXP_NS viewer to $SDEXP_SA in $GCP_PROJECT_ID\n"
|
|
37
|
+
gcloud projects add-iam-policy-binding "$GCP_PROJECT_ID" \
|
|
38
|
+
--role "roles/monitoring.viewer" \
|
|
39
|
+
--member "serviceAccount:$SDEXP_EM" &> $DEVNULL
|
|
40
|
+
sleep 2 # give the IAM binding a chance to complete before moving on
|
|
41
|
+
|
|
42
|
+
bindWorkloadIdentity $SDEXP_SA $SDEXP_NS
|
|
43
|
+
|
|
44
|
+
removeHelmRepo prometheus-community
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
installStackdriverExporterEnvironment
|
|
@@ -31,8 +31,8 @@ spec:
|
|
|
31
31
|
# VALUE = {{ $value }}
|
|
32
32
|
# LABELS = {{ $labels }}
|
|
33
33
|
- alert: TraefikHighHttp5xxErrorRateService
|
|
34
|
-
expr: sum(rate(traefik_service_requests_total{code=~"5.*"}[
|
|
35
|
-
for: 1m
|
|
34
|
+
expr: sum(rate(traefik_service_requests_total{code=~"5.*"}[5m])) by (service) / sum(rate(traefik_service_requests_total[5m])) by (service) * 100 > 5
|
|
35
|
+
for: 5m # awesome was => 1m
|
|
36
36
|
labels:
|
|
37
37
|
severity: critical
|
|
38
38
|
annotations:
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# lifted from helmup.sh
|
|
4
|
+
function installVeleroEnvironment() {
|
|
5
|
+
# Follows instructions => https://github.com/vmware-tanzu/velero-plugin-for-gcp
|
|
6
|
+
showInstalling "Velero Backup Management"
|
|
7
|
+
createNamespaceIfNeeded velero
|
|
8
|
+
|
|
9
|
+
# Do we need to => gcloud auth application-default
|
|
10
|
+
gcloud config set project $GCP_PROJECT_ID
|
|
11
|
+
|
|
12
|
+
## The major chart version will determine the bucket suffix
|
|
13
|
+
[ -z "$VELERO_CHART_VERSION" ] && VELERO_CHART_VERSION="10"
|
|
14
|
+
|
|
15
|
+
## Create a bucket
|
|
16
|
+
BUCKET="$GCP_PROJECT_ID-velero-$VELERO_CHART_VERSION"
|
|
17
|
+
printf "\nCreating storage bucket `color g $BUCKET` in `color g $GCE_REGION`\n"
|
|
18
|
+
gsutil mb -l $GCE_REGION gs://$BUCKET/ &> $DEVNULL
|
|
19
|
+
warnOnError $? "Bucket failed to create or already exists - go check it\n"
|
|
20
|
+
gsutil ubla set on gs://$BUCKET &> $DEVNULL
|
|
21
|
+
|
|
22
|
+
## Create a service account
|
|
23
|
+
printf "\nCreating the service account\n"
|
|
24
|
+
gcloud iam service-accounts create velero \
|
|
25
|
+
--project $GCP_PROJECT_ID \
|
|
26
|
+
--display-name "Velero service account" \
|
|
27
|
+
--description "Velero service account" &> $DEVNULL
|
|
28
|
+
if [ $? -eq 0 ];
|
|
29
|
+
then
|
|
30
|
+
# no error means a new SA was created - slight delay to let it update
|
|
31
|
+
sleep 2
|
|
32
|
+
else
|
|
33
|
+
printf "$YELO_WARN Failed to create the service account - does it already exist?"
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
SERVICE_ACCOUNT_EMAIL="velero@${GCP_PROJECT_ID}.iam.gserviceaccount.com"
|
|
37
|
+
|
|
38
|
+
## Attach roles
|
|
39
|
+
ROLE_PERMISSIONS=(
|
|
40
|
+
compute.disks.get
|
|
41
|
+
compute.disks.create
|
|
42
|
+
compute.disks.createSnapshot
|
|
43
|
+
compute.projects.get
|
|
44
|
+
compute.snapshots.get
|
|
45
|
+
compute.snapshots.create
|
|
46
|
+
compute.snapshots.useReadOnly
|
|
47
|
+
compute.snapshots.delete
|
|
48
|
+
compute.zones.get
|
|
49
|
+
iam.serviceAccounts.actAs
|
|
50
|
+
iam.serviceAccounts.signBlob
|
|
51
|
+
storage.objects.create
|
|
52
|
+
storage.objects.delete
|
|
53
|
+
storage.objects.get
|
|
54
|
+
storage.objects.list
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
printf "\nAssigning roles to the SA\n"
|
|
58
|
+
gcloud iam roles create velero.server \
|
|
59
|
+
--project $GCP_PROJECT_ID \
|
|
60
|
+
--title "Velero Server" \
|
|
61
|
+
--permissions "$(IFS=","; echo "${ROLE_PERMISSIONS[*]}")" &> $DEVNULL
|
|
62
|
+
if [ $? -ne 0 ];
|
|
63
|
+
then
|
|
64
|
+
# assume error is that role exists so try updating instead
|
|
65
|
+
printf "\nUpdating roles on the SA\n"
|
|
66
|
+
gcloud iam roles update velero.server \
|
|
67
|
+
--project $GCP_PROJECT_ID \
|
|
68
|
+
--title "Velero Server" \
|
|
69
|
+
--permissions "$(IFS=","; echo "${ROLE_PERMISSIONS[*]}")" &> $DEVNULL
|
|
70
|
+
fi
|
|
71
|
+
warnOnError $? "Failed to add roles to velero.server - perhaps they already exist?"
|
|
72
|
+
|
|
73
|
+
printf "\nBinding IAM policy to the SA\n"
|
|
74
|
+
gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
|
|
75
|
+
--project $GCP_PROJECT_ID \
|
|
76
|
+
--member serviceAccount:$SERVICE_ACCOUNT_EMAIL \
|
|
77
|
+
--condition 'None' \
|
|
78
|
+
--role projects/$GCP_PROJECT_ID/roles/velero.server &> $DEVNULL
|
|
79
|
+
warnOnError $? "gcloud problem binding IAM policy"
|
|
80
|
+
|
|
81
|
+
printf "\nBinding workload identity IAM policy to the SA\n"
|
|
82
|
+
gcloud iam service-accounts add-iam-policy-binding \
|
|
83
|
+
--member "serviceAccount:$GCP_PROJECT_ID.svc.id.goog[velero/velero]" \
|
|
84
|
+
--role roles/iam.workloadIdentityUser \
|
|
85
|
+
$SERVICE_ACCOUNT_EMAIL
|
|
86
|
+
warnOnError $? "gcloud workload identity binding may have failed"
|
|
87
|
+
|
|
88
|
+
printf "\nCreate and annotate the k8s SA\n"
|
|
89
|
+
kubectl create serviceaccount velero --namespace velero
|
|
90
|
+
warnOnError $? "Failed to create k8s SA - perhaps it already exists?"
|
|
91
|
+
|
|
92
|
+
kubectl annotate serviceaccount velero \
|
|
93
|
+
--namespace velero \
|
|
94
|
+
"iam.gke.io/gcp-service-account=$SERVICE_ACCOUNT_EMAIL"
|
|
95
|
+
warnOnError $? "Failed to annotate k8s SA - things may fail"
|
|
96
|
+
|
|
97
|
+
gsutil iam ch serviceAccount:$SERVICE_ACCOUNT_EMAIL:objectAdmin gs://$BUCKET
|
|
98
|
+
|
|
99
|
+
## Clean up from previous failed install
|
|
100
|
+
# kubectl delete volumesnapshotlocation.velero.io -n velero gcp &> $DEVNULL
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# Run It!
|
|
104
|
+
installVeleroEnvironment
|