Skip to content

Commit

Permalink
Merge pull request #35 from mguetta1/add-kubeconfig
Browse files Browse the repository at this point in the history
Add kubeconfig
  • Loading branch information
sshveta committed Sep 21, 2023
2 parents 97be782 + 6e5e17e commit d6bf743
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ git clone https://github.com/aufi/go-konveyor-tests && cd go-konveyor-tests
$ make setup # start minikube&tackle using David's scripts - local env only
```

### OpenShift cluster

These tests can be executed against OpenShift cluster with Konveyor installed by setting `KUBECONFIG` variable:

```
KUBECONFIG=<kubeconfig file>
```

> **_NOTE:_** You might be required to download and import the certificate chain. Please see [Hub API test README](https://github.com/konveyor/tackle2-hub/tree/main/test#https) for more information.
### Run test suite

Set ```$HUB_BASE_URL``` environment variable to point to Konveyor installation before running tests. More options could be found in [Hub API test README](https://github.com/konveyor/tackle2-hub/tree/main/test#rest-api).
Expand Down
1 change: 1 addition & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"KUBECONFIG": "",
"RETRY_NUM": "10",
"KEEP": "0"
}
1 change: 1 addition & 0 deletions config/configuration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

type Configuration struct {
KUBECONFIG string `env:"KUBECONFIG"`
JIRA_USERNAME string `env:"JIRA_USERNAME"`
JIRA_PASSWORD string `env:"JIRA_PASSWORD"`
JIRA_URL string `env:"JIRA_URL"`
Expand Down
41 changes: 28 additions & 13 deletions e2e/metrics/metrics_utils.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package metrics

import (
"bytes"
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"time"

. "github.com/konveyor/go-konveyor-tests/config"
. "github.com/onsi/gomega"

"github.com/konveyor/go-konveyor-tests/utils"
)

Expand All @@ -16,10 +20,6 @@ var (
hub_pod_name string
)

func init() {
hub_pod_name = getHubFullName()
}

func getHubFullName() string {
operator_namespace = "konveyor-tackle"
pod := "tackle-hub"
Expand All @@ -30,25 +30,40 @@ func getHubFullName() string {
pod = "mta-hub"
}
cmd := fmt.Sprintf("oc get pod -n %s | grep %s | awk '{print $1}'", operator_namespace, pod)
return runCmd(cmd)
return runOpenshiftCmd(cmd)
}

func GetMetricValue(metricName string) int {
hub_pod_name = getHubFullName()
utils.Log.Info("Waiting for 30 seconds...")
time.Sleep(30 * time.Second)
cmd := fmt.Sprintf("oc exec -n %s %s -- curl -s http://localhost:2112/metrics | grep %s", operator_namespace, hub_pod_name, metricName)
var outStr []string = strings.Split(runCmd(cmd), "\n")
var outStr []string = strings.Split(runOpenshiftCmd(cmd), "\n")
metricValue := outStr[len(outStr)-1]
metricValue = utils.LastString(strings.Split(metricValue, " "))
outInt, _ := strconv.Atoi(metricValue)
return outInt
}

func runCmd(cmd string) string {
out, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
return fmt.Sprintf("Failed to execute command: %s", cmd)
}
out = out[:len(out)-1]
return string(out)
// runOpenshiftCmd runs an OpenShift command and returns its output as a string.
func runOpenshiftCmd(cmd string) string {
os.Setenv("KUBECONFIG", Config.KUBECONFIG)

// Create a new command to execute in a Bash environment.
command := exec.Command("bash", "-c", cmd)

// Create a buffer to capture the standard output of the executed command.
var out bytes.Buffer
command.Stdout = &out

// Execute the command and check for any errors.
err := command.Run()
Expect(err).ShouldNot(HaveOccurred())

// Assert that the captured output is not empty.
Expect(out.Len()).ShouldNot(BeZero())

// Removing the trailing newline character ("\n")
outStr := out.String()
return outStr[:len(outStr)-1]
}

0 comments on commit d6bf743

Please sign in to comment.