Skip to content

Commit 72447e0

Browse files
authored
Merge pull request #578 from andrewh1978/grafana
refactor grafana steps
2 parents 8f7433b + 5a63c83 commit 72447e0

File tree

5 files changed

+47
-77
lines changed

5 files changed

+47
-77
lines changed

scripts/clusterpair-metro

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
# Configures a clusterpair from cluster 1 to this cluster
2-
if [ "$operator" = false ]; then
3-
NAMESPACE=kube-system
4-
else
5-
NAMESPACE=portworx
6-
fi
72
while : ; do
8-
POD=$(kubectl get pods -n $NAMESPACE -lname=portworx --field-selector=status.phase=Running | tail -1 | cut -f 1 -d " ")
3+
POD=$(kubectl get pods -n portworx -lname=portworx --field-selector=status.phase=Running | tail -1 | cut -f 1 -d " ")
94
if [ "$security" = true ]; then
10-
ADMIN_TOKEN=$(kubectl -n $NAMESPACE get secret px-admin-token -o json | jq -r '.data."auth-token"' | base64 -d)
11-
kubectl -n $NAMESPACE exec -ti $POD -c portworx -- /opt/pwx/bin/pxctl context create admin --token=$ADMIN_TOKEN
5+
ADMIN_TOKEN=$(kubectl -n portworx get secret px-admin-token -o json | jq -r '.data."auth-token"' | base64 -d)
6+
kubectl -n portworx exec -ti $POD -c portworx -- /opt/pwx/bin/pxctl context create admin --token=$ADMIN_TOKEN
127
fi
13-
token=$(kubectl exec -n $NAMESPACE -it $POD -- /opt/pwx/bin/pxctl cluster token show 2>/dev/null | cut -f 3 -d " ")
8+
token=$(kubectl exec -n portworx -it $POD -- /opt/pwx/bin/pxctl cluster token show 2>/dev/null | cut -f 3 -d " ")
149
echo $token | grep -Eq '\w{128}'
1510
[ $? -eq 0 ] && break
1611
sleep 5

scripts/install-px

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,11 @@
77

88
# Default secrets store is k8s; can also set environment variable secrets=vault
99

10-
# If you do not want to deploy using the operator, set the environment variable operator=false, and then the DaemonSet will be used
11-
1210
# You can also set csi=true and security=true
1311

1412
# If you select cloud=vsphere, clouddrives will be provisioned from vsphere_disks
1513

16-
if [ "$operator" != false ]; then
17-
namespace=portworx
18-
kubectl create namespace portworx
19-
else
20-
namespace=kube-system
21-
fi
14+
kubectl create namespace portworx
2215
if [ $cloud = vsphere ]; then
2316
VSPHERE_USER=$(printf $vsphere_user | base64)
2417
VSPHERE_PASSWORD=$(printf $vsphere_password | base64)
@@ -27,7 +20,7 @@ apiVersion: v1
2720
kind: Secret
2821
metadata:
2922
name: px-vsphere-secret
30-
namespace: $namespace
23+
namespace: portworx
3124
type: Opaque
3225
data:
3326
VSPHERE_USER: $VSPHERE_USER
@@ -40,7 +33,7 @@ EOF
4033
fi
4134

4235
k8s_version=$((kubectl version --short 2>&1 || kubectl version) | awk -Fv '/Server Version: / {print $3}')
43-
url="https://install.portworx.com/$px_version?kbver=$k8s_version&b=true&c=px-deploy-$cluster&stork=true&st=k8s&lh=true&mon=true&promop=true"
36+
url="https://install.portworx.com/$px_version?kbver=$k8s_version&b=true&c=px-deploy-$cluster&stork=true&st=k8s&lh=true&mon=true&promop=true&operator=true"
4437
[ -e /usr/bin/oc ] && url="$url&osft=true"
4538
if [ "$cloud_drive" ]; then
4639
if [ "$cloud" = "azure" ]; then
@@ -61,7 +54,6 @@ fi
6154
[ "$vsphere_suffix" ] && url="$url&$vsphere_suffix"
6255
[ "$platform" = eks ] && url="$url&eks=true"
6356
[ "$platform" = ocp4 ] && url="$url&r=17001"
64-
[ "$operator" = false ] || url="$url&operator=true"
6557
[ "$security" = true ] && url="$url&security=true"
6658
[ -n "$csi" ] && url="$url&csi=$csi"
6759
#[ "$etcd" = EXTERNAL ] && url="$url&k=etcd:http://$(ssh master-1 curl https://ipinfo.io/ip):2382"
@@ -98,7 +90,7 @@ EOF
9890
done
9991
fi
10092

