Skip to content

Instantly share code, notes, and snippets.

View achetronic's full-sized avatar
💭
From bad practises always to the best ones

Alby Hernández achetronic

💭
From bad practises always to the best ones
View GitHub Profile
@achetronic
achetronic / delete-secret-ownerreferences-all-namespaces.sh
Last active December 15, 2023 11:30
Delete ownerReferences from all the Secret resources across namespaces in Kubernetes
#!/bin/bash
# Obtener la lista de nombres de todos los namespaces
NAMESPACE_LIST=($(kubectl get namespaces --output=jsonpath='{.items[*].metadata.name}'))
# Bucle externo para recorrer todos los namespaces
for NAMESPACE in "${NAMESPACE_LIST[@]}"
do
echo "NAMESPACE: ${NAMESPACE}"
@achetronic
achetronic / update-namespaces-label-temporarily.sh
Created November 29, 2023 12:22
Add and delete a label on all namespaces to trigger update event
#!/bin/bash
NAMESPACES=$( kubectl get namespaces --no-headers -o custom-columns=":metadata.name")
for namespace in $NAMESPACES; do
kubectl label Namespace "${namespace}" app.kubernetes.io/menganito=fue-a-por-pan
kubectl label Namespace "${namespace}" app.kubernetes.io/menganito-
done
@achetronic
achetronic / debug-pod.yaml
Last active March 14, 2024 15:56
Simple pod to debug
apiVersion: v1
kind: Pod
metadata:
name: ubuntu
labels:
app: ubuntu
sidecar.istio.io/inject: "false"
#istio-injection: disabled
spec:
containers:
@achetronic
achetronic / adopt-helm-resources.sh
Last active October 24, 2023 09:41
Put Helm annotations and labels on already deployed Kubernetes resources to adopt them inside a Helm Release automatically
#!/bin/bash
LOCAL_EXIT_CODE=0
RELEASE_NAME="istiod"
RELEASE_NAMESPACE="istio-system"
HELM_CHART_PATH="./istio/istiod"
HELM_EXTRA_VALUES_PATH="./istio/common/istio.yaml"
@achetronic
achetronic / get-gcloud-gke-contexts.sh
Last active October 5, 2023 12:46
Get all the GKE contexts available for you authenticted account
#!/bin/bash
LOCAL_EXIT_CODE=0
# Get a list of projects from Gcloud
PROJECTS=($(gcloud projects list --format="value(projectId)"))
# Create a directory to split clusters kubeconfig files later
mkdir -p "${HOME}/.kube/clusters"
@achetronic
achetronic / update-s3-objects-acls-huge-buckets.sh
Created October 14, 2022 13:23
Update ACLs, object by object, for buckets with millions of objects inside
#!/usr/bin/env bash
## VARIABLES
BUCKET_NAME="YOUR-BUCKET-TO-PROCESS"
BUCKET_PREFIX="THE-PREFIX-TO-START-PROCESSING/"
NEXT_FILE_TO_PROCESS=""
BASE_LIST_COMMAND="aws s3api list-objects-v2 --bucket ${BUCKET_NAME} --prefix ${BUCKET_PREFIX} --output text --query 'Contents[].Key' --max-items 100 --page-size 100"
@achetronic
achetronic / add-ssh-key-to-all-ec2-machines.sh
Created July 2, 2022 19:23
Add an SSH key to all EC2 machines on AWS
#!/usr/bin/env bash
AWS_ENVIRONMENT="production"
SSH_PUBLIC_KEY="ssh-ed25519 XXXYYYZZZexampleXXXYYYZZZ/XYZXYZ your.email@your.company.com"
# Copy the key to a temporary location
touch /tmp/id_ed25519.pub
echo "${SSH_PUBLIC_KEY}" > /tmp/id_ed25519.pub
# See all machines in all regions
@achetronic
achetronic / get-docker-image-tag-by-sha.sh
Created July 2, 2022 19:19
Find the tag of a Docker image having only the SHA256
#!/bin/bash
SHA256_HASH="5bb4faffc8b35e2702b2ffa78e982b979d7b66db29bd55b0c58de8fa745df661"
for i in {1..1000}
do
echo "Looking into page: $i"
curl "https://registry.hub.docker.com/v2/repositories/apache/superset/tags/?page=$i" \
| jq '.results[] | select(.["images"][]["digest"] == "sha256:'${SHA256_HASH}'")'