Skip to content

Commit

Permalink
Fix kubeconfig generation
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <derek.nola@suse.com>
  • Loading branch information
dereknola committed Jan 31, 2025
1 parent 155abff commit bd342f7
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tests/e2e/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (tc *TestConfig) Status() string {
if tc.Hardened {
hardened = "Hardened: true\n"
}
return fmt.Sprintf("%sServers Nodes: %s\nAgents Nodes: %s\n)", hardened, sN, aN)
return fmt.Sprintf("%sKubeconfig: %s\nServers Nodes: %s\nAgents Nodes: %s\n)", tc.KubeConfigFile, hardened, sN, aN)
}

type Node struct {
Expand Down Expand Up @@ -157,10 +157,19 @@ func CreateCluster(nodeOS string, serverCount, agentCount int) (*TestConfig, err
return nil, err
}

kubeConfigFile, err := GenKubeConfigFile(serverNodes[0].String())
// For startup test, we don't start the cluster, so check first before
// generating the kubeconfig file
var kubeConfigFile string
res, err := serverNodes[0].RunCmdOnNode("systemctl is-active k3s")
if err != nil {
return nil, err
}
if !strings.Contains(res, "inactive") && strings.Contains(res, "active") {
kubeConfigFile, err = GenKubeConfigFile(serverNodes[0].String())
if err != nil {
return nil, err
}
}

tc := &TestConfig{
KubeConfigFile: kubeConfigFile,
Expand Down Expand Up @@ -246,11 +255,13 @@ func CreateLocalCluster(nodeOS string, serverCount, agentCount int) (*TestConfig
return nil, err
}

// For startup test, we don't start the cluster, so check first before
// generating the kubeconfig file
// For startup test, we don't start the cluster, so check first before generating the kubeconfig file.
// Systemctl returns a exit code of 3 when the service is inactive, so we don't check for errors
// on the command itself.
var kubeConfigFile string
res, err := serverNodes[0].RunCmdOnNode("sudo systemctl is-active k3s")
if err != nil && !strings.Contains(res, "inactive") && strings.Contains(res, "active") {
var err error
res, _ := serverNodes[0].RunCmdOnNode("systemctl is-active k3s")
if !strings.Contains(res, "inactive") && strings.Contains(res, "active") {
kubeConfigFile, err = GenKubeConfigFile(serverNodes[0].String())
if err != nil {
return nil, err
Expand Down

0 comments on commit bd342f7

Please sign in to comment.