Skip to content
Snippets Groups Projects
Commit a33003b6 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

get k8s coordinated from k8s bot

parent 0783cfc9
No related branches found
No related tags found
1 merge request!159Resolve "Integration Tests Fail"
Pipeline #73951 passed with warnings
...@@ -3,9 +3,11 @@ package main ...@@ -3,9 +3,11 @@ package main
import ( import (
"context" "context"
"os" "os"
"strconv"
nucleus "code.fbi.h-da.de/cocsn/gosdn/nucleus/errors" nucleus "code.fbi.h-da.de/cocsn/gosdn/nucleus/errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
appv1 "k8s.io/api/apps/v1" appv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
netv1 "k8s.io/api/networking/v1" netv1 "k8s.io/api/networking/v1"
...@@ -52,11 +54,42 @@ func main() { ...@@ -52,11 +54,42 @@ func main() {
if err := remove(clientset, tag); err != nil { if err := remove(clientset, tag); err != nil {
log.Fatal(err) log.Fatal(err)
} }
case "getenv":
if err := getenv(clientset, tag); err != nil {
log.Fatal(err)
}
default: default:
log.Fatal("invalid option") 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 // nolint
func create(clientset *kubernetes.Clientset, tag string) error { func create(clientset *kubernetes.Clientset, tag string) error {
env := "gosdn-" + tag env := "gosdn-" + tag
...@@ -82,6 +115,7 @@ func create(clientset *kubernetes.Clientset, tag string) error { ...@@ -82,6 +115,7 @@ func create(clientset *kubernetes.Clientset, tag string) error {
} else { } else {
log.Printf("service %v created", service.Name) log.Printf("service %v created", service.Name)
} }
_, err = clientset.CoreV1().ConfigMaps("cocsn").Create(ctx, config, opts) _, err = clientset.CoreV1().ConfigMaps("cocsn").Create(ctx, config, opts)
if err != nil { if err != nil {
switch err.(type) { switch err.(type) {
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
needs: needs:
- job: "apply" - job: "apply"
- job: "deploy:integration-test" - job: "deploy:integration-test"
variables:
GOSDN_TEST_API_ENDPOINT: gosdn-$CI_COMMIT_SHA.apps.ocp.fbi.h-da.de:80
rules: rules:
- if: $CI_NIGHTLY - if: $CI_NIGHTLY
when: delayed when: delayed
...@@ -29,8 +27,17 @@ integration-test:nucleus: ...@@ -29,8 +27,17 @@ integration-test:nucleus:
integration-test:cmd: integration-test:cmd:
<<: *integration-test <<: *integration-test
variables:
K8S_OP: "getenv"
needs:
- job: "build:merge-request"
- job: "apply"
- job: "deploy:integration-test"
- job: "build:k8s-bot"
artifacts: true
script: script:
- cd ./test/integration - cd ./test/integration
- ./../build/cd/k8s-bot
- go test -race -v -run TestCmdIntegration - go test -race -v -run TestCmdIntegration
integration-test:cli: integration-test:cli:
......
...@@ -30,6 +30,11 @@ func TestMain(m *testing.M) { ...@@ -30,6 +30,11 @@ func TestMain(m *testing.M) {
} }
func testSetupIntegration() { func testSetupIntegration() {
viper.SetConfigFile(".k8s.toml")
if err := viper.ReadInConfig(); err != nil {
log.Fatal(err)
}
if os.Getenv("GOSDN_LOG") == "nolog" { if os.Getenv("GOSDN_LOG") == "nolog" {
log.SetLevel(log.PanicLevel) log.SetLevel(log.PanicLevel)
} }
...@@ -39,7 +44,7 @@ func testSetupIntegration() { ...@@ -39,7 +44,7 @@ func testSetupIntegration() {
testAddress = a testAddress = a
log.Infof("GOSDN_TEST_ENDPOINT set to %v", testAddress) 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 != "" { if api != "" {
testAPIEndpoint = api testAPIEndpoint = api
log.Infof("GOSDN_TEST_API_ENDPOINT set to %v", testAPIEndpoint) log.Infof("GOSDN_TEST_API_ENDPOINT set to %v", testAPIEndpoint)
...@@ -83,8 +88,6 @@ func testSetupIntegration() { ...@@ -83,8 +88,6 @@ func testSetupIntegration() {
} }
func TestCmdIntegration(t *testing.T) { func TestCmdIntegration(t *testing.T) {
// TDOO: Remove once openshift grpc support is available
t.Skip("skipped due to openshift limitations")
if testing.Short() { if testing.Short() {
t.Skip("skipping integration test") t.Skip("skipping integration test")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment