Skip to content

Commit dbbc6ff

Browse files
chore: fix taskfile for evicter, add funs for stop vm duration
Signed-off-by: Nikita Korolev <nikita.korolev@flant.com>
1 parent baaae86 commit dbbc6ff

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

tests/performance/statistic/internal/vm/get_vm.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
type VM struct {
1818
Name string `json:"name"`
1919
VirtualMachineLaunchTimeDuration v1alpha2.VirtualMachineLaunchTimeDuration `json:"launchTimeDuration"`
20+
VirtualMachineStopTime time.Duration `json:"stopTime,omitempty"`
2021
}
2122

2223
type VMs struct {
@@ -118,3 +119,41 @@ func Get(client kubeclient.Client, namespace string) {
118119

119120
vms.SaveToCSV(namespace)
120121
}
122+
123+
func getStoppingAndStoppedDuration(vm v1alpha2.VirtualMachine) time.Duration {
124+
var (
125+
stopping metav1.Time
126+
stopped metav1.Time
127+
)
128+
for _, transition := range vm.Status.Stats.PhasesTransitions {
129+
if string(transition.Phase) == "Stopping" {
130+
stopping = transition.Timestamp
131+
}
132+
if string(transition.Phase) == "Stopped" {
133+
stopped = transition.Timestamp
134+
}
135+
}
136+
return stopped.Time.Sub(stopping.Time) // `Time` is from metav1.Time
137+
}
138+
139+
func GetStatStop(client kubeclient.Client, namespace string) {
140+
var vms VMs
141+
142+
vmList, err := client.VirtualMachines(namespace).List(context.TODO(), metav1.ListOptions{})
143+
if err != nil {
144+
fmt.Printf("Failed to get vm: %v\n", err)
145+
os.Exit(1)
146+
}
147+
fmt.Println("Total VMs:", len(vmList.Items))
148+
149+
for _, vm := range vmList.Items {
150+
if string(vm.Status.Phase) == "Stopped" {
151+
vms.Items = append(vms.Items, VM{
152+
Name: vm.Name,
153+
// VirtualMachinePhaseTransitionTimestamp
154+
// vm.Status.Stats.PhasesTransitions[len(vm.Status.Stats.PhasesTransitions)-1]
155+
VirtualMachineStopTime: getStoppingAndStoppedDuration(vm),
156+
})
157+
}
158+
}
159+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "3"
2+
3+
silent: true
4+
5+
vars:
6+
NS: '{{ .NS | default "perf" }}'
7+
TARGET: '{{ .TARGET | default 10 }}'
8+
9+
tasks:
10+
run:miration:
11+
desc: "Run migration | NS=myns TARGET=10 task run:miration"
12+
cmds:
13+
- go run main.go -ns={{.NS}} -target={{.TARGET}}

0 commit comments

Comments
 (0)