@@ -28,6 +28,7 @@ import (
2828 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929 "k8s.io/apimachinery/pkg/runtime"
3030 "k8s.io/client-go/kubernetes"
31+ "knative.dev/pkg/apis"
3132 ctrl "sigs.k8s.io/controller-runtime"
3233 "sigs.k8s.io/controller-runtime/pkg/client"
3334 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -152,45 +153,78 @@ func (p *Transformer) Reconcile(ctx context.Context, isvc *v1beta1.InferenceServ
152153
153154 // Here we allow switch between knative and vanilla deployment
154155 if p .deploymentMode == constants .RawDeployment {
155- r , err := raw .NewRawKubeReconciler (ctx , p .client , p .clientset , p .scheme , objectMeta , metav1.ObjectMeta {},
156- & isvc .Spec .Transformer .ComponentExtensionSpec , & podSpec , nil )
157- if err != nil {
158- return ctrl.Result {}, errors .Wrapf (err , "fails to create NewRawKubeReconciler for transformer" )
159- }
160- // set Deployment Controller
161- for _ , deployment := range r .Deployment .DeploymentList {
162- if err := controllerutil .SetControllerReference (isvc , deployment , p .scheme ); err != nil {
163- return ctrl.Result {}, errors .Wrapf (err , "fails to set deployment owner reference for transformer" )
164- }
156+ if err := p .reconcileTransformerRawDeployment (ctx , isvc , & objectMeta , & podSpec ); err != nil {
157+ return ctrl.Result {}, err
165158 }
166- // set Service Controller
167- for _ , svc := range r .Service .ServiceList {
168- if err := controllerutil .SetControllerReference (isvc , svc , p .scheme ); err != nil {
169- return ctrl.Result {}, errors .Wrapf (err , "fails to set service owner reference for transformer" )
170- }
171- }
172- // set autoscaler Controller
173- if err := r .Scaler .Autoscaler .SetControllerReferences (isvc , p .scheme ); err != nil {
174- return ctrl.Result {}, errors .Wrapf (err , "fails to set autoscaler owner references for transformer" )
159+ } else {
160+ if err := p .reconcileTransformerKnativeDeployment (ctx , isvc , & objectMeta , & podSpec ); err != nil {
161+ return ctrl.Result {}, err
175162 }
163+ }
176164
177- deployment , err := r .Reconcile (ctx )
178- if err != nil {
179- return ctrl.Result {}, errors .Wrapf (err , "fails to reconcile transformer" )
165+ if utils .GetForceStopRuntime (isvc ) {
166+ // Exit early if we have already set the transformer's status to stopped
167+ existingTransformerCondition := isvc .Status .GetCondition (v1beta1 .TransformerReady )
168+ if existingTransformerCondition != nil && existingTransformerCondition .Status == corev1 .ConditionFalse && existingTransformerCondition .Reason == v1beta1 .StoppedISVCReason {
169+ return ctrl.Result {}, nil
180170 }
181- isvc .Status .PropagateRawStatus (v1beta1 .TransformerComponent , deployment , r .URL )
182- } else {
183- r := knative .NewKsvcReconciler (p .client , p .scheme , objectMeta , & isvc .Spec .Transformer .ComponentExtensionSpec ,
184- & podSpec , isvc .Status .Components [v1beta1 .TransformerComponent ], p .inferenceServiceConfig .ServiceLabelDisallowedList )
185171
186- if err := controllerutil .SetControllerReference (isvc , r .Service , p .scheme ); err != nil {
187- return ctrl.Result {}, errors .Wrapf (err , "fails to set owner reference for transformer" )
172+ // Set the ready condition to false
173+ isvc .Status .SetCondition (v1beta1 .TransformerReady , & apis.Condition {
174+ Type : v1beta1 .TransformerReady ,
175+ Status : corev1 .ConditionFalse ,
176+ Reason : v1beta1 .StoppedISVCReason ,
177+ })
178+ }
179+ return ctrl.Result {}, nil
180+ }
181+
182+ func (p * Transformer ) reconcileTransformerRawDeployment (ctx context.Context , isvc * v1beta1.InferenceService , objectMeta * metav1.ObjectMeta , podSpec * corev1.PodSpec ) error {
183+ r , err := raw .NewRawKubeReconciler (ctx , p .client , p .clientset , p .scheme , * objectMeta , metav1.ObjectMeta {},
184+ & isvc .Spec .Transformer .ComponentExtensionSpec , podSpec , nil )
185+ if err != nil {
186+ return errors .Wrapf (err , "fails to create NewRawKubeReconciler for transformer" )
187+ }
188+ // set Deployment Controller
189+ for _ , deployment := range r .Deployment .DeploymentList {
190+ if err := controllerutil .SetControllerReference (isvc , deployment , p .scheme ); err != nil {
191+ return errors .Wrapf (err , "fails to set deployment owner reference for transformer" )
188192 }
189- status , err := r .Reconcile (ctx )
190- if err != nil {
191- return ctrl.Result {}, errors .Wrapf (err , "fails to reconcile transformer" )
193+ }
194+ // set Service Controller
195+ for _ , svc := range r .Service .ServiceList {
196+ if err := controllerutil .SetControllerReference (isvc , svc , p .scheme ); err != nil {
197+ return errors .Wrapf (err , "fails to set service owner reference for transformer" )
192198 }
193- isvc .Status .PropagateStatus (v1beta1 .TransformerComponent , status )
194199 }
195- return ctrl.Result {}, nil
200+ // set autoscaler Controller
201+ if err := r .Scaler .Autoscaler .SetControllerReferences (isvc , p .scheme ); err != nil {
202+ return errors .Wrapf (err , "fails to set autoscaler owner references for transformer" )
203+ }
204+
205+ deployment , err := r .Reconcile (ctx )
206+ if err != nil {
207+ return errors .Wrapf (err , "fails to reconcile transformer" )
208+ }
209+ if ! utils .GetForceStopRuntime (isvc ) {
210+ isvc .Status .PropagateRawStatus (v1beta1 .TransformerComponent , deployment , r .URL )
211+ }
212+ return nil
213+ }
214+
215+ func (p * Transformer ) reconcileTransformerKnativeDeployment (ctx context.Context , isvc * v1beta1.InferenceService , objectMeta * metav1.ObjectMeta , podSpec * corev1.PodSpec ) error {
216+ r := knative .NewKsvcReconciler (p .client , p .scheme , * objectMeta , & isvc .Spec .Transformer .ComponentExtensionSpec ,
217+ podSpec , isvc .Status .Components [v1beta1 .TransformerComponent ], p .inferenceServiceConfig .ServiceLabelDisallowedList )
218+
219+ if err := controllerutil .SetControllerReference (isvc , r .Service , p .scheme ); err != nil {
220+ return errors .Wrapf (err , "fails to set owner reference for transformer" )
221+ }
222+ kstatus , err := r .Reconcile (ctx )
223+ if err != nil {
224+ return errors .Wrapf (err , "fails to reconcile transformer" )
225+ }
226+ if ! utils .GetForceStopRuntime (isvc ) {
227+ isvc .Status .PropagateStatus (v1beta1 .TransformerComponent , kstatus )
228+ }
229+ return nil
196230}
0 commit comments