Skip to content

Instantly share code, notes, and snippets.

@fl64
fl64 / dvp.sh
Last active January 24, 2024 08:03
virtctl vnc | serial replacement
#!/bin/bash
trap 'other_commands' EXIT
other_commands() {
echo "Closing..."
jobs -p | xargs kill 2>/dev/null
}
random_port() {
echo $((10000 + $RANDOM % 20000))
@fl64
fl64 / check.sh
Created December 11, 2023 10:08
broken images check
#!/usr/bin/env bash
rst='\033[0m' # Text Reset
red='\033[0;31m' # Red
module_image_path="dev-registry.deckhouse.io/sys/deckhouse-oss/modules/virtualization"
virtualization_image_digest=$(kubectl get mpo virtualization -o json | jq .status.imageDigest -r)
module_images=$(crane export ${module_image_path}@${virtualization_image_digest} | tar -Oxf - images_digests.json | jq '. | to_entries | .[]' -c)
@fl64
fl64 / filter.py
Last active December 5, 2023 07:00
CRD filter
#!/usr/bin/env python3
import argparse
import yaml
keepIt = ["description"]
def custom_represent(dumper, data):
if len(data) > 30: # Set a condition for when to use the |
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
@fl64
fl64 / getvms.sh
Created November 22, 2023 20:50
get vms and it's linstor nodes
ns=tfprod
vms=$(kubectl -n ${ns} get pods -l vm.kubevirt.io/name -o json | jq '.items[] | select(.status.phase=="Running") | { ns: .metadata.namespace, name: .metadata.name, node: .spec.nodeName, claims: [.spec.volumes[] | select(.persistentVolumeClaim!=null) | .persistentVolumeClaim.claimName] }' -cr)
for vm in ${vms}; do
echo ${vm} | jq '. | {ns,name,node}' -c
pvcs=$(echo ${vm} | jq .claims[] -r)
for pvc in ${pvcs}; do
volume_name=$(kubectl -n ${ns} get pvc ${pvc} -o json | jq .spec.volumeName -r)
echo "${pvc} / ${volume_name}"
kubectl exec -n d8-linstor deploy/linstor-controller -- linstor r l -r ${volume_name}
@fl64
fl64 / Makefile
Last active November 20, 2023 12:29
convert images for testcases
TMP_DIR=./tmp
IMAGE_NAME=cirros-0.5.1
IMAGE_PATH=${TMP_DIR}/${IMAGE_NAME}
# https://docs.openstack.org/image-guide/obtain-images.html
bold := $(shell tput bold)
red := $(shell tput setaf 1)
green := $(shell tput setaf 2)
@fl64
fl64 / clenup.go
Created November 17, 2023 07:19
deckhouse hooks
package hooks
import (
"github.com/flant/addon-operator/pkg/module_manager/go_hook"
"github.com/flant/addon-operator/sdk"
"github.com/flant/shell-operator/pkg/kube/object_patch"
)
var _ = sdk.RegisterFunc(&go_hook.HookConfig{
OnAfterDeleteHelm: &go_hook.OrderedConfig{Order: 10},
@fl64
fl64 / watchdog-timer.go
Last active November 2, 2023 07:10
watchdog timer
package main
import (
"fmt"
"time"
)
func watchdog(resetTimer <-chan bool, timeout time.Duration) {
t5 := time.NewTicker(time.Second * 5)
ticker := time.NewTicker(time.Second)
@fl64
fl64 / check.sh
Last active May 3, 2024 17:06
cleanup deckhouse virtualization
#!/usr/bin/env bash
resources=$(kubectl api-resources --output name)
orange=$(tput setaf 3)
sgr0=$(tput sgr0)
for res in $resources; do
echo "$orange $res $sgr0"
kubectl get -A $res -o json 2> /dev/null | jq '.items[].metadata | {name, namespace}' -c | grep -v "No resources found" | grep -E '(kubevirt|cdi).*'
@fl64
fl64 / service.sh
Created October 16, 2023 17:14
systemd-watchdog service
#!/bin/bash
trap 'kill $(jobs -p)' EXIT
/opt/test/service.sh &
PID=$!
/bin/systemd-notify --ready
while(true); do