INT 21h

Hi, I am Vladimir Smagin, SysAdmin, DevOps and barely good guy. Telegram Email / GIT / Микроблог / Thingiverse / RSS / GPG

Простой способ подготовки библиотеки на golang к тестированию

№ 11006 В разделе "Programming" от May 26th, 2020,

Чтобы без проблем тестировать программы, написанные с использованием вашей библиотеки ее необходимо подготовить для этого. Делаем интерфейс, который будет использоваться в тестах, где ваши реальные функции будут заменены функциями с тестовыми данными.

package main

import "fmt"

// library 

type FooAdapter interface {
	Read() string

type Foo struct {
	mvar    string

func NewFoo(v string) FooAdapter {
	return &Foo{mvar:v}

func (a *Foo) Read() string {
	return "orig: " + a.mvar

// test 

func NewFooStub(v string) FooAdapter {
	return &FooStub{mvar: v}

type FooStub struct {
	mvar string

func (s *FooStub) Read() string {
	return "stub: " + s.mvar

func main() {
	z := NewFoo("o")
	fmt.Println("Read", z.Read())
	m := NewFooStub("s")
	fmt.Println("Read", m.Read())

Нет комментариев »

Hetzner DNS golang library

№ 10996 В разделе "Programming" от May 6th, 2020,

I made this library to interact with Hetzner DNS API in most easy way. Hopefully in future it will be used for Hetzner external-dns provider. Check out example directory and

Get your own token on Hetzner DNS and place it to token variable and run code

token := "jcB2UywP9XtZGhvhSHpH5m"
zone := "vhSHpH5mjcB2UywP9XtZGh"

log.Println("Create new instance")
hdns := hclouddns.New(token)

log.Println("Get zone", zone)

allRecords, err := hdns.GetRecords(zone)
if err != nil {


Нет комментариев »

CronJobs operator for Kubernetes

№ 10306 В разделах: Programming Sysadmin от September 17th, 2019,
В подшивках: , , ,

Helps to control multiple cronjobs with same image, but different commands.

Checkout code and documentation

Нет комментариев »

Vault secret retrieve and save to JSON file

№ 10280 В разделах: Programming Sysadmin от September 1st, 2019,
В подшивках: , ,

I wrote small program to retrieve secrets from Vault and provide them to my PHP and Python apps. ENV variables with connection credentials is useful with Docker containers and even Kubernetes, list of secrets to retrieve can be stored inside Docker image.

Secret stored in Vault

Result file on disk

Source code and binary release

Нет комментариев »

Fast bootstrap of Operator SDK and your first project

№ 10268 В разделе "Programming" от August 30th, 2019,
В подшивках: ,

1) Install operator-sdk on your computer I prefer to install into $GOPATH/bin.
2) create script somewhere like /opt/

set -e


# operator sdk
export GO111MODULE=on
echo "Bootstraping ${NAME}"
operator-sdk new ${NAME} --git-init --repo ${REPO} --verbose
cd ${NAME}
echo "Adding API ${API_VERSION}"
operator-sdk add api --api-version=${API_VERSION} --kind=${KIND} --verbose
echo "Creating controller"
operator-sdk add controller --api-version=${API_VERSION} --kind=${KIND} --verbose

3) change directory to your “~/dev” and run script bash /opt/, it will create new directory “~/dev/redis-operator

4) build your new operator, pack to image operator-sdk build redis-operator

5) push new image to registry with docker push

Нет комментариев »


Fortune cookie: "Such things have often happened and still happen, and how can these be signs of the end of the world?" [Julian, Emperor of Rome 361-363 A.D.]