@@ -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
1213func (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
2121type 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
5588func (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-
89103func (z * Zeusro ) callThanos () {
90104 fmt .Println ("Thanos: I am inevitable." )
91105 time .Sleep (time .Second * 2 )
0 commit comments