Skip to content

Commit 4e1747b

Browse files
Updated sa argocd permission and sentinel fixed bash script
1 parent d4950ba commit 4e1747b

File tree

3 files changed

+83
-16
lines changed

3 files changed

+83
-16
lines changed

charts/osmosis-fullnode/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: osmosis-fullnode
33
description: A Helm chart for deploying Osmosis fullnode with monitoring and sentinel
44
type: application
5-
version: 0.1.4
5+
version: 0.1.5
66
appVersion: "29.0.2"
77
keywords:
88
- osmosis

charts/osmosis-fullnode/templates/cronjob.yaml

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,31 @@ spec:
242242
NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
243243
echo "🔍 Namespace: $NAMESPACE"
244244
245-
# Extract both type and number from hostname
246-
POD_TYPE=$(hostname | sed 's/{{ include "osmosis-fullnode.fullname" . }}-sentinel-\(node\|seed\)-.*$/\1/')
247-
NODE_NUMBER=$(hostname | sed 's/{{ include "osmosis-fullnode.fullname" . }}-sentinel-\(node\|seed\)-\([0-9]*\).*$/\2/')
248-
echo "🔍 Hostname: $(hostname)"
245+
# Get current hostname
246+
CURRENT_HOSTNAME=$(hostname)
247+
echo "🔍 Hostname: $CURRENT_HOSTNAME"
248+
249+
# Extract pod type and number from hostname
250+
# Expected format: {fullname}-{type}-{number}-sentinel-{cronJobId}-{podId}
251+
# Example: fullnodes-stage-osmosis-fullnode-node-0-sentinel-29224300-mktf4
252+
FULLNAME="{{ include "osmosis-fullnode.fullname" . }}"
253+
254+
# Extract type (node or seed) - look for pattern after fullname
255+
if echo "$CURRENT_HOSTNAME" | grep -q "${FULLNAME}-node-"; then
256+
POD_TYPE="node"
257+
# Extract node number
258+
NODE_NUMBER=$(echo "$CURRENT_HOSTNAME" | sed "s/^${FULLNAME}-node-\([0-9]*\)-sentinel-.*$/\1/")
259+
elif echo "$CURRENT_HOSTNAME" | grep -q "${FULLNAME}-seed-"; then
260+
POD_TYPE="seed"
261+
# Extract seed number
262+
NODE_NUMBER=$(echo "$CURRENT_HOSTNAME" | sed "s/^${FULLNAME}-seed-\([0-9]*\)-sentinel-.*$/\1/")
263+
else
264+
POD_TYPE="unknown"
265+
NODE_NUMBER="unknown"
266+
fi
267+
249268
echo "🔍 Pod Type: $POD_TYPE"
250-
echo "🔍 Extracted Node Number: $NODE_NUMBER"
269+
echo "🔍 Node Number: $NODE_NUMBER"
251270
252271
OSMOSIS_APP="{{ include "osmosis-fullnode.fullname" . }}"
253272
OSMOSIS_POD="{{ include "osmosis-fullnode.fullname" . }}-0"
@@ -269,25 +288,38 @@ spec:
269288
exit 1
270289
fi
271290
272-
# Check for CrashLoopBackOff status
273-
POD_STATUS=$(kubectl get pod $OSMOSIS_POD -n $NAMESPACE -o jsonpath='{.status.containerStatuses[0].state.waiting.reason}' 2>/dev/null || echo "Running")
274-
RESTART_COUNT=$(kubectl get pod $OSMOSIS_POD -n $NAMESPACE -o jsonpath='{.status.containerStatuses[0].restartCount}')
291+
# Check for CrashLoopBackOff status - handle case where pod is running
292+
POD_STATUS=$(kubectl get pod $OSMOSIS_POD -n $NAMESPACE -o jsonpath='{.status.containerStatuses[0].state.waiting.reason}' 2>/dev/null)
293+
if [ -z "$POD_STATUS" ]; then
294+
# Pod is not in waiting state, check if it's running
295+
POD_PHASE=$(kubectl get pod $OSMOSIS_POD -n $NAMESPACE -o jsonpath='{.status.phase}' 2>/dev/null)
296+
POD_STATUS="${POD_PHASE:-Unknown}"
297+
fi
298+
299+
RESTART_COUNT=$(kubectl get pod $OSMOSIS_POD -n $NAMESPACE -o jsonpath='{.status.containerStatuses[0].restartCount}' 2>/dev/null || echo "0")
275300
276301
# Check directory size
277302
TOTAL_SIZE=$(kubectl exec $(hostname) -n $NAMESPACE -- du -sb $MONITOR_PATH 2>/dev/null | awk '{print $1}' || echo 0)
278303
SIZE_THRESHOLD=$(echo "${MAX_DIR_SIZE_GB:-100} * 1024 * 1024 * 1024" | bc) # Convert GB to bytes
279304
280-
echo "📊 Total size: $(echo "$TOTAL_SIZE / 1024 / 1024" | bc)MB"
281-
echo "📊 Threshold: $(echo "$SIZE_THRESHOLD / 1024 / 1024" | bc)MB"
305+
# Convert sizes to MB for display
306+
TOTAL_SIZE_MB=$(echo "scale=0; $TOTAL_SIZE / 1024 / 1024" | bc)
307+
THRESHOLD_MB=$(echo "scale=0; $SIZE_THRESHOLD / 1024 / 1024" | bc)
308+
309+
echo "📊 Total size: ${TOTAL_SIZE_MB}MB"
310+
echo "📊 Threshold: ${THRESHOLD_MB}MB"
282311
echo "📊 Pod Status: $POD_STATUS"
283312
echo "📊 Restart Count: $RESTART_COUNT"
284313
285-
# Check if cleanup is needed
286-
if [ "$POD_STATUS" = "CrashLoopBackOff" ] || [ "${RESTART_COUNT:-0}" -gt "${MAX_NODE_RESTART_COUNT}" ]; then
287-
echo "⚠️ Pod $OSMOSIS_POD is in CrashLoopBackOff state or has too many restarts"
314+
# Check if cleanup is needed - properly quote variables and handle empty values
315+
MAX_RESTART_COUNT="${MAX_NODE_RESTART_COUNT:-10}"
316+
CURRENT_RESTART_COUNT="${RESTART_COUNT:-0}"
317+
318+
if [ "$POD_STATUS" = "CrashLoopBackOff" ] || [ "$CURRENT_RESTART_COUNT" -gt "$MAX_RESTART_COUNT" ]; then
319+
echo "⚠️ Pod $OSMOSIS_POD is in CrashLoopBackOff state or has too many restarts ($CURRENT_RESTART_COUNT > $MAX_RESTART_COUNT)"
288320
handle_cleanup $NAMESPACE $OSMOSIS_APP $OSMOSIS_POD
289321
elif [ $(echo "$TOTAL_SIZE > $SIZE_THRESHOLD" | bc -l) -eq 1 ]; then
290-
echo "⚠️ Directory size ($(echo "$TOTAL_SIZE / 1024 / 1024" | bc)MB) exceeds threshold ($(echo "$SIZE_THRESHOLD / 1024 / 1024" | bc)MB)"
322+
echo "⚠️ Directory size (${TOTAL_SIZE_MB}MB) exceeds threshold (${THRESHOLD_MB}MB)"
291323
handle_cleanup $NAMESPACE $OSMOSIS_APP $OSMOSIS_POD
292324
else
293325
echo "✅ Pod $OSMOSIS_POD is running normally and directory size is within limits"

