@@ -14,14 +14,17 @@ import (
1414 "fmt"
1515
1616 "github.com/cucumber/godog"
17+ v "github.com/seldonio/seldon-core/operator/v2/pkg/generated/clientset/versioned"
1718 "github.com/seldonio/seldon-core/tests/integration/godog/k8sclient"
1819 "github.com/seldonio/seldon-core/tests/integration/godog/steps"
1920 "github.com/sirupsen/logrus"
21+ controllerruntime "sigs.k8s.io/controller-runtime"
2022)
2123
2224type SuiteDeps struct {
23- K8sClient * k8sclient.K8sClient
24- WatcherStore k8sclient.WatcherStorage
25+ k8sClient * k8sclient.K8sClient
26+ mlopsClient * v.Clientset
27+ watcherStore k8sclient.WatcherStorage
2528}
2629
2730// might have to pass the suit struct and other config with closures to avoid having global vars
@@ -41,41 +44,36 @@ type SuiteDeps struct {
4144// }
4245var suiteDeps SuiteDeps
4346
44- // todo: think about how we can drive server config from a file
45- // - have a default server for test
46- // - but also have the posibility of specifying the servers deployed in the test suite
47-
48- // we create a server config or multiple servers
49- // server 1 caps mlserver
50- // default modelCapDeployment = mlserver
51-
52- // we can set the default model capabilities for models
53-
54- // if we have an scenario and it doesn't specify the server capabilities that it is deployed to
55- // it will deploy into the default server capability that might be in our server dpeloyment def
56-
5747func InitializeTestSuite (ctx * godog.TestSuiteContext ) {
48+ // todo: we should bootstrap config here
49+
5850 // Create long-lived deps here
5951 k8sClient , err := k8sclient .New ("seldon-mesh" )
6052 if err != nil {
6153 panic (fmt .Errorf ("failed to create k8s client: %w" , err ))
6254 }
6355
64- watchStore , err := k8sclient .NewWatcherStore ("seldon-mesh" , k8sclient .CRDLabels , k8sClient .KubeClient )
56+ clientSet , err := v .NewForConfig (controllerruntime .GetConfigOrDie ())
57+ if err != nil {
58+ panic (fmt .Errorf ("failed to mlops client: %w" , err ))
59+ }
60+
61+ watchStore , err := k8sclient .NewWatcherStore ("seldon-mesh" , k8sclient .DefaultCRDLabel , clientSet .MlopsV1alpha1 ())
6562 if err != nil {
6663 panic (fmt .Errorf ("failed to create k8s watch store: %w" , err ))
6764 }
6865
69- suiteDeps .K8sClient = k8sClient
70- suiteDeps .WatcherStore = watchStore
66+ suiteDeps .k8sClient = k8sClient
67+ 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
68+ suiteDeps .watcherStore = watchStore
7169
7270 ctx .BeforeSuite (func () {
73- suiteDeps .WatcherStore .Start ()
71+ suiteDeps .watcherStore .Start ()
7472 // e.g. create namespace, apply CRDs, etc.
7573 })
7674
7775 ctx .AfterSuite (func () {
78- suiteDeps .WatcherStore .Stop ()
76+ suiteDeps .watcherStore .Stop ()
7977 // e.g. clean namespace, close clients if needed
8078 })
8179}
@@ -85,8 +83,8 @@ func InitializeScenario(scenarioCtx *godog.ScenarioContext) {
8583 world , err := steps .NewWorld (steps.Config {
8684 Namespace : "seldon-mesh" , //TODO configurable
8785 Logger : logrus .New ().WithField ("test_type" , "godog" ),
88- KubeClient : suiteDeps .K8sClient ,
89- WatcherStorage : suiteDeps .WatcherStore ,
86+ KubeClient : suiteDeps .k8sClient ,
87+ WatcherStorage : suiteDeps .watcherStore ,
9088 IngressHost : "localhost" , //TODO configurable
9189 HTTPPort : 9000 , //TODO configurable
9290 GRPCPort : 9000 , //TODO configurable
@@ -100,11 +98,6 @@ func InitializeScenario(scenarioCtx *godog.ScenarioContext) {
10098
10199 // Before: reset state and prep cluster before each scenario
102100 scenarioCtx .Before (func (ctx context.Context , scenario * godog.Scenario ) (context.Context , error ) {
103- if err := world .KubeClient .DeleteGodogTestModels (ctx ); err != nil {
104- return ctx , fmt .Errorf ("error when deleting models on before steps: %w" , err )
105- }
106-
107- // Create a fresh model for THIS scenario
108101 world .CurrentModel .Reset (world )
109102
110103 // Reset scenario-level state
@@ -114,10 +107,10 @@ func InitializeScenario(scenarioCtx *godog.ScenarioContext) {
114107
115108 // After: optional cleanup / rollback
116109 scenarioCtx .After (func (ctx context.Context , scenario * godog.Scenario , err error ) (context.Context , error ) {
117- // e.g. clean up any resources if needed
118- // if cleanupErr := world.KubeClient.DeleteGodogTestModels(); cleanupErr != nil && err == nil {
119- // err = cleanupErr
120- // }
110+ if err := world . KubeClient . DeleteScenarioResources ( ctx , world . Label ); err != nil {
111+ return ctx , fmt . Errorf ( "error when deleting models on before steps: %w" , err )
112+ }
113+
121114 return ctx , err
122115 })
123116
0 commit comments