Skip to content

Commit

Permalink
feat(dev): added emulation of virtual machine movements
Browse files Browse the repository at this point in the history
Shatal - the tool for virtual machine wobbling.

Available operations:

Node draining with migration of virtual machines
Update core fraction from 10% to 25% and vice versa
Creation of virtual machines
Deletion of virtual machines

---------

Signed-off-by: Isteb4k <[email protected]>
  • Loading branch information
Isteb4k authored Jun 5, 2024
1 parent 460f069 commit 677708b
Show file tree
Hide file tree
Showing 21 changed files with 1,783 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ includes:
e2e:
taskfile: ./tests/e2e
dir: ./tests/e2e
perf:
taskfile: ./tests/performance
dir: ./tests/performance

vars:
deckhouse_lib_helm_ver: 1.7.0
Expand Down
5 changes: 5 additions & 0 deletions tests/performance/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ version: "3"

silent: true

includes:
shatal:
taskfile: ./shatal
dir: ./shatal

vars:
COUNT: '{{ .COUNT | default "1" }}'
NAMESPACE: "{{ .NAMESPACE }}"
Expand Down
61 changes: 61 additions & 0 deletions tests/performance/shatal/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
run:
timeout: 10m
# skip-dirs:
# this code has been copied from kubectl cli. No need to lint external code.
# - go_lib/dependency/k8s/drain
# this code has been copied from kubernetes vertical-pod-autoscaler. No need to lint external code.
# - modules/302-vertical-pod-autoscaler/hooks/internal/vertical-pod-autoscaler/v1
issues:
# Show all errors.
max-issues-per-linter: 0
max-same-issues: 0
exclude:
# - ST1005.*
- "don't use an underscore in package name"
# - "exported: .*"

linters-settings:
gofumpt:
extra-rules: true
gci:
sections:
- standard
- default
- prefix(github.com/deckhouse/)
goimports:
local-prefixes: github.com/deckhouse/
errcheck:
ignore: fmt:.*,[rR]ead|[wW]rite|[cC]lose,io:Copy
revive:
rules:
- name: dot-imports
disabled: true

linters:
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
- dogsled
- errcheck
- errname
- errorlint
- exportloopref
- gci
- gocritic
- gofmt
- gofumpt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- nolintlint
- revive
- staticcheck
- typecheck
- unconvert
- unparam
- unused
- whitespace
81 changes: 81 additions & 0 deletions tests/performance/shatal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Shatal - the tool for virtual machine wobbling.

## Available operations

- Node draining with migration of virtual machines
- Update core fraction from 10% to 25% and vice versa
- Creation of virtual machines
- Deletion of virtual machines
## How to run

```shell
KUBECONFIG=$(cat ~/.kube/config | base64 -w 0)
KUBECONFIG_BASE64=$KUBECONFIG task run
```

## How to configure

The binary expects a `config.yaml` file to configure its operation. The description of the expected configuration is given below.

```yaml
# Base64 of kubeconfig to interact with k8s API.
# Corresponds to the KUBECONFIG_BASE64 environment variable.
kubeconfigBase64: "XXX="
# The resource prefix for virtual machine wobbling.
# Corresponds to the RESOURCES_PREFIX environment variable.
resourcesPrefix: "performance"
# The namespace of virtual machines to wobble.
# Corresponds to the NAMESPACE environment variable.
namespace: "default"
# The interval of wobbling iterations.
# Corresponds to the INTERVAL environment variable.
interval: "5s"
# The count of virtual machines to wobble.
# Corresponds to the COUNT environment variable.
count: 100
# The flag to show debug level logs.
# Corresponds to the DEBUG environment variable.
debug: true
drainer:
# The flag to enable node draining.
# Corresponds to the DRAINER_ENABLED environment variable.
enabled: true
# Flag to drain the node only once.
# Corresponds to the DRAINER_ONCE environment variable.
once: true
# The selector to specify nodes to drain
# Corresponds to the DRAINER_LABEL_SELECTOR environment variable.
labelSelector: true
# The interval between draining operations.
# Corresponds to the DRAINER_INTERVAL environment variable.
interval: "10s"
creator:
# The flag is enabled to initiate the generation of missing virtual machines until the target quantity is reached (where the target quantity equals the 'count' value).
# Corresponds to the CREATOR_ENABLED environment variable.
enabled: true
# The interval of creation iterations.
# Corresponds to the CREATOR_INTERVAL environment variable.
interval: "5s"
deleter:
# The flag to enable deletion of virtual machines.
# Corresponds to the DELETER_ENABLED environment variable.
enabled: true
# The weight of this operation in comparison to others (determines the probability of triggering the deletion scenario).
# Corresponds to the DELETER_WIGHT environment variable.
weight: 1
modifier:
# The flag to enable update of virtual machines (core fraction from 10% to 25% and vice versa).
# Corresponds to the MODIFIER_ENABLED environment variable.
enabled: true
# The weight of this operation in comparison to others (determines the probability of triggering the deletion scenario).
# Corresponds to the MODIFIER_WIGHT environment variable.
weight: 1
nothing:
# Just a flag to do nothing with virtual machines compared other operations.
# Maybe you want 10% of virtual machines to be updated, 10% deleted, and 80% to continue working as usual.
# Corresponds to the NOTHING_ENABLED environment variable.
enabled: true
# The weight of the operation determines the probability of taking no action with the virtual machine.
# Corresponds to the NOTHING_WIGHT environment variable.
weight: 8
```
16 changes: 16 additions & 0 deletions tests/performance/shatal/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# https://taskfile.dev

