Skip to content

Commit edb683c

Browse files
committed
config for tests
1 parent 5b74b42 commit edb683c

File tree

4 files changed

+109
-11
lines changed

4 files changed

+109
-11
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"namespace": "seldon-mesh",
3+
"log_level": "debug",
4+
"skip_cleanup" : false,
5+
"inference" : {
6+
"host": "localhost",
7+
"httpPort": 9000,
8+
"grpcPort": 9000,
9+
"ssl": false
10+
}
11+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright (c) 2024 Seldon Technologies Ltd.
3+
4+
Use of this software is governed BY
5+
(1) the license included in the LICENSE file or
6+
(2) if the license included in the LICENSE file is the Business Source License 1.1,
7+
the Change License after the Change Date as each is defined in accordance with the LICENSE file.
8+
*/
9+
10+
package scenario
11+
12+
import (
13+
"encoding/json"
14+
"fmt"
15+
"os"
16+
)
17+
18+
type GodogConfig struct {
19+
Namespace string `json:"namespace"`
20+
LogLevel string `json:"log_level"`
21+
SkipCleanup bool `json:"skip_cleanup"`
22+
Inference Inference `json:"inference"`
23+
}
24+
25+
type Inference struct {
26+
Host string `json:"host"`
27+
HTTPPort uint `json:"httpPort"`
28+
GRPCPort uint `json:"grpcPort"`
29+
SSL bool `json:"ssl"`
30+
}
31+
32+
func LoadConfig() (*GodogConfig, error) {
33+
configFile := os.Getenv("GODOG_CONFIG_FILE")
34+
if configFile == "" {
35+
configFile = "./godog-config.json"
36+
}
37+
38+
if _, err := os.Stat(configFile); err != nil {
39+
if os.IsNotExist(err) {
40+
return nil, fmt.Errorf("config file not found: %s", configFile)
41+
}
42+
return nil, fmt.Errorf("failed to open config file %s: %w", configFile, err)
43+
}
44+
45+
data, err := os.ReadFile(configFile)
46+
if err != nil {
47+
return nil, fmt.Errorf("failed to read config file %s: %w", configFile, err)
48+
}
49+
50+
var config GodogConfig
51+
if err := json.Unmarshal(data, &config); err != nil {
52+
return nil, fmt.Errorf("failed to parse config file %s: %w", configFile, err)
53+
}
54+
55+
return &config, nil
56+
}

tests/integration/godog/scenario/scenario.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
type SuiteDeps struct {
2323
K8sClient *k8sclient.K8sClient
2424
WatcherStore k8sclient.WatcherStorage
25+
Config *GodogConfig
2526
}
2627

2728
// might have to pass the suit struct and other config with closures to avoid having global vars
@@ -55,19 +56,26 @@ var suiteDeps SuiteDeps
5556
// it will deploy into the default server capability that might be in our server dpeloyment def
5657

