Skip to content

Commit 38fb4a2

Browse files
authored
Merge pull request #762 from PureStorage-OpenConnect/761-pxb-refactor
refactor pxb scripts
2 parents dce513a + 3837afd commit 38fb4a2

File tree

11 files changed

+145
-160
lines changed

11 files changed

+145
-160
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: px-backup-api-grpc
5+
namespace: central
6+
spec:
7+
ports:
8+
- name: grpc
9+
port: 10002
10+
protocol: TCP
11+
targetPort: 10002
12+
selector:
13+
app: px-backup
14+
type: NodePort

assets/helm-backup/namespace.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: central
5+
---
6+
apiVersion: v1
7+
kind: Secret
8+
metadata:
9+
name: pxc-credentials
10+
namespace: central
11+
data:
12+
mongodb-px-backup-password: UDBydHdvcnhCYWNrdXA=
13+
mongodb-root-password: UDBydHdvcnhCYWNrdXA=
14+
mongodb-replica-set-key: UDBydHdvcnhCYWNrdXA=
15+
postgresql-password: UDBydHdvcnhCYWNrdXA=
16+
mysql-password: UDBydHdvcnhCYWNrdXA=
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
kind: Route
2+
apiVersion: route.openshift.io/v1
3+
metadata:
4+
name: px-backup-ui
5+
namespace: central
6+
spec:
7+
to:
8+
kind: Service
9+
name: px-backup-ui
10+
weight: 100
11+
port:
12+
targetPort: http
13+
wildcardPolicy: None
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
kind: Route
2+
apiVersion: route.openshift.io/v1
3+
metadata:
4+
name: px-central-ui
5+
namespace: central
6+
spec:
7+
to:
8+
kind: Service
9+
name: px-central-ui
10+
weight: 100
11+
port:
12+
targetPort: http
13+
wildcardPolicy: None
14+

scripts/helm-backup

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
NAMESPACE=central
2-
VERSION=2.10.1
3-
4-
kubectl apply -f - <<EOF
5-
apiVersion: v1
6-
kind: Namespace
7-
metadata:
8-
name: central
9-
---
10-
apiVersion: v1
11-
kind: Secret
12-
metadata:
13-
name: pxc-credentials
14-
namespace: central
15-
data:
16-
mongodb-px-backup-password: UDBydHdvcnhCYWNrdXA=
17-
mongodb-root-password: UDBydHdvcnhCYWNrdXA=
18-
mongodb-replica-set-key: UDBydHdvcnhCYWNrdXA=
19-
postgresql-password: UDBydHdvcnhCYWNrdXA=
20-
mysql-password: UDBydHdvcnhCYWNrdXA=
21-
EOF
2+
VERSION=2.10.2
3+
4+
kubectl apply -f /assets/helm-backup/namespace.yml
225

236
curl -O https://raw.githubusercontent.com/portworx/helm/master/stable/px-central-$VERSION.tgz
247
helm install px-central px-central-$VERSION.tgz --namespace $NAMESPACE --create-namespace --version $VERSION --set persistentStorage.enabled=true,persistentStorage.storageClassName="px-csi-db",pxbackup.enabled=true,oidc.centralOIDC.updateAdminProfile=false,installCRDs=true
@@ -44,6 +27,51 @@ kubectl delete job pxcentral-post-install-hook --namespace $NAMESPACE
4427
helm upgrade px-central px-central-$VERSION.tgz --namespace $NAMESPACE --version $VERSION --reuse-values --set pxmonitor.enabled=true --set pxmonitor.pxCentralEndpoint=$pubIP:$backupPort
4528
until (kubectl get po -n $NAMESPACE -ljob-name=pxcentral-post-install-hook -o wide | awk '{print $1, $2, $3}' |grep "Completed"); do echo "Waiting for post install hook";sleep 3; done
4629