charts/osmosis-fullnode/templates/rbac.yaml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ roleRef:
4444
name: {{ include "osmosis-fullnode.fullname" . }}-pod-deleter
4545
apiGroup: rbac.authorization.k8s.io
4646

47+
{{- if and .Values.sentinel.enabled .Values.sentinel.config.argocdEnabled }}
4748
---
4849
apiVersion: rbac.authorization.k8s.io/v1
4950
kind: ClusterRole
@@ -55,6 +56,9 @@ rules:
5556
- apiGroups: ["argoproj.io"]
5657
resources: ["applications"]
5758
verbs: ["get", "list", "watch", "update", "patch"]
59+
- apiGroups: [""]
60+
resources: ["namespaces"]
61+
verbs: ["get", "list"]
5862

5963
---
6064
apiVersion: rbac.authorization.k8s.io/v1
@@ -70,4 +74,35 @@ subjects:
7074
roleRef:
7175
kind: ClusterRole
7276
name: {{ include "osmosis-fullnode.fullname" . }}-argocd-application-manager
73-
apiGroup: rbac.authorization.k8s.io
77+
apiGroup: rbac.authorization.k8s.io
78+
79+
---
80+
apiVersion: rbac.authorization.k8s.io/v1
81+
kind: Role
82+
metadata:
83+
name: {{ include "osmosis-fullnode.fullname" . }}-argocd-namespace-access
84+
namespace: argocd
85+
labels:
86+
{{- include "osmosis-fullnode.labels" . | nindent 4 }}
87+
rules:
88+
- apiGroups: ["argoproj.io"]
89+
resources: ["applications"]
90+
verbs: ["get", "list", "watch", "update", "patch"]
91+
92+
---
93+
apiVersion: rbac.authorization.k8s.io/v1
94+
kind: RoleBinding
95+
metadata:
96+
name: {{ include "osmosis-fullnode.fullname" . }}-argocd-namespace-access
97+
namespace: argocd
98+
labels:
99+
{{- include "osmosis-fullnode.labels" . | nindent 4 }}
100+
subjects:
101+
- kind: ServiceAccount
102+
name: {{ include "osmosis-fullnode.serviceAccountName" . }}
103+
namespace: {{ .Values.namespace }}
104+
roleRef:
105+
kind: Role
106+
name: {{ include "osmosis-fullnode.fullname" . }}-argocd-namespace-access
107+
apiGroup: rbac.authorization.k8s.io
108+
{{- end }}

0 commit comments

Comments
 (0)