5758
func InitializeTestSuite(ctx *godog.TestSuiteContext) {
59+
// Load configuration from JSON file
60+
config, err := LoadConfig()
61+
if err != nil {
62+
panic(fmt.Errorf("failed to load config: %w", err))
63+
}
64+
5865
// Create long-lived deps here
59-
k8sClient, err := k8sclient.New("seldon-mesh")
66+
k8sClient, err := k8sclient.New(config.Namespace)
6067
if err != nil {
6168
panic(fmt.Errorf("failed to create k8s client: %w", err))
6269
}
6370

64-
watchStore, err := k8sclient.NewWatcherStore("seldon-mesh", k8sclient.CRDLabels, k8sClient.KubeClient)
71+
watchStore, err := k8sclient.NewWatcherStore(config.Namespace, k8sclient.CRDLabels, k8sClient.KubeClient)
6572
if err != nil {
6673
panic(fmt.Errorf("failed to create k8s watch store: %w", err))
6774
}
6875

6976
suiteDeps.K8sClient = k8sClient
7077
suiteDeps.WatcherStore = watchStore
78+
suiteDeps.Config = config
7179

7280
ctx.BeforeSuite(func() {
7381
suiteDeps.WatcherStore.Start()
@@ -81,16 +89,25 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {
8189
}
8290

8391
func InitializeScenario(scenarioCtx *godog.ScenarioContext) {
92+
log := logrus.New()
93+
if suiteDeps.Config.LogLevel != "" {
94+
logLevel, err := logrus.ParseLevel(suiteDeps.Config.LogLevel)
95+
if err != nil {
96+
panic(fmt.Errorf("failed to parse log level %s: %w", logLevel, err))
97+
}
98+
log.SetLevel(logLevel)
99+
}
100+
84101
// Create the world with long-lived deps once per scenario context
85102
world, err := steps.NewWorld(steps.Config{
86-
Namespace: "seldon-mesh", //TODO configurable
87-
Logger: logrus.New().WithField("test_type", "godog"),
103+
Namespace: suiteDeps.Config.Namespace,
104+
Logger: log.WithField("test_type", "godog"),
88105
KubeClient: suiteDeps.K8sClient,
89106
WatcherStorage: suiteDeps.WatcherStore,
90-
IngressHost: "localhost", //TODO configurable
91-
HTTPPort: 9000, //TODO configurable
92-
GRPCPort: 9000, //TODO configurable
93-
SSL: false, //TODO configurable
107+
IngressHost: suiteDeps.Config.Inference.Host,
108+
HTTPPort: suiteDeps.Config.Inference.HTTPPort,
109+
GRPCPort: suiteDeps.Config.Inference.GRPCPort,
110+
SSL: suiteDeps.Config.Inference.SSL,
94111
})
95112
if err != nil {
96113
panic(fmt.Errorf("failed to create world: %w", err))
@@ -118,6 +135,13 @@ func InitializeScenario(scenarioCtx *godog.ScenarioContext) {
118135
// if cleanupErr := world.KubeClient.DeleteGodogTestModels(); cleanupErr != nil && err == nil {
119136
// err = cleanupErr
120137
// }
138+
139+
if suiteDeps.Config.SkipCleanup {
140+
log.WithField("scenario", scenario.Name).Debug("Skipping cleanup")
141+
return ctx, nil
142+
}
143+
144+
// TODO clean up
121145
return ctx, err
122146
})
123147

@@ -126,5 +150,4 @@ func InitializeScenario(scenarioCtx *godog.ScenarioContext) {
126150
steps.LoadExplicitModelSteps(scenarioCtx, world)
127151
steps.LoadInferenceSteps(scenarioCtx, world)
128152
// TODO: load other steps, e.g. pipeline, experiment, etc.
129-
130153
}

tests/integration/godog/steps/world.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ the Change License after the Change Date as each is defined in accordance with t
1010
package steps
1111

1212
import (
13+
"crypto/tls"
1314
"fmt"
1415
"net/http"
1516

1617
"github.com/seldonio/seldon-core/apis/go/v2/mlops/v2_dataplane"
1718
"github.com/seldonio/seldon-core/tests/integration/godog/k8sclient"
1819
"github.com/sirupsen/logrus"
1920
"google.golang.org/grpc"
21+
"google.golang.org/grpc/credentials"
2022
"google.golang.org/grpc/credentials/insecure"
2123
)
2224

@@ -54,9 +56,15 @@ type inference struct {
5456
}
5557

5658
func NewWorld(c Config) (*World, error) {
57-
// TODO TLS for gRPC when c.SSL == true
59+
creds := insecure.NewCredentials()
60+
if c.SSL {
61+
creds = credentials.NewTLS(&tls.Config{
62+
InsecureSkipVerify: true,
63+
})
64+
}
65+
5866
opts := []grpc.DialOption{
59-
grpc.WithTransportCredentials(insecure.NewCredentials()),
67+
grpc.WithTransportCredentials(creds),
6068
}
6169

6270
conn, err := grpc.NewClient(fmt.Sprintf("%s:%d", c.IngressHost, c.GRPCPort), opts...)

0 commit comments

Comments
 (0)