Skip to content

Commit f528d19

Browse files
authored
config for tests (#6994)
1 parent d8d3a0e commit f528d19

File tree

4 files changed

+106
-11
lines changed

4 files changed

+106
-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: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type SuiteDeps struct {
2525
k8sClient *k8sclient.K8sClient
2626
mlopsClient *v.Clientset
2727
watcherStore k8sclient.WatcherStorage
28+
Config *GodogConfig
2829
}
2930

3031
// might have to pass the suit struct and other config with closures to avoid having global vars
@@ -46,9 +47,14 @@ var suiteDeps SuiteDeps
4647

4748
func InitializeTestSuite(ctx *godog.TestSuiteContext) {
4849
// todo: we should bootstrap config here
50+
// Load configuration from JSON file
51+
config, err := LoadConfig()
52+
if err != nil {
53+
panic(fmt.Errorf("failed to load config: %w", err))
54+
}
4955

5056
// Create long-lived deps here
51-
k8sClient, err := k8sclient.New("seldon-mesh")
57+
k8sClient, err := k8sclient.New(config.Namespace)
5258
if err != nil {
5359
panic(fmt.Errorf("failed to create k8s client: %w", err))
5460
}
@@ -58,14 +64,15 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {
5864
panic(fmt.Errorf("failed to mlops client: %w", err))
5965
}
6066

61-
watchStore, err := k8sclient.NewWatcherStore("seldon-mesh", k8sclient.DefaultCRDLabel, clientSet.MlopsV1alpha1())
67+
watchStore, err := k8sclient.NewWatcherStore(config.Namespace, k8sclient.DefaultCRDLabel, clientSet.MlopsV1alpha1())
6268
if err != nil {
6369
panic(fmt.Errorf("failed to create k8s watch store: %w", err))
6470
}
6571

6672
suiteDeps.k8sClient = k8sClient
6773
suiteDeps.mlopsClient = clientSet // todo: this clientSet might get use for get requests or for the mlops interface and could be passed to the world might be split up by type
6874
suiteDeps.watcherStore = watchStore
75+
suiteDeps.Config = config
6976

7077
ctx.BeforeSuite(func() {
7178
suiteDeps.watcherStore.Start()
@@ -79,16 +86,25 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {
7986
}
8087

8188
func InitializeScenario(scenarioCtx *godog.ScenarioContext) {
89+
log := logrus.New()
90+
if suiteDeps.Config.LogLevel != "" {
91+
logLevel, err := logrus.ParseLevel(suiteDeps.Config.LogLevel)
92+
if err != nil {
93+
panic(fmt.Errorf("failed to parse log level %s: %w", logLevel, err))
94+
}
95+
log.SetLevel(logLevel)
96+
}
97+
8298
// Create the world with long-lived deps once per scenario context
8399
world, err := steps.NewWorld(steps.Config{
84-
Namespace: "seldon-mesh", //TODO configurable
85-
Logger: logrus.New().WithField("test_type", "godog"),
100+
Namespace: suiteDeps.Config.Namespace,
101+
Logger: log.WithField("test_type", "godog"),
86102
KubeClient: suiteDeps.k8sClient,
87103
WatcherStorage: suiteDeps.watcherStore,
88-
IngressHost: "localhost", //TODO configurable
89-
HTTPPort: 9000, //TODO configurable
90-
GRPCPort: 9000, //TODO configurable
91-
SSL: false, //TODO configurable
104+
IngressHost: suiteDeps.Config.Inference.Host,
105+
HTTPPort: suiteDeps.Config.Inference.HTTPPort,
106+
GRPCPort: suiteDeps.Config.Inference.GRPCPort,
107+
SSL: suiteDeps.Config.Inference.SSL,
92108
})
93109
if err != nil {
94110
panic(fmt.Errorf("failed to create world: %w", err))
@@ -107,6 +123,11 @@ func InitializeScenario(scenarioCtx *godog.ScenarioContext) {
107123

108124
// After: optional cleanup / rollback
109125
scenarioCtx.After(func(ctx context.Context, scenario *godog.Scenario, err error) (context.Context, error) {
126+
if suiteDeps.Config.SkipCleanup {
127+
log.WithField("scenario", scenario.Name).Debug("Skipping cleanup")
128+
return ctx, nil
129+
}
130+
110131
if err := world.KubeClient.DeleteScenarioResources(ctx, world.Label); err != nil {
111132
return ctx, fmt.Errorf("error when deleting models on before steps: %w", err)
112133
}
@@ -119,5 +140,4 @@ func InitializeScenario(scenarioCtx *godog.ScenarioContext) {
119140
steps.LoadExplicitModelSteps(scenarioCtx, world)
120141
steps.LoadInferenceSteps(scenarioCtx, world)
121142
// TODO: load other steps, e.g. pipeline, experiment, etc.
122-
123143
}

tests/integration/godog/steps/world.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ 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

@@ -18,6 +19,7 @@ import (
1819
"github.com/seldonio/seldon-core/tests/integration/godog/k8sclient"
1920
"github.com/sirupsen/logrus"
2021
"google.golang.org/grpc"
22+
"google.golang.org/grpc/credentials"
2123
"google.golang.org/grpc/credentials/insecure"
2224
)
2325

@@ -57,9 +59,15 @@ type inference struct {
5759
}
5860

5961
func NewWorld(c Config) (*World, error) {
60-
// TODO TLS for gRPC when c.SSL == true
62+
creds := insecure.NewCredentials()
63+
if c.SSL {
64+
creds = credentials.NewTLS(&tls.Config{
65+
InsecureSkipVerify: true,
66+
})
67+
}
68+
6169
opts := []grpc.DialOption{
62-
grpc.WithTransportCredentials(insecure.NewCredentials()),
70+
grpc.WithTransportCredentials(creds),
6371
}
6472

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

0 commit comments

Comments
 (0)