101-
if [ "$operator" != false -a "$platform" != ocp4 ]; then
93+
if [ "$platform" != ocp4 ]; then
10294
kubectl apply -f "https://install.portworx.com/$px_version?comp=pxoperator&kbver=$k8s_version"
10395
while ! kubectl wait --for=condition=ready pod -lname=portworx-operator -n kube-system; do
10496
sleep 2
@@ -120,11 +112,9 @@ if [ "$platform" = aks ]; then
120112
fi
121113

122114
curl -sko /tmp/px.yml $url
123-
if [ "$operator" != false ]; then
124-
sed -i 's/namespace: kube-system/namespace: portworx/' /tmp/px.yml
125-
sed -i 's/imagePullPolicy: Always/imagePullPolicy: IfNotPresent/' /tmp/px.yml
126-
[ -f "/tmp/metro" ] && clusterdomain=$(cat /tmp/metro) && sed -i '/ annotations:/a\ \ \ \ '"$clusterdomain"'' /tmp/px.yml
127-
fi
115+
sed -i 's/namespace: kube-system/namespace: portworx/' /tmp/px.yml
116+
sed -i 's/imagePullPolicy: Always/imagePullPolicy: IfNotPresent/' /tmp/px.yml
117+
[ -f "/tmp/metro" ] && clusterdomain=$(cat /tmp/metro) && sed -i '/ annotations:/a\ \ \ \ '"$clusterdomain"'' /tmp/px.yml
128118
kubectl apply -f /tmp/px.yml
129119

