-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·71 lines (59 loc) · 2.36 KB
/
test.sh
File metadata and controls
executable file
·71 lines (59 loc) · 2.36 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
#!/bin/bash
NAMESPACE="j1"
# Add the jupiterone helm chart
echo "helm repo add jupiterone https://jupiterone.github.io/helm-charts"
helm repo add jupiterone https://jupiterone.github.io/helm-charts
# Install/upgrade the jupiterone integration
echo "helm upgrade --install j1-integration ./charts/graph-kubernetes -f values.yaml -n $NAMESPACE --create-namespace"
helm upgrade --install j1-integration ./charts/graph-kubernetes -f values.yaml -n $NAMESPACE --create-namespace
# See the resources created by the helm chart installation
echo "kubectl get all -n $NAMESPACE"
kubectl get all -n $NAMESPACE
# Manually invoke the cron job
# Get the cron job name from the j1 namespace and assign the name to CRONJOB_NAME
echo "kubectl get cronjob -n $NAMESPACE"
CRONJOB_NAME=$(kubectl get cronjob -n $NAMESPACE -o jsonpath='{.items[0].metadata.name}')
# Create a job from the cron job
JOB_NAME=${CRONJOB_NAME}-$(date +%s)
echo "kubectl create job --from=cronjob/$CRONJOB_NAME $JOB_NAME -n $NAMESPACE"
kubectl create job --from=cronjob/$CRONJOB_NAME $JOB_NAME -n $NAMESPACE
# Wait for the job to start (timeout after 60 seconds)
echo "Waiting for job to start..."
for i in {1..60}; do
if kubectl get job $JOB_NAME -n $NAMESPACE -o jsonpath='{.status.active}' | grep -q "1"; then
echo "Job started successfully"
break
fi
if [ $i -eq 60 ]; then
echo "Timeout waiting for job to start"
exit 1
fi
sleep 1
done
# Wait for the pod to be running (timeout after 60 seconds)
echo "Waiting for pod to be running..."
POD_NAME=$(kubectl get pods -n $NAMESPACE -l "job-name=$JOB_NAME" -o jsonpath='{.items[0].metadata.name}')
for i in {1..60}; do
if kubectl get pod $POD_NAME -n $NAMESPACE -o jsonpath='{.status.phase}' | grep -q "Running"; then
echo "Pod is running"
break
fi
if [ $i -eq 60 ]; then
echo "Timeout waiting for pod to be running"
exit 1
fi
sleep 1
done
# Check the status of the job
echo "Checking job status..."
echo "kubectl get job $JOB_NAME -n $NAMESPACE"
kubectl get job $JOB_NAME -n $NAMESPACE
# Wait 60 seconds before checking logs
echo "Waiting 60 seconds before checking logs..."
sleep 60
# Check the logs of the job
echo "kubectl logs job/$JOB_NAME -n $NAMESPACE"
kubectl logs job/$JOB_NAME -n $NAMESPACE
# Check the status of the pod
echo "kubectl get pod -n $NAMESPACE"
kubectl get pod -n $NAMESPACE