47-
#BACKUP_POD_NAME=$(kubectl get pods -n $NAMESPACE -l app=px-backup -o jsonpath='{.items[0].metadata.name}' 2>/dev/null)
48-
#kubectl cp -n $NAMESPACE $BACKUP_POD_NAME:pxbackupctl/linux/pxbackupctl /usr/bin/pxbackupctl
49-
#chmod +x /usr/bin/pxbackupctl
30+
ADMIN_PW=$(kubectl get secret pxcentral-keycloak-http -n central -o jsonpath="{.data.password}" | base64 --decode)
31+
32+
while [ ! -f /usr/local/bin/px ]; do
33+
echo "missing px cli. please install manually in /usr/local/bin to proceed"
34+
sleep 30
35+
done
36+
37+
if [ "$platform" = ocp4 ]; then
38+
# create ocp route for backup UI
39+
kubectl apply -f /assets/helm-backup/ocp-backup-ui-route.yml
40+
kubectl apply -f /assets/helm-backup/ocp-central-ui-route.yml
41+
42+
# expose px-backup service to run pxbackupctl
43+
kubectl patch svc px-backup -n central -p '{"spec":{"type":"LoadBalancer"}}'
44+
backupIP=$(kubectl get svc px-backup -n central -o json | jq -r ".status.loadBalancer.ingress[0].hostname")
45+
46+
while [ $backupIP = "null" ]; do
47+
sleep 2
48+
echo "PX Backup grpc LB not assigned"
49+
backupIP=$(kubectl get svc px-backup -n central -o json | jq -r ".status.loadBalancer.ingress[0].hostname")
50+
done
51+
echo "PX Backup grpc LB assigned: $backupIP"
52+
53+
backupPort=10002
54+
authIP=$(kubectl get route px-central-ui -n central -o json |jq -r ".status.ingress[0].host")
55+
authPort=80
56+
PXB_URL=$(kubectl get route px-backup-ui -n central -o json |jq -r ".status.ingress[0].host")
57+
58+
else # platform is k8s on aws
59+
IMDSTOKEN=$(curl -s -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 120')
60+
backupIP=$(curl -H "X-aws-ec2-metadata-token: $IMDSTOKEN" -s http://169.254.169.254/latest/meta-data/public-ipv4)
61+
authIP=$backupIP
62+
authPort=$(kubectl get svc px-central-ui -n central -o=jsonpath='{.spec.ports[?(@.port==80)].nodePort}')
63+
#expose px-backup api grpc endpoint
64+
kubectl apply -f /assets/helm-backup/backup-grpc-api-svc.yml
65+
backupPort=$(kubectl get svc px-backup-api-grpc -n central -o=jsonpath='{.spec.ports[?(@.port==10002)].nodePort}')
66+
PXB_URL=$(kubectl get svc px-backup-ui -n central -o=jsonpath='{.status.loadBalancer.ingress[0].hostname}')
67+
fi
68+
69+
px pxb init config --px-backup-api-url http://$backupIP:$backupPort --pxcentral-auth-url http://$authIP:$authPort
70+
px pxb set config --pxcentral-verify-ssl false
71+
px pxb login --username admin --password $ADMIN_PW
72+
73+
while ! px pxb version; do
74+
echo "waiting for grpc availability"
75+
sleep 2
76+
done
77+

scripts/helm-backup-apps

Lines changed: 0 additions & 133 deletions
This file was deleted.

scripts/helm-backup-postinstall

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
AWS_ACCESS_KEY=$(sed -n 's/aws_access_key_id[ =]*//p' /root/.aws/credentials 2>/dev/null)
2+
AWS_SECRET_KEY=$(sed -n 's/aws_secret_access_key[ =]*//p' /root/.aws/credentials 2>/dev/null)
3+
4+
ADMIN_PW=$(kubectl get secret pxcentral-keycloak-http -n central -o jsonpath="{.data.password}" | base64 --decode)
5+
6+
px pxb create cloudcredential --name aws-credential --provider aws --aws-access-key $AWS_ACCESS_KEY --aws-secret-key $AWS_SECRET_KEY
7+
px pxb create backuplocation --name s3 --provider s3 --path $BACKUP_BUCKET --cloud-credential-name aws-credential --s3-endpoint s3.amazonaws.com --s3-region $aws_region
8+
px pxb create schedulepolicy --name 15min-schedule --interval-minutes 15 --interval-retain 12
9+
10+
px pxb connect cluster --name cluster-1 --kubeconfig /root/.kube/config
11+
12+
for i in $(seq 2 $clusters); do
13+
ssh master-$i cat /root/.kube/config > /tmp/cluster-$i-kube-config
14+
px pxb connect cluster --name cluster-$i --kubeconfig /tmp/cluster-$i-kube-config
15+
done
16+
17+
if [ "$platform" = ocp4 ]; then
18+
PXB_URL=$(kubectl get route px-backup-ui -n central -o json |jq -r ".status.ingress[0].host")
19+
else
20+
PXB_URL=$(kubectl get svc px-backup-ui -n central -o=jsonpath='{.status.loadBalancer.ingress[0].hostname}')
21+
fi
22+
23+
cat <<EOF >> /etc/motd
24+
+================================================+
25+
SAVE THE FOLLOWING DETAILS FOR FUTURE REFERENCES
26+
+================================================+
27+
PX-Central User Interface Access URL : http://$PXB_URL
28+
PX-Central admin user name: admin
29+
PX-Central admin user password: $ADMIN_PW
30+
+================================================+
31+
EOF
32+

scripts/install-px

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ done
141141
kubectl apply -f /tmp/px.yml
142142

143143
# Install px cli
144-
curl -L -o /tmp/pxcli.tgz https://mirrors.portworx.com/packages/px-cli/v1.0.0/px-v1.0.0.linux.amd64.tar.gz
144+
curl -L -o /tmp/pxcli.tgz https://mirrors.portworx.com/packages/px-cli/v1.1.0/px-v1.1.0.linux.amd64.tar.gz
145145
tar -xzf /tmp/pxcli.tgz -C /tmp/
146146
chmod +x /tmp/px/bin/px*
147147
cp /tmp/px/bin/* /usr/local/bin/

templates/ocp-backup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ clusters: 2
77
nodes: 5
88
cluster:
99
- id: 1
10-
scripts: ["helm-backup", "helm-backup-apps"]
10+
scripts: ["helm-backup", "helm-backup-postinstall"]
1111
- id: 2
1212
scripts: ["clusterpair"]
1313
env:

templates/ocp-kubevirt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cloud: "aws"
99
clusters: 2
1010
cluster:
1111
- id: 1
12-
scripts: [ "kubevirt-apps", "helm-backup", "helm-backup-apps"]
12+
scripts: [ "kubevirt-apps", "helm-backup", "helm-backup-postinstall"]
1313
- id: 2
1414
scripts: ["clusterpair"]
1515
env:

0 commit comments

Comments
 (0)