130120
wait
@@ -138,34 +128,45 @@ curl -so /usr/local/bin/pxc-pxctl https://raw.githubusercontent.com/portworx/pxc
138128
mv /tmp/pxc/kubectl-pxc /usr/bin
139129
chmod +x /usr/local/bin/pxc-pxctl
140130
echo "alias pxctl='kubectl pxc pxctl'" >>/root/.bashrc
141-
[ "$operator" != false ] && kubectl-pxc config cluster set --portworx-service-namespace=portworx
142-
143-
# Install Grafana / wait for storagecluster readiness
144-
if [ "$operator" != false ]; then
145-
kubectl -n portworx create configmap grafana-dashboard-config --from-file=grafana-dashboard-config.yaml=<(curl -s https://docs.portworx.com/samples/k8s/pxc/grafana-dashboard-config.yaml)
131+
kubectl-pxc config cluster set --portworx-service-namespace=portworx
132+
133+
# Install Grafana
134+
if [ $platform = ocp4 ]; then
135+
kubectl apply -f <(curl -s https://docs.portworx.com/samples/portworx-enterprise/k8s/pxc/grafana-service-account.yaml | sed s/kube-system/portworx/)
136+
oc -n portworx adm policy add-cluster-role-to-user cluster-monitoring-view -z grafana
137+
TOKEN=$(oc -n portworx create token grafana --duration=8760h)
138+
THANOS=$(oc get route thanos-querier -n openshift-monitoring -o json | jq -r '.spec.host')
139+
kubectl -n portworx create configmap grafana-source-config --from-file=grafana-datasource-ocp.yaml=<(curl -s https://docs.portworx.com/samples/portworx-enterprise/k8s/pxc/grafana-datasource-ocp.yaml | sed "s/<THANOS_QUERIER_HOST>/$THANOS/;s/<BEARER_TOKEN>/$TOKEN/g")
140+
kubectl apply -f <(curl -s https://docs.portworx.com/samples/portworx-enterprise/k8s/pxc/grafana-ocp.yaml | sed s/kube-system/portworx/)
141+
else
146142
kubectl -n portworx create configmap grafana-source-config --from-file=grafana-datasource.yaml=<(curl -s https://docs.portworx.com/samples/k8s/pxc/grafana-datasource.yaml)
147-
kubectl -n portworx create configmap grafana-dashboards --from-file=portworx-cluster-dashboard.json=<(curl -s https://docs.portworx.com/samples/k8s/pxc/portworx-cluster-dashboard.json) --from-file=portworx-node-dashboard.json=<(curl -s https://docs.portworx.com/samples/k8s/pxc/portworx-node-dashboard.json) --from-file=portworx-volume-dashboard.json=<(curl -s https://docs.portworx.com/samples/k8s/pxc/portworx-volume-dashboard.json) --from-file=portworx-etcd-dashboard.json=<(curl -s https://docs.portworx.com/samples/k8s/pxc/portworx-etcd-dashboard.json) --from-file=portworx-performance-dashboard.json=<(curl -s https://docs.portworx.com/samples/k8s/pxc/portworx-performance-dashboard.json)
148-
kubectl apply -f <(curl -s https://docs.portworx.com/samples/k8s/pxc/grafana.yaml | sed s/kube-system/portworx/)
149-
if [ $platform != eks ] && [ $platform != gke ] && [ $platform != ocp4 ] && [ $platform != rancher ] && [ $platform != aks ]; then
150-
kubectl patch svc grafana -n portworx -p '{"spec": { "type": "NodePort", "ports": [ { "nodePort": 30112, "port": 3000, "protocol": "TCP", "targetPort": 3000 } ] } }'
151-
while ! curl -m 1 -s -X POST -H "Content-Type: application/json" -d '{"Name":"portworx","type":"prometheus","access":"server","url":"http://px-prometheus:9090"}' http://admin:admin@localhost:30112/api/datasources; do
152-
echo waiting for grafana
153-
sleep 2
154-
done
155-
curl -s -X PUT -H "Content-Type: application/json" -d '{"oldPassword":"admin","newPassword":"admin","confirmNew":"admin"}' http://admin:admin@localhost:30112/api/user/password
156-
fi
157-
while ! kubectl get stc -A -n $namespace | grep -q 'Running\|Online'; do
158-
echo "Waiting for StorageCluster status online"
159-
sleep 3
143+
kubectl apply -f <(curl -s https://docs.portworx.com/samples/portworx-enterprise/k8s/pxc/grafana.yaml | sed s/kube-system/portworx/)
144+
fi
145+
kubectl -n portworx create configmap grafana-dashboard-config --from-file=grafana-dashboard-config.yaml=<(curl -s https://docs.portworx.com/samples/k8s/pxc/grafana-dashboard-config.yaml)
146+
kubectl -n portworx create configmap grafana-dashboards --from-file=portworx-cluster-dashboard.json=<(curl -s https://docs.portworx.com/samples/k8s/pxc/portworx-cluster-dashboard.json) --from-file=portworx-node-dashboard.json=<(curl -s https://docs.portworx.com/samples/k8s/pxc/portworx-node-dashboard.json) --from-file=portworx-volume-dashboard.json=<(curl -s https://docs.portworx.com/samples/k8s/pxc/portworx-volume-dashboard.json) --from-file=portworx-etcd-dashboard.json=<(curl -s https://docs.portworx.com/samples/k8s/pxc/portworx-etcd-dashboard.json) --from-file=portworx-performance-dashboard.json=<(curl -s https://docs.portworx.com/samples/portworx-enterprise/k8s/pxc/portworx-performance-dashboard.json)
147+
148+
# Patch Grafana
149+
if [ $platform != eks ] && [ $platform != gke ] && [ $platform != ocp4 ] && [ $platform != rancher ] && [ $platform != aks ]; then
150+
kubectl patch svc grafana -n portworx -p '{"spec": { "type": "NodePort", "ports": [ { "nodePort": 30112, "port": 3000, "protocol": "TCP", "targetPort": 3000 } ] } }'
151+
while ! curl -m 1 -s -X POST -H "Content-Type: application/json" -d '{"Name":"portworx","type":"prometheus","access":"server","url":"http://px-prometheus:9090"}' http://admin:admin@localhost:30112/api/datasources; do
152+
echo waiting for grafana
153+
sleep 2
160154
done
155+
curl -s -X PUT -H "Content-Type: application/json" -d '{"oldPassword":"admin","newPassword":"admin","confirmNew":"admin"}' http://admin:admin@localhost:30112/api/user/password
161156
fi
162157

158+
# Wait for cluster readiness
159+
while ! kubectl get stc -A -n portworx | grep -q 'Running\|Online'; do
160+
echo "Waiting for StorageCluster status online"
161+
sleep 3
162+
done
163+
163164
# install storkctl
164-
STORK_POD=$(kubectl get pods -n $namespace -l name=stork -o jsonpath='{.items[0].metadata.name}')
165-
while ! kubectl cp -n $namespace $STORK_POD:/storkctl/linux/storkctl /usr/local/bin/storkctl ; do
165+
STORK_POD=$(kubectl get pods -n portworx -l name=stork -o jsonpath='{.items[0].metadata.name}')
166+
while ! kubectl cp -n portworx $STORK_POD:/storkctl/linux/storkctl /usr/local/bin/storkctl ; do
166167
echo "trying to kubectl cp storkctl out of $STORK_POD"
167168
sleep 2
168-
STORK_POD=$(kubectl get pods -n $namespace -l name=stork -o jsonpath='{.items[0].metadata.name}')
169+
STORK_POD=$(kubectl get pods -n portworx -l name=stork -o jsonpath='{.items[0].metadata.name}')
169170
done
170171
chmod +x /usr/local/bin/storkctl
171172

scripts/licenses

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@ for i in $licenses; do
1212
done
1313

1414
for i in $licenses; do
15-
if [ "$operator" = false ]; then
16-
NAMESPACE=kube-system
17-
else
18-
NAMESPACE=portworx
19-
fi
2015
if [ "$security" = true ]; then
21-
ADMIN_TOKEN=$(kubectl -n $NAMESPACE get secret px-admin-token -o json | jq -r '.data."auth-token"' | base64 -d)
16+
ADMIN_TOKEN=$(kubectl -n portworx get secret px-admin-token -o json | jq -r '.data."auth-token"' | base64 -d)
2217
fi
23-
while ! kubectl exec -n $NAMESPACE -c portworx -it $(kubectl get pods -n $NAMESPACE -lname=portworx --field-selector=status.phase=Running | tail -1 | cut -f 1 -d " ") -- bash <<EOF
18+
while ! kubectl exec -n portworx -c portworx -it $(kubectl get pods -n portworx -lname=portworx --field-selector=status.phase=Running | tail -1 | cut -f 1 -d " ") -- bash <<EOF
2419
/opt/pwx/bin/pxctl context create admin --token=$ADMIN_TOKEN
2520
/opt/pwx/bin/pxctl license activate $i
2621
EOF

scripts/metro-post

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,6 @@ else
66
port=9001
77
fi
88

9-
#while : ; do
10-
# n=$(ssh master-1 'kubectl exec -it -n portworx -c portworx $(kubectl get pod -n portworx -lname=portworx -o jsonpath="{.items[0].metadata.name}") -- curl http://localhost:'$port'/status | jq .QuorumMap | grep true | wc -l')
11-
# [ $n -eq $[$nodes*$clusters] ] && break
12-
# sleep 1
13-
# echo Waiting for Portworx cluster to come up before patching
14-
#done
15-
16-
#if [ "$operator" = false ]; then
17-
# x=$(kubectl get ds/portworx -n kube-system -o json | jq -c '.spec.template.spec.containers[0].args')
18-
# x="${x%]},-cluster_domain, cluster-$cluster]"
19-
# kubectl patch ds/portworx -n kube-system --type json -p="[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/args\", \"value\":$x}]"
20-
#else
21-
# kubectl patch stc metro-cluster -n portworx --type json -p='[{"op": "add", "path": "/metadata/annotations/portworx.io~1misc-args", "value":"-cluster_domain cluster-'$cluster'"}]'
22-
# echo
23-
#fi
24-
259
while : ; do
2610
n=$(ssh master-1 'kubectl exec -it -n portworx -c portworx $(kubectl get pod -n portworx -lname=portworx -o jsonpath="{.items[0].metadata.name}") -- curl http://localhost:'$port'/status | jq .QuorumMap | grep true | wc -l')
2711
[ $n -eq $[$nodes*$clusters] ] && break

scripts/px-wait

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
# Wait for Portworx to be running on every node in the cluster
22
while : ; do
3-
if [ "$operator" = "false" ]; then
4-
namespace=kube-system
5-
else
6-
namespace=portworx
7-
fi
8-
n=$(kubectl exec -n $namespace -it $(kubectl get pods -n $namespace -lname=portworx --field-selector=status.phase=Running | tail -1 | cut -f 1 -d " ") -- /opt/pwx/bin/pxctl status 2>/dev/null | grep "Yes.*Online.*Up" | wc -l)
3+
n=$(kubectl exec -n portworx -it $(kubectl get pods -n portworx -lname=portworx --field-selector=status.phase=Running | tail -1 | cut -f 1 -d " ") -- /opt/pwx/bin/pxctl status 2>/dev/null | grep "Yes.*Online.*Up" | wc -l)
94
[ $n -eq $nodes ] && break
105
sleep 1
116
done
12-
kubectl rollout status deployment stork -n $namespace
7+
kubectl rollout status deployment stork -n portworx

0 commit comments

Comments
 (0)