Skip to content

Commit 7773a10

Browse files
author
Zeusro
committed
Mon Jan 12 06:53:29 CST 2026
1 parent 3457d1f commit 7773a10

6 files changed

Lines changed: 16 additions & 43 deletions

File tree

cmd/freeze.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@ import (
55
"github.com/spf13/cobra"
66
)
77

8-
func init() {
9-
10-
}
11-
128
var (
139
namespace string
14-
dryRun bool
1510
)
1611

1712
func NewFreezeCommand() *cobra.Command {
@@ -33,6 +28,5 @@ func NewFreezeCommand() *cobra.Command {
3328
icebox.Freeze(args[0], args[1])
3429
}}
3530
c.PersistentFlags().StringVarP(&namespace, "namespace", "n", "default", "working namespace")
36-
c.PersistentFlags().BoolVarP(&dryRun, "dryrun", "d", false, "dryRun")
3731
return c
3832
}

cmd/killer/job_killer.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,20 @@ func (k *JobKiller) KillHalfJobs() error {
8787
log.Info().Msg("No jobs to kill")
8888
return nil
8989
}
90-
90+
9191
// Randomly shuffle the jobs list
9292
jobList := jobs.Items
9393
rand.Seed(time.Now().UnixNano())
9494
rand.Shuffle(len(jobList), func(i, j int) {
9595
jobList[i], jobList[j] = jobList[j], jobList[i]
9696
})
97-
97+
9898
// Calculate how many jobs to kill (half, rounded down)
9999
jobsToKill := len(jobList) / 2
100100
if jobsToKill == 0 {
101101
jobsToKill = 1 // At least kill one job if there's only one
102102
}
103-
103+
104104
log.Info().Msgf("Killing %d out of %d jobs", jobsToKill, len(jobList))
105105
for i := 0; i < jobsToKill; i++ {
106106
job := jobList[i]
@@ -136,7 +136,7 @@ func (k *JobKiller) DeserveDead(resource interface{}) bool {
136136
return true
137137
}
138138
job := resource.(batchv1.Job)
139-
139+
140140
// Check if job is completed based on conditions
141141
for _, condition := range job.Status.Conditions {
142142
if condition.Type == batchv1.JobComplete && condition.Status == "True" {
@@ -146,7 +146,7 @@ func (k *JobKiller) DeserveDead(resource interface{}) bool {
146146
return true
147147
}
148148
}
149-
149+
150150
// If no conditions are set, check completion based on spec and status
151151
// A job is considered complete if:
152152
// 1. It has completions specified and succeeded count matches
@@ -161,12 +161,11 @@ func (k *JobKiller) DeserveDead(resource interface{}) bool {
161161
return true
162162
}
163163
}
164-
164+
165165
// Check if job has failed (backoff limit exceeded)
166166
if job.Spec.BackoffLimit != nil && job.Status.Failed > *job.Spec.BackoffLimit {
167167
return true
168168
}
169-
169+
170170
return false
171171
}
172-

cmd/killer/pod_killer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ func (k *PodKiller) KillHalfPods() error {
143143
log.Info().Msg("No pods to kill")
144144
return nil
145145
}
146-
146+
147147
// Randomly shuffle the pods list
148148
podList := pods.Items
149149
rand.Seed(time.Now().UnixNano())
150150
rand.Shuffle(len(podList), func(i, j int) {
151151
podList[i], podList[j] = podList[j], podList[i]
152152
})
153-
153+
154154
// Calculate how many pods to kill (half, rounded down)
155155
podsToKill := len(podList) / 2
156156
if podsToKill == 0 {

cmd/killer/pvc_killer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,20 @@ func (k *PVCKiller) KillHalfPVCs() error {
104104
log.Info().Msg("No PVCs to kill")
105105
return nil
106106
}
107-
107+
108108
// Randomly shuffle the PVCs list
109109
pvcList := list.Items
110110
rand.Seed(time.Now().UnixNano())
111111
rand.Shuffle(len(pvcList), func(i, j int) {
112112
pvcList[i], pvcList[j] = pvcList[j], pvcList[i]
113113
})
114-
114+
115115
// Calculate how many PVCs to kill (half, rounded down)
116116
pvcsToKill := len(pvcList) / 2
117117
if pvcsToKill == 0 {
118118
pvcsToKill = 1 // At least kill one PVC if there's only one
119119
}
120-
120+
121121
log.Info().Msgf("Killing %d out of %d PVCs", pvcsToKill, len(pvcList))
122122
for i := 0; i < pvcsToKill; i++ {
123123
pvc := pvcList[i]
@@ -136,7 +136,7 @@ func (k *PVCKiller) KillUnusedPVCs() error {
136136
if err != nil {
137137
return err
138138
}
139-
139+
140140
// Get all Pods to check which PVCs are in use
141141
podKiller, err := NewPodKiller(k.namespace)
142142
if err != nil {
@@ -146,7 +146,7 @@ func (k *PVCKiller) KillUnusedPVCs() error {
146146
if err != nil {
147147
return err
148148
}
149-
149+
150150
// Build map of used PVCs
151151
usedPVCs := make(map[string]bool)
152152
for _, pod := range pods {
@@ -156,7 +156,7 @@ func (k *PVCKiller) KillUnusedPVCs() error {
156156
}
157157
}
158158
}
159-
159+
160160
// Delete unused PVCs
161161
for _, pvc := range pvcList.Items {
162162
// Skip bound PVCs that are in use

cmd/root.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package cmd
22

33
import (
4-
"fmt"
5-
"os"
6-
74
"github.com/p-program/kube-killer/cmd/killer"
85
"github.com/p-program/kube-killer/cmd/server"
96
"github.com/spf13/cobra"
@@ -12,8 +9,7 @@ import (
129

1310
var (
1411
// Used for flags.
15-
cfgFile string
16-
userLicense string
12+
cfgFile string
1713

1814
rootCmd = &cobra.Command{
1915
Use: "kube-killer",
@@ -30,12 +26,6 @@ func Execute() error {
3026
func init() {
3127
cobra.OnInitialize(initConfig)
3228
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config.yaml)")
33-
rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project")
34-
rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration")
35-
viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author"))
36-
viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper"))
37-
viper.SetDefault("author", "https://github.com/p-program")
38-
viper.SetDefault("license", "Mulan PSL v2")
3929
bindCommand()
4030

4131
}
@@ -51,11 +41,6 @@ func bindCommand() {
5141

5242
}
5343

54-
func er(msg interface{}) {
55-
fmt.Println("Error:", msg)
56-
os.Exit(1)
57-
}
58-
5944
func initConfig() {
6045
if cfgFile != "" {
6146
// Use config file from the flag.

cmd/util.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)