Skip to content

Commit ab47dc3

Browse files
author
Zeusro
committed
Mon Jan 12 22:04:59 CST 2026
1 parent a2ad478 commit ab47dc3

3 files changed

Lines changed: 95 additions & 44 deletions

File tree

cmd/killer/kill.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"strings"
88

9+
"github.com/p-program/kube-killer/config"
910
"github.com/p-program/kube-killer/core"
1011
"github.com/rs/zerolog/log"
1112
"github.com/spf13/cobra"
@@ -333,6 +334,15 @@ func SelectKiller(args []string) error {
333334
case "me":
334335
log.Warn().Msg("!!!WARNING!!!: PLEASE DO NOT USE. It's an unpredictable command.")
335336
return nil
337+
case "zeusro":
338+
log.Warn().Msg("!!!WARNING!!!: ZEUSRO mode - 50% chance nothing happens, 50% chance deletes 50% of pods randomly!")
339+
projectConfig := config.NewProjectConfig()
340+
targetNamespace := namespace
341+
if allNamespaces {
342+
targetNamespace = ""
343+
}
344+
z := NewZeusro(projectConfig, targetNamespace, dryRun)
345+
return z.Run()
336346
case "n", "no", "node":
337347
if len(args) < 2 {
338348
log.Error().Msg("Node name is required")

cmd/killer/zeusro.go

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,85 @@ import (
66
"time"
77

88
"github.com/p-program/kube-killer/config"
9+
"github.com/rs/zerolog/log"
910
)
1011

11-
// Coin live or dead ?
12+
// Coin returns true with 50% probability
1213
func (z *Zeusro) Coin() bool {
13-
//prevent same result
1414
// Use rand.New() instead of deprecated rand.Seed() (Go 1.20+)
1515
r := rand.New(rand.NewSource(time.Now().UnixNano()))
1616
v := r.Intn(2)
1717
return v == 1
1818
}
1919

20-
// Zeusro Kuiper
20+
// Zeusro Kuiper - The unpredictable killer
2121
type Zeusro struct {
22-
dryRun bool
23-
config *config.ProjectConfig
22+
dryRun bool
23+
namespace string
24+
config *config.ProjectConfig
2425
}
2526

26-
func NewZeusro(config *config.ProjectConfig, dryRun bool) *Zeusro {
27+
func NewZeusro(config *config.ProjectConfig, namespace string, dryRun bool) *Zeusro {
2728
z := Zeusro{
28-
dryRun: dryRun,
29-
config: config,
29+
dryRun: dryRun,
30+
namespace: namespace,
31+
config: config,
3032
}
3133
return &z
3234
}
3335

34-
func (z *Zeusro) Run() {
36+
// DryRun sets the dryRun flag
37+
func (z *Zeusro) DryRun() *Zeusro {
38+
z.dryRun = true
39+
return z
40+
}
41+
42+
// Run executes the Zeusro command:
43+
// - 50% probability: Valar Dohaeris (nothing happens)
44+
// - 50% probability: Thanos mode (randomly delete 50% of pods)
45+
func (z *Zeusro) Run() error {
3546
if z.dryRun {
36-
fmt.Println("Leonard: I am sorry,I have to go.")
37-
time.Sleep(time.Second)
38-
fmt.Println("Leonard: I don't believe this.")
39-
time.Sleep(time.Second * 2)
40-
z.callSheldon()
41-
return
47+
log.Info().Msg("Zeusro: [DRY RUN] The coin will be flipped...")
48+
coin := z.Coin()
49+
if coin {
50+
log.Info().Msg("Arya: Valar Dohaeris (Nothing happens)")
51+
} else {
52+
log.Warn().Msg("Thanos: I am inevitable. [DRY RUN] Would delete 50% of pods")
53+
}
54+
return nil
4255
}
56+
4357
coin := z.Coin()
44-
dead := !coin
45-
if dead {
46-
fmt.Println("Zeusro: Goodbye.")
47-
z.callMyWife()
58+
if coin {
59+
// Valar Dohaeris - nothing happens
60+
fmt.Println("Arya: Valar Dohaeris")
61+
log.Info().Msg("Zeusro: All shall serve. Nothing happens.")
62+
return nil
4863
}
49-
live := coin
50-
if live {
51-
z.callAryaStark()
64+
65+
// Thanos mode - delete 50% of pods
66+
fmt.Println("Thanos: I am inevitable.")
67+
time.Sleep(time.Second)
68+
fmt.Println("Thanos: *snaps fingers*")
69+
time.Sleep(time.Second)
70+
fmt.Println("Thanos: The universe will be balanced.")
71+
log.Warn().Msg("Zeusro: Thanos mode activated - deleting 50% of pods randomly")
72+
73+
// Create PodKiller and kill half of the pods
74+
podKiller, err := NewPodKiller(z.namespace)
75+
if err != nil {
76+
return fmt.Errorf("failed to create PodKiller: %w", err)
5277
}
78+
79+
// Set half mode to delete 50% of pods
80+
podKiller.SetHalf()
81+
// BlackHand is needed to trigger KillHalfPods
82+
podKiller.BlackHand()
83+
84+
return podKiller.Kill()
5385
}
5486

87+
// Legacy methods kept for backward compatibility
5588
func (z *Zeusro) callAryaStark() {
5689
coin := z.Coin()
5790
dead := !coin
@@ -67,25 +100,6 @@ func (z *Zeusro) callAryaStark() {
67100
}
68101
}
69102

70-
func (z *Zeusro) callSheldon() {
71-
fmt.Print("Sheldon: A")
72-
for i := 0; i < 2049; i++ {
73-
time.Sleep(time.Millisecond * 2)
74-
fmt.Print("a")
75-
}
76-
fmt.Println("!")
77-
time.Sleep(time.Second * 3)
78-
fmt.Println("Sheldon: BAZINGA PUNK!!! NOW WE'RE EVEN.")
79-
}
80-
81-
func (z *Zeusro) callMyWife() {
82-
fmt.Println("Penny: What? What happened?")
83-
time.Sleep(time.Second)
84-
fmt.Println("Penny: Oh my god, are you okay?")
85-
time.Sleep(time.Second)
86-
fmt.Println("Penny: I'm coming over right now!")
87-
}
88-
89103
func (z *Zeusro) callThanos() {
90104
fmt.Println("Thanos: I am inevitable.")
91105
time.Sleep(time.Second * 2)

cmd/killer/zeusro_test.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"testing"
77

88
"github.com/p-program/kube-killer/config"
9+
"github.com/stretchr/testify/assert"
910
)
1011

1112
func prepareZeusro() *Zeusro {
1213
projectConfig := config.NewProjectConfig()
13-
return NewZeusro(projectConfig, false)
14+
return NewZeusro(projectConfig, "default", false)
1415
}
1516

1617
func TestCoin(t *testing.T) {
@@ -44,11 +45,37 @@ func BenchmarkFmtCoin(b *testing.B) {
4445
}
4546

4647
func TestFakeZeusro(t *testing.T) {
48+
skipIfNoCluster(t)
4749
z := prepareZeusro()
48-
z.Run()
50+
z.DryRun()
51+
err := z.Run()
52+
// Error may occur if no pods exist, which is fine
53+
_ = err
4954
}
5055

5156
func TestZeusro(t *testing.T) {
57+
skipIfNoCluster(t)
5258
z := prepareZeusro()
53-
z.Run()
59+
z.DryRun()
60+
err := z.Run()
61+
// Error may occur if no pods exist, which is fine
62+
_ = err
63+
}
64+
65+
func TestZeusroNewZeusro(t *testing.T) {
66+
skipIfNoCluster(t)
67+
projectConfig := config.NewProjectConfig()
68+
z := NewZeusro(projectConfig, "default", true)
69+
assert.NotNil(t, z)
70+
assert.Equal(t, "default", z.namespace)
71+
assert.True(t, z.dryRun)
72+
assert.NotNil(t, z.config)
73+
}
74+
75+
func TestZeusroDryRun(t *testing.T) {
76+
skipIfNoCluster(t)
77+
projectConfig := config.NewProjectConfig()
78+
z := NewZeusro(projectConfig, "default", false)
79+
z.DryRun()
80+
assert.True(t, z.dryRun)
5481
}

0 commit comments

Comments
 (0)