version: "3"

silent: true

tasks:
run:
desc: "Run emulation of virtual machine movements"
cmds:
- |
if [[ -n "$KUBECONFIG_BASE64" ]] ; then
KUBECONFIG_BASE64=$KUBECONFIG_BASE64 go run cmd/shatal/main.go
else
go run cmd/shatal/main.go
fi
46 changes: 46 additions & 0 deletions tests/performance/shatal/cmd/shatal/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"log/slog"
"os"
"os/signal"
"syscall"

"github.com/deckhouse/virtualization/shatal/internal/api"
"github.com/deckhouse/virtualization/shatal/internal/config"
"github.com/deckhouse/virtualization/shatal/internal/logger"
"github.com/deckhouse/virtualization/shatal/internal/shatal"
)

func main() {
conf, err := config.New()
if err != nil {
panic(err)
}

var log *slog.Logger
if conf.Debug {
log = logger.New(logger.NewDebugOption())
} else {
log = logger.New()
}

client, err := api.NewClient(conf.Kubeconfig, conf.Namespace, conf.ResourcesPrefix, log)
if err != nil {
panic(err)
}

service, err := shatal.New(client, conf, log)
if err != nil {
panic(err)
}

service.Run()

exit := make(chan os.Signal, 1)
signal.Notify(exit, syscall.SIGINT, syscall.SIGTERM)

<-exit

service.Stop()
}
22 changes: 22 additions & 0 deletions tests/performance/shatal/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
kubeconfigBase64: "XXX="
resourcesPrefix: "performance"
namespace: "default"
interval: "5s"
count: 100
debug: true
drainer:
enabled: true
interval: "10s"
labelSelector: "!node-role.kubernetes.io/master"
creator:
enabled: true
interval: "5s"
deleter:
enabled: true
weight: 1
modifier:
enabled: true
weight: 1
nothing:
enabled: true
weight: 8
93 changes: 93 additions & 0 deletions tests/performance/shatal/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
module github.com/deckhouse/virtualization/shatal

go 1.21

require (
github.com/deckhouse/virtualization/api v0.0.0-20240408082728-b892ddd03f9e
github.com/google/uuid v1.3.0
github.com/ilyakaznacheev/cleanenv v1.5.0
k8s.io/api v0.29.3
k8s.io/apimachinery v0.29.3
k8s.io/client-go v0.29.3
k8s.io/kubectl v0.29.3
sigs.k8s.io/controller-runtime v0.17.2
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/openshift/api v0.0.0-20230503133300-8bbcb7ca7183 // indirect
github.com/openshift/custom-resource-status v1.1.2 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.29.2 // indirect
k8s.io/cli-runtime v0.29.3 // indirect
k8s.io/component-base v0.29.3 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
kubevirt.io/api v1.0.0 // indirect
kubevirt.io/containerized-data-importer-api v1.57.0-alpha1 // indirect
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace github.com/deckhouse/virtualization/api => ./../../../api
Loading

0 comments on commit 677708b

Please sign in to comment.