diff --git a/build/cd/deploy.go b/build/cd/deploy.go index a888d956d5a0a7e4c2017e3689616d52120559f0..06a8a8097b9ee5a66b249eb78023ba014aa43fba 100644 --- a/build/cd/deploy.go +++ b/build/cd/deploy.go @@ -3,9 +3,11 @@ package main import ( "context" "os" + "strconv" nucleus "code.fbi.h-da.de/cocsn/gosdn/nucleus/errors" log "github.com/sirupsen/logrus" + "github.com/spf13/viper" appv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" netv1 "k8s.io/api/networking/v1" @@ -52,11 +54,42 @@ func main() { if err := remove(clientset, tag); err != nil { log.Fatal(err) } + case "getenv": + if err := getenv(clientset, tag); err != nil { + log.Fatal(err) + } default: log.Fatal("invalid option") } } +func getenv(clientset *kubernetes.Clientset, tag string) error { + env := "gosdn-" + tag + opts := metav1.GetOptions{} + ctx := context.Background() + service, err := clientset.CoreV1().Services("cocsn").Get(ctx, env, opts) + if err != nil { + return err + } + var ip string + for _, ingress := range service.Status.LoadBalancer.Ingress { + ip = ingress.IP + } + + var port string + for _, p := range service.Spec.Ports { + if p.Name == "grpc" { + port = strconv.Itoa(int(p.NodePort)) + } + } + log.WithFields(log.Fields{ + "ip": ip, + "port": port, + }).Info(env) + viper.Set("GOSDN_TEST_API_ENDPOINT", ip+":"+port) + return viper.SafeWriteConfigAs(".k8s.toml") +} + // nolint func create(clientset *kubernetes.Clientset, tag string) error { env := "gosdn-" + tag @@ -82,6 +115,7 @@ func create(clientset *kubernetes.Clientset, tag string) error { } else { log.Printf("service %v created", service.Name) } + _, err = clientset.CoreV1().ConfigMaps("cocsn").Create(ctx, config, opts) if err != nil { switch err.(type) { diff --git a/build/ci/.test.yml b/build/ci/.test.yml index ace7a5e1e7aa24d2982ed447903e82c96072b956..863f3e3157381ea09efbdc5bde5f054d300142ea 100644 --- a/build/ci/.test.yml +++ b/build/ci/.test.yml @@ -4,8 +4,6 @@ needs: - job: "apply" - job: "deploy:integration-test" - variables: - GOSDN_TEST_API_ENDPOINT: gosdn-$CI_COMMIT_SHA.apps.ocp.fbi.h-da.de:80 rules: - if: $CI_NIGHTLY when: delayed @@ -29,8 +27,17 @@ integration-test:nucleus: integration-test:cmd: <<: *integration-test + variables: + K8S_OP: "getenv" + needs: + - job: "build:merge-request" + - job: "apply" + - job: "deploy:integration-test" + - job: "build:k8s-bot" + artifacts: true script: - cd ./test/integration + - ./../build/cd/k8s-bot - go test -race -v -run TestCmdIntegration integration-test:cli: diff --git a/test/integration/cmdIntegration_test.go b/test/integration/cmdIntegration_test.go index 37a4405be4452724f08ee456c65613f5631892de..f82ffd7e55951d1c9299cc990954c96488988886 100644 --- a/test/integration/cmdIntegration_test.go +++ b/test/integration/cmdIntegration_test.go @@ -30,6 +30,11 @@ func TestMain(m *testing.M) { } func testSetupIntegration() { + viper.SetConfigFile(".k8s.toml") + if err := viper.ReadInConfig(); err != nil { + log.Fatal(err) + } + if os.Getenv("GOSDN_LOG") == "nolog" { log.SetLevel(log.PanicLevel) } @@ -39,7 +44,7 @@ func testSetupIntegration() { testAddress = a log.Infof("GOSDN_TEST_ENDPOINT set to %v", testAddress) } - api := os.Getenv("GOSDN_TEST_API_ENDPOINT") + api := viper.GetString("gosdn_test_api_endpoint") if api != "" { testAPIEndpoint = api log.Infof("GOSDN_TEST_API_ENDPOINT set to %v", testAPIEndpoint) @@ -83,8 +88,6 @@ func testSetupIntegration() { } func TestCmdIntegration(t *testing.T) { - // TDOO: Remove once openshift grpc support is available - t.Skip("skipped due to openshift limitations") if testing.Short() { t.Skip("skipping integration test") }