-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
7a0ef96
commit 3aec531
Showing
2 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
if [ "$#" -ne 2 ]; then | ||
echo "Usage: $0 <namespace> <deployment>" | ||
exit 1 | ||
fi | ||
|
||
NAMESPACE=$1 | ||
DEPLOYMENT=$2 | ||
|
||
get_pv_details() { | ||
local pvc_name=$1 | ||
local pv_name | ||
pv_name=$(kubectl get pvc -n "$NAMESPACE" "$pvc_name" -o jsonpath='{.spec.volumeName}' 2>/dev/null) | ||
if [ -n "$pv_name" ]; then | ||
kubectl get pv "$pv_name" -o json 2>/dev/null | jq '{ | ||
pvName: .metadata.name, | ||
pvSize: .spec.capacity.storage, | ||
storageClass: .spec.storageClassName, | ||
pvAccessModes: .spec.accessModes | ||
}' | ||
else | ||
echo "{}" | ||
fi | ||
} | ||
|
||
if ! DEPLOYMENT_INFO=$(kubectl get deployment -n "$NAMESPACE" "$DEPLOYMENT" -o json 2>&1); then | ||
echo "Error: Failed to get deployment information" | ||
echo "$DEPLOYMENT_INFO" | ||
exit 1 | ||
fi | ||
|
||
echo "$DEPLOYMENT_INFO" | jq --arg namespace "$NAMESPACE" ' | ||
.spec.template.spec.containers[].volumeMounts[] as $vm | | ||
.spec.template.spec.volumes[] | | ||
select(.name == $vm.name) | | ||
select($vm.mountPath | endswith("local.d") | not) | | ||
{ | ||
mountPath: $vm.mountPath, | ||
name: $vm.name, | ||
subPath: $vm.subPath, | ||
volumeType: ( | ||
if .persistentVolumeClaim then "PVC" | ||
elif .hostPath then "HostPath" | ||
else "Other" | ||
end | ||
), | ||
claimName: ( | ||
if .persistentVolumeClaim then .persistentVolumeClaim.claimName | ||
else null | ||
end | ||
), | ||
hostPath: ( | ||
if .hostPath then .hostPath.path | ||
else null | ||
end | ||
) | ||
}' | jq -c '.' | while read -r volume_info; do | ||
claim_name=$(echo "$volume_info" | jq -r '.claimName // empty') | ||
if [ -n "$claim_name" ]; then | ||
pv_info=$(get_pv_details "$claim_name") | ||
echo "$volume_info" | jq --argjson pv_info "$pv_info" '. + $pv_info' | ||
else | ||
echo "$volume_info" | ||
fi | ||
done || { | ||
echo "Error: Failed to process deployment information" | ||
exit 1 | ||
} |