Skip to content

Commit

Permalink
Better kcp cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekMichali committed Jan 3, 2025
1 parent 8de9c91 commit e8b7a1b
Showing 1 changed file with 5 additions and 42 deletions.
47 changes: 5 additions & 42 deletions testing/e2e/skr-tester/pkg/command/update.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package command

import (
"encoding/json"
"errors"
"fmt"
"os/exec"
broker "skr-tester/pkg/broker"
"skr-tester/pkg/logger"
"strings"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -114,50 +114,13 @@ func getCurrentMachineType(instanceID string) (*string, error) {
if err != nil {
return nil, fmt.Errorf("failed to run kcp login: %v", err)
}
output, err := exec.Command("kcp", "rt", "-i", instanceID, "-ojson", "--runtime-config").Output()
output, err := exec.Command("kcp", "rt", "-i", instanceID, "--runtime-config", "-o", "custom=:{.runtimeConfig.spec.shoot.provider.workers[0].machine.type}").Output()
if err != nil {
return nil, fmt.Errorf("failed to run kcp rt: %v", err)
}
var outputData map[string]interface{}
if err := json.Unmarshal(output, &outputData); err != nil {
return nil, fmt.Errorf("failed to unmarshal output: %v", err)
}
data, ok := outputData["data"].([]interface{})
if !ok || len(data) == 0 {
return nil, errors.New("data field not found or empty in output")
}
runtimeConfig, ok := data[0].(map[string]interface{})["runtimeConfig"].(map[string]interface{})
if !ok {
return nil, errors.New("runtimeConfig field not found in data")
}
spec, ok := runtimeConfig["spec"].(map[string]interface{})
if !ok {
return nil, errors.New("spec field not found in runtimeConfig")
}
shoot, ok := spec["shoot"].(map[string]interface{})
if !ok {
return nil, errors.New("shoot field not found in spec")
}
provider, ok := shoot["provider"].(map[string]interface{})
if !ok {
return nil, errors.New("provider field not found in shoot")
}
workers, ok := provider["workers"].([]interface{})
if !ok || len(workers) == 0 {
return nil, errors.New("workers field not found or empty in provider")
}
worker, ok := workers[0].(map[string]interface{})
if !ok {
return nil, errors.New("worker field not found in workers")
}
machine, ok := worker["machine"].(map[string]interface{})
if !ok {
return nil, errors.New("machine field not found in worker")
}
machineType, ok := machine["type"].(string)
if !ok {
return nil, errors.New("type field not found in machine")
}

machineType := string(output)
machineType = strings.TrimSpace(machineType)
return &machineType, nil
}

Expand Down

0 comments on commit e8b7a1b

Please sign in to comment.