Skip to content

Instantly share code, notes, and snippets.

View hermanbanken's full-sized avatar
🇳🇱

Herman hermanbanken

🇳🇱
View GitHub Profile
@hermanbanken
hermanbanken / auth.go
Created January 18, 2022 23:59
Triple JWT audience/issuer server
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"github.com/golang-jwt/jwt/v4"
@hermanbanken
hermanbanken / NativeHttpServer.java
Created December 17, 2021 10:17
java server serving 404 without dependencies
package main;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Map;
@hermanbanken
hermanbanken / README.md
Last active December 12, 2021 14:15
Cloud Function for GKE upgrade notifications

We want to receive notifications when a Kubernetes cluster upgrades. For this we can configure PubSub subscriptions:

const exec = require("child_process").execSync;

const mapping = {
  "my-dev-project": [{ name: "clusterA", region: "europe-west4" }, { name: "clusterB", region: "us-east1" }],
  "my-prod-project": [{ name: "clusterC", region: "europe-west4" }, { name: "clusterD", region: "us-east1" }],
};
@hermanbanken
hermanbanken / gitlab_list_variables.js
Created September 9, 2021 13:09
GitLab list pipeline variables
#!/bin/env node
const PRIVATE_TOKEN = "redacted";
const headers = { "PRIVATE-TOKEN": PRIVATE_TOKEN };
const root = "https://gitlab.com/api/v4";
const project = 24418136; // "hue-contract-tests";
const { default: fetch } = require("node-fetch");
fetch(`${root}/projects/${project}/pipelines`, { headers }).then((res) => res.json())
.then(async (pipelines) => {
@hermanbanken
hermanbanken / blog.md
Created September 6, 2021 15:08
Raft cluster completely blocked

Raft issue

When developing my first hashicorp/raft implementation I was stuck at a stone wall it seemed. Somehow I could bootstrap one of the nodes and this would win the election and the raft observation for it becoming Leader also made it in, but then nothing. I couldn't figure out why all RPCs timed out after that.

I started to run locally and debugged using VS Code Launch configuration (which uses Delve) and found that before bootstrapping there was a "runCandidate" goroutine, but after bootstrapping there was no "runLeader" goroutine. Turns out the leader loop never started! How could this be? Then my mind wandered to the observer that I added:

	ch := make(chan raft.Observation, 1)
	r.RegisterObserver(raft.NewObserver(ch, true, func(o *raft.Observation) bool {
		// *RequestVoteRequest
@hermanbanken
hermanbanken / _README.md
Last active August 23, 2021 09:28
LimitedSampler

Limited Sampler

flow chart

@hermanbanken
hermanbanken / .gitmodules
Last active June 6, 2021 10:45
Protobuf ramblings
[submodule "proto/googleapis"]
path = proto/vendor/googleapis
url = https://github.com/googleapis/googleapis.git
@hermanbanken
hermanbanken / _README.md
Last active January 9, 2023 23:00
Datastore Emulator consistency

TLDR: The datastore emulator has a consistency setting. When developing, always set this to a value to 0.05 or lower to simulate realistic eventual consistency.

The Google Datastore is only partly consistent: only lookups and ancestor queries are strongly consistent. All types of queries use the indexes, which take a while to process in a distributed system like Google Datastore. When you develop an application that uses the Datastore, it helps to use the emulator in a way that simulates this eventual consistency. This way to can test if your

@hermanbanken
hermanbanken / README.md
Last active January 13, 2021 16:21
Go net dial DNSError has the wrong server name #golang

Go net dial DNSError has the wrong server name

Suppose you write this piece of Go code to do a DNS resolve using 1.1.1.1:

var resolver = &net.Resolver{
	PreferGo: true,
	Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
		d := net.Dialer{
			Timeout: time.Millisecond * time.Duration(5000),
		}
@hermanbanken
hermanbanken / kustomize_vars.md
Created November 22, 2020 13:11
Kustomize Vars example

This was initially posted in an kubernetes-sigs/kustomize issue.

We are using Kustomize's vars feature. Initially we didn't understand how to use it for our purpose, but it is a 100% fit. One example is our Ingress resource, which looks like this:

# file: base/ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: services