@@ -18,10 +18,12 @@ package inference
1818
1919import (
2020 "context"
21+ "fmt"
2122
2223 "github.com/onsi/ginkgo/v2"
2324 "github.com/onsi/gomega"
2425 corev1 "k8s.io/api/core/v1"
26+ apierrors "k8s.io/apimachinery/pkg/api/errors"
2527 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2628 "k8s.io/apimachinery/pkg/types"
2729 "k8s.io/utils/ptr"
@@ -155,5 +157,56 @@ var _ = ginkgo.Describe("playground controller test", func() {
155157 },
156158 },
157159 }),
160+ ginkgo .Entry ("create the model after playground is created" , & testValidatingCase {
161+ makePlayground : func () * inferenceapi.Playground {
162+ return util .MockASamplePlayground (ns .Name )
163+ },
164+ updates : []* update {
165+ {
166+ // Delete the pre-provision model before creating playground.
167+ playgroundUpdateFn : func (_ * inferenceapi.Playground ) {
168+ gomega .Expect (k8sClient .Delete (ctx , model )).To (gomega .Succeed ())
169+ // To make sure model not exists.
170+ gomega .Eventually (func () error {
171+ oldModel := & coreapi.OpenModel {}
172+ if err := k8sClient .Get (ctx , types.NamespacedName {Name : model .Name , Namespace : model .Namespace }, oldModel ); err != nil {
173+ if apierrors .IsNotFound (err ) {
174+ return nil
175+ }
176+ return err
177+ }
178+ return fmt .Errorf ("model %s/%s still exists" , model .Namespace , model .Name )
179+ }, util .IntegrationTimeout , util .Interval ).Should (gomega .Succeed ())
180+ },
181+ },
182+ { // Create the playground when the model not exists.
183+ playgroundUpdateFn : func (playground * inferenceapi.Playground ) {
184+ gomega .Expect (k8sClient .Create (ctx , playground )).To (gomega .Succeed ())
185+ },
186+ checkPlayground : func (ctx context.Context , k8sClient client.Client , playground * inferenceapi.Playground ) {
187+ validation .ValidatePlayground (ctx , k8sClient , playground )
188+ gomega .Consistently (func () error {
189+ updatePlayground := inferenceapi.Playground {}
190+ if err := k8sClient .Get (ctx , types.NamespacedName {Name : playground .Name , Namespace : playground .Namespace }, & updatePlayground ); err != nil {
191+ return err
192+ }
193+ if len (updatePlayground .Status .Conditions ) != 0 {
194+ return fmt .Errorf ("playground status conditions should be empty, got %v" , updatePlayground .Status .Conditions )
195+ }
196+ return nil
197+ }, 3 * util .Interval , util .Interval ).Should (gomega .Succeed ())
198+ },
199+ },
200+ {
201+ // create the model after playground is created.
202+ playgroundUpdateFn : func (_ * inferenceapi.Playground ) {
203+ gomega .Expect (k8sClient .Create (ctx , model )).To (gomega .Succeed ())
204+ },
205+ checkPlayground : func (ctx context.Context , k8sClient client.Client , playground * inferenceapi.Playground ) {
206+ validation .ValidatePlaygroundStatusEqualTo (ctx , k8sClient , playground , inferenceapi .PlaygroundAvailable , "PlaygroundReady" , metav1 .ConditionTrue )
207+ },
208+ },
209+ },
210+ }),
158211 )
159212})
0 commit comments