Skip to content

Instantly share code, notes, and snippets.

View ImIOImI's full-sized avatar

Troy Knapp ImIOImI

  • SumerSports
  • OKC
View GitHub Profile
@ImIOImI
ImIOImI / login-workload-identity.sh
Created March 15, 2024 20:15
Test Azure workload identity in a container
# Reference https://blog.baeke.info/2022/05/18/quick-guide-to-kubernetes-workload-identity-on-aks/
echo $AZURE_CLIENT_ID
echo $AZURE_TENANT_ID
echo $AZURE_FEDERATED_TOKEN_FILE
cat $AZURE_FEDERATED_TOKEN_FILE
echo $AZURE_AUTHORITY_HOST
# list the standard Kubernetes service account secrets
cd /var/run/secrets/kubernetes.io/serviceaccount
ls
@ImIOImI
ImIOImI / login-all-clusters.sh
Created February 29, 2024 13:46
Login to all clusters that you have access to in an Azure tenant
#!/usr/bin/env bash
# get the environment to deploy to
read -p "Should we login as admin? (y/n) [y]: " ADMIN
ADMIN=${ADMIN:-y}
if [ "$ADMIN" == "y" ]; then
ADMIN_STRING="--admin"
else
ADMIN_STRING=""
@ImIOImI
ImIOImI / gist:94a1d6cecc9145a41d8478c867095d0b
Created January 13, 2024 23:00
Create a product of two maps
# I find myself having to get the product of two maps fairly regularly, this is one way to do it
locals {
pre_merge = [
for map1_key, map1_object in local.map1 : {
for map2_key, map2_value in local.map2 : "${map1_key}-${map2_key}" => {
map2_value_name = map2_value
object_name = object.name
object_id = object.id
}
}
@ImIOImI
ImIOImI / find-string-in-manifest.py
Last active December 1, 2023 21:39
Search All K8s Manifests for A String
#!/usr/bin/env python3
import subprocess
import argparse
import os
def get_resource_types():
cmd = ["kubectl", "api-resources", "-o", "name"]
output = subprocess.check_output(cmd, text=True)
resource_types = output.strip().split('\n')
@ImIOImI
ImIOImI / convert-tf-errors.py
Created November 11, 2023 02:17
Ingest Terraform apply output and extract all the resources that need to be imported and write terraform import statements.
# Read terraform-errors.txt and filter errors to generate terraform-import.sh
input_file = 'terraform-errors.txt'
output_file = 'terraform-import.sh'
try:
# Open the input file in read mode
with open(input_file, 'r') as f_in:
# Read lines from the input file
lines = f_in.readlines()
@ImIOImI
ImIOImI / updateHPAManifest.sh
Created May 24, 2023 13:45
Migrate HPAs in a helm chart from autoscaling/v2beta1 or autoscaling/v2beta2 to autoscaling/v2
#!/bin/bash
# This script will migrate a broken release that has an HPA with a autoscaler that uses the beta1 or beta2 api to
# autoscaling v2. This script is necessary to run if you have upgraded your cluster to 1.26 or higher and you can't use
# mapkubeapis to fix the issue.
COLUMNS=1
# Prompt the user to select one of their namespaces.
echo -e "\e[33mPlease select a namespace:\e[0m"
readarray -t NAMESPACES < <(kubectl get namespaces -o json | jq -r '.items[].metadata.name')
select NAMESPACE in "${NAMESPACES[@]}"; do
@ImIOImI
ImIOImI / pushit.yaml
Created February 3, 2023 02:36
On Merge Tag and Build and Push Image to ACR
name: Build a Docker image and Push it to ACR
on:
push:
branches: [ main ]
schedule:
- cron: 0 11 * * 1
workflow_dispatch:
jobs:
docker:
runs-on: ubuntu-latest
@ImIOImI
ImIOImI / README.md
Last active March 5, 2023 08:31
Env0 Project Module

Tagging

Env0 relies on git tags to version modules. By default the tag workflow automagically increments the release patch version (so applying a tag to a PR is unecessary). Acceptable tags are

Requirements

@ImIOImI
ImIOImI / storage-endpoint.tf
Created December 8, 2021 15:45
Azure Storage Account With Private Endpoint
terraform {
required_providers {
}
required_version = "~> 1.0.5"
}
provider "azurerm" {
subscription_id = var.us-dev-subscription-id
alias = "us"
@ImIOImI
ImIOImI / cloudshell-init.sh
Last active May 9, 2024 15:46
AWS Cloudshell init script
#!/bin/sh
defaultUser="ImIOImI"
defaultEmail="troy.knapp@gmail.com"
rsaKeyFile=/home/cloudshell-user/.ssh/id_rsa
if [ ! -f "$rsaKeyFile" ]; then
#add rsa key
ssh-keygen -b 2048 -t rsa -f "$rsaKeyFile" -q -N ""
echo "Please copy the following into your GitHub profile here: https://github.com/settings/ssh/new
"