templates

package
v3.1.0-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var K8eKillallScript = template.Must(template.New("k8e-killall.sh").Parse(
	dedent.Dedent(`#!/bin/sh
[ $(id -u) -eq 0 ] || exec sudo $0 $@

for service in /etc/systemd/system/k8e*.service; do
    [ -s $service ] && systemctl stop $(basename $service)
done
pschildren() {
    ps -e -o ppid= -o pid= | \
    sed -e 's/^\s*//g; s/\s\s*/\t/g;' | \
    grep -w "^$1" | \
    cut -f2
}
pstree() {
    for pid in $@; do
        echo $pid
        for child in $(pschildren $pid); do
            pstree $child
        done
    done
}
killtree() {
    kill -9 $(
        { set +x; } 2>/dev/null;
        pstree $@;
        set -x;
    ) 2>/dev/null
}
getshims() {
    ps -e -o pid= -o args= | sed -e 's/^ *//; s/\s\s*/\t/;' | grep -w 'k8e/data/[^/]*/bin/containerd-shim' | cut -f1
}
killtree $({ set +x; } 2>/dev/null; getshims; set -x)
do_unmount_and_remove() {
    set +x
    while read -r _ path _; do
        case "$path" in $1*) echo "$path" ;; esac
    done < /proc/self/mounts | sort -r | xargs -r -t -n 1 sh -c 'umount "$0" && rm -rf "$0"'
    set -x
}
do_unmount_and_remove '/run/k8e'
do_unmount_and_remove '/var/lib/k8e'
do_unmount_and_remove '/var/lib/kubelet/pods'
do_unmount_and_remove '/var/lib/kubelet/plugins'
do_unmount_and_remove '/run/netns/cni-'
# Remove CNI namespaces
ip netns show 2>/dev/null | grep cni- | xargs -r -t -n 1 ip netns delete
rm -rf /var/lib/cni/
    `)))

K8eKillallScript defines the template of k3s-killall script.

View Source
var (
	// K8eService defines the template of kubelet service for systemd.
	K8eService = template.Must(template.New("k8e.service").Parse(
		dedent.Dedent(`[Unit]
Description=Simple Kubernetes Distribution
Documentation=https://getk8e.com
Wants=network-online.target
After=network-online.target

[Install]
WantedBy=multi-user.target

[Service]
Type=notify
EnvironmentFile=/etc/systemd/system/k8e.service.env
{{ if .IsMaster }}
Environment="K8E_ARGS= {{ range .CertSANs }} --tls-san={{ . }}{{- end }} {{ range .ApiserverArgs }} --kube-apiserver-arg={{ . }}{{- end }} {{ range .ControllerManager }} --kube-controller-manager-arg={{ . }}{{- end }} {{ range .SchedulerArgs }} --kube-scheduler-arg={{ . }}{{- end }} --cluster-cidr={{ .PodSubnet }} --service-cidr={{ .ServiceSubnet }} --cluster-dns={{ .ClusterDns }} "
{{ end }}
Environment="K8E_EXTRA_ARGS=--node-name={{ .HostName }}  --node-ip={{ .NodeIP }}  --pause-image={{ .PauseImage }} {{ range .KubeletArgs }} --kubelet-arg={{ . }}{{- end }} {{ range .KubeProxyArgs }} --kube-proxy-arg={{ . }}{{- end }}"
Environment="K8E_ROLE={{ if .IsMaster }}server{{ else }}agent{{ end }}"
Environment="K8E_SERVER_ARGS={{ if .Server }}--server={{ .Server }}{{ end }}"
KillMode=process
Delegate=yes
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Restart=always
RestartSec=5s
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k8e $K8E_ROLE $K8E_ARGS $K8E_EXTRA_ARGS $K8E_SERVER_ARGS
    `)))
)
View Source
var K8eServiceEnv = template.Must(template.New("k8e.service.env").Parse(
	dedent.Dedent(`# Note: This dropin only works with k3s
{{ if .IsMaster }}
K8E_DATASTORE_ENDPOINT={{ .DataStoreEndPoint }}
{{- if .DataStoreCaFile }}
K8E_DATASTORE_CAFILE={{ .DataStoreCaFile }}
{{- end }}
{{- if .DataStoreCertFile }}
K8E_DATASTORE_CERTFILE={{ .DataStoreCertFile }}
{{- end }}
{{- if .DataStoreKeyFile }}
K8E_DATASTORE_KEYFILE={{ .DataStoreKeyFile }}
{{- end }}
K8E_KUBECONFIG_MODE=644
{{ end }}
{{ if .Token }}
K8E_TOKEN={{ .Token }}
{{ end }}

    `)))

K8eServiceEnv defines the template of kubelet's Env for the kubelet's systemd service.

View Source
var K8eUninstallScript = template.Must(template.New("k8e-uninstall.sh").Parse(
	dedent.Dedent(`#!/bin/sh
set -x
[ $(id -u) -eq 0 ] || exec sudo $0 $@

/usr/local/bin/k8e-killall.sh

if which systemctl; then
    systemctl disable k8e
    systemctl reset-failed k8e
    systemctl daemon-reload
fi
if which rc-update; then
    rc-update delete k8e default
fi

rm -f /etc/systemd/system/k8e.service
rm -rf /etc/systemd/system/k8e.service.d
rm -f /etc/systemd/system/k8e.service.env

remove_uninstall() {
    rm -f /usr/local/bin/k8e-uninstall.sh
}
trap remove_uninstall EXIT

if (ls /etc/systemd/system/k8e*.service || ls /etc/init.d/k8e*) >/dev/null 2>&1; then
    set +x; echo 'Additional k8e services installed, skipping uninstall of k8e'; set -x
    exit
fi

for cmd in kubectl crictl ctr; do
    if [ -L /usr/local/bin/$cmd ]; then
        rm -f /usr/local/bin/$cmd
    fi
done

rm -rf /etc/rancher/k8e
rm -rf /run/k8e
rm -rf /var/lib/k8e
rm -rf /var/lib/kubelet
rm -f /usr/local/bin/k8e
rm -f /usr/local/bin/k8e-killall.sh
    `)))

K8eUninstallScript defines the template of k3s-killall script.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL