Skip to content

Instantly share code, notes, and snippets.

@corkupine
corkupine / ete_cloudflare.sh
Last active March 7, 2024 21:08
Updating ETE tenant config with Cloudflare DNS record IDs
#Get cloudflare dns record IDs for cnames in zescrow.com - redirect to a file
API_KEY="xxxxxxxxxxxxxxxxxx"
ZONE_ID="xxxxxxxxxxxxxxxxxx"
API_URL="https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records?type=CNAME"
#Change page as necessary
curl -s -X GET "${API_URL}&page=4" \
-H "Authorization: Bearer ${API_KEY}" \
-H "Content-Type: application/json"
# This doesn't work well with paging in CLI v2 - do this too:
# export AWS_PAGER=""
BUCKET_NAME=argocdexport
OBJECT_KEY=export.yaml
versions=$(aws s3api list-object-versions --bucket $BUCKET_NAME --prefix $OBJECT_KEY | jq -r '.Versions[].VersionId')
count=`echo $versions |jq 'length'`-1
echo "Retrieved $count versions"
@corkupine
corkupine / getPodsAndZones.sh
Created August 29, 2023 20:52
Get pods, nodes and zones
#!/bin/bash
kubectl get pods --all-namespaces -o custom-columns=":metadata.namespace,:metadata.name,:spec.nodeName" --no-headers=true | while read -r namespace pod_name node_name
do
zone=$(kubectl get node "$node_name" -o jsonpath="{.metadata.labels.topology\.kubernetes\.io/zone}")
echo "Namespace: $namespace, Pod Name: $pod_name, Node Name: $node_name, Zone: $zone"
done
@corkupine
corkupine / replicateBranch.sh
Created August 4, 2023 14:19
Duplicate all code on another branch with a commit with the diff
#Start out on the branch with the code we want
git checkout branch_a
#create tmp branch same as branch_a (so that we don't change our local branch_a state during the operation)
#working directory has all the code that we want, on tmp branch
git checkout -b tmp
# Change the branch head to the branch we want to be on. All the delta
# between the current source code and branch_b is now staged for commit
git reset --soft branch_b
# Based on: https://developer.hashicorp.com/terraform/tutorials/automation/github-actions
name: Terraform plan on PR and apply on merge
on:
pull_request:
types: [opened, closed, synchronize, reopened]
paths:
- "environment/**"
jobs:
terraform_plan:
@corkupine
corkupine / restartall.ps1
Created February 9, 2023 18:09
Powershell script to restart all deployments and statefulsets in all k8s namespaces
param($kubecontext)
if ($kubecontext -ne $null){
kubectl config use-context $kubecontext
}
else {
$kubecontext = kubectl config current-context
}
$response = Read-Host "Are you sure you want to restart all pods in $kubecontext ? Type YES to continue"
Port-forward a k8s service
k port-forward svc/argo-cd-argocd-server 12345:443 -n argocd
Get shell on a pod
k -n [namespace] exec -i -t [argocd server pod name] -- /bin/bash
add --container param for specific container
List all non-running pods
k get pods --field-selector status.phase!=Running -A
@corkupine
corkupine / tf-import-stack.sh
Created October 31, 2022 18:39 — forked from jmlrt/tf-import-stack.sh
import terraform stack resources helper
#!/usr/bin/env bash
# List terraform resources in the current directory and ask their arn to import them into terraform state
RESOURCES_LIST=$(awk -F\" '/^resource "/ {print $2"."$4}' *.tf)
for resource in ${RESOURCES_LIST}
do
read -p "Enter ARN for resource ${resource} (type none to not import it): " arn
if [[ ${arn} != "none" ]]
"devDependencies": {
"bower": "~0.6.4",
"underscore" : "~1.4.4",
"grunt" : "0.4.0rc4",
"grunt-cli" : "~0.1.5",
"grunt-contrib-clean" : "~0.4.0a",
"grunt-contrib-coffee" : "git+https://github.com/gruntjs/grunt-contrib-coffee.git#01f90adb16e315ee88c0befa5bb401bbfd4cbc6e",
"grunt-contrib-concat" : "~0.1.1",
"grunt-contrib-connect" : "0.1.0",
"grunt-contrib-copy" : "git+https://github.com/gruntjs/grunt-contrib-copy.git#2bd6f0e99e6be6f4bc48f50e5cb32ff8aa3f8ffc",
@corkupine
corkupine / apseduo.cs
Created October 16, 2012 18:47
AuditingPersistence pseudocode
public ObjRepository : IObjRepository
{
public Obj Add(Obj newObj)
{
Audited<Obj> newAuditedObj = new AuditPersist.Audited<Obj>(Obj newObj);
Audited<Obj> persistedAuditedObj = CI.Add<Audited<Obj>>("objbucket", newAuditedObj);
return newAuditedObj.CurrentState();
}
private Audited<Obj> GetAudited(Guid objId)