@@ -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,53 @@ 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+ playgroundUpdateFn : func (playground * inferenceapi.Playground ) {
167+ // Delete the pre-provision model before creating 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+ gomega .Expect (k8sClient .Create (ctx , playground )).To (gomega .Succeed ())
182+ },
183+ checkPlayground : func (ctx context.Context , k8sClient client.Client , playground * inferenceapi.Playground ) {
184+ validation .ValidatePlayground (ctx , k8sClient , playground )
185+ gomega .Consistently (func () error {
186+ updatePlayground := inferenceapi.Playground {}
187+ if err := k8sClient .Get (ctx , types.NamespacedName {Name : playground .Name , Namespace : playground .Namespace }, & updatePlayground ); err != nil {
188+ return err
189+ }
190+ if len (updatePlayground .Status .Conditions ) != 0 {
191+ return fmt .Errorf ("playground status conditions should be empty, got %v" , updatePlayground .Status .Conditions )
192+ }
193+ return nil
194+ }, 3 * util .Interval , util .Interval ).Should (gomega .Succeed ())
195+ },
196+ },
197+ {
198+ // create the model after playground is created.
199+ playgroundUpdateFn : func (_ * inferenceapi.Playground ) {
200+ gomega .Expect (k8sClient .Create (ctx , model )).To (gomega .Succeed ())
201+ },
202+ checkPlayground : func (ctx context.Context , k8sClient client.Client , playground * inferenceapi.Playground ) {
203+ validation .ValidatePlaygroundStatusEqualTo (ctx , k8sClient , playground , inferenceapi .PlaygroundAvailable , "PlaygroundReady" , metav1 .ConditionTrue )
204+ },
205+ },
206+ },
207+ }),
158208 )
159209})
0 commit comments