Skip to content

Commit b6a8ef3

Browse files
committed
Remove redundant logic
1 parent 8235814 commit b6a8ef3

File tree

1 file changed

+1
-59
lines changed

1 file changed

+1
-59
lines changed

controllers/deployment.go

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ package controllers
22

33
import (
44
"context"
5+
templateParser "github.com/trustyai-explainability/trustyai-service-operator/controllers/templates"
56
"reflect"
6-
"sigs.k8s.io/controller-runtime/pkg/client"
77
"strconv"
8-
"time"
9-
10-
templateParser "github.com/trustyai-explainability/trustyai-service-operator/controllers/templates"
118

129
trustyaiopendatahubiov1alpha1 "github.com/trustyai-explainability/trustyai-service-operator/api/v1alpha1"
1310
appsv1 "k8s.io/api/apps/v1"
@@ -210,58 +207,3 @@ func (r *TrustyAIServiceReconciler) checkDeploymentReady(ctx context.Context, in
210207

211208
return false, nil
212209
}
213-
214-
func (r *TrustyAIServiceReconciler) scaleDeployment(ctx context.Context, instance *trustyaiopendatahubiov1alpha1.TrustyAIService, replicas int32) error {
215-
deployment := &appsv1.Deployment{}
216-
err := r.Get(ctx, types.NamespacedName{Name: instance.Name, Namespace: instance.Namespace}, deployment)
217-
if err != nil {
218-
return err
219-
}
220-
deployment.Spec.Replicas = &replicas
221-
return r.Update(ctx, deployment)
222-
}
223-
224-
func (r *TrustyAIServiceReconciler) waitForTermination(ctx context.Context, instance *trustyaiopendatahubiov1alpha1.TrustyAIService) error {
225-
for {
226-
select {
227-
case <-ctx.Done():
228-
return ctx.Err()
229-
default:
230-
podList := &corev1.PodList{}
231-
opts := []client.ListOption{
232-
client.InNamespace(instance.Name),
233-
client.MatchingLabels{"app": instance.Name},
234-
}
235-
err := r.List(ctx, podList, opts...)
236-
if err != nil {
237-
return err
238-
}
239-
if len(podList.Items) == 0 {
240-
return nil
241-
}
242-
time.Sleep(2 * time.Second)
243-
}
244-
}
245-
}
246-
247-
func (r *TrustyAIServiceReconciler) redeployForMigration(ctx context.Context, instance *trustyaiopendatahubiov1alpha1.TrustyAIService) error {
248-
log.FromContext(ctx).Info("Scaling down to zero replicas")
249-
err := r.scaleDeployment(ctx, instance, 0)
250-
if err != nil {
251-
return err
252-
}
253-
254-
log.FromContext(ctx).Info("Waiting for deployment to scale down to zero replicas")
255-
err = r.waitForTermination(ctx, instance)
256-
if err != nil {
257-
return err
258-
}
259-
260-
log.FromContext(ctx).Info("Scaling up")
261-
err = r.scaleDeployment(ctx, instance, 1)
262-
if err != nil {
263-
return err
264-
}
265-
266-
return nil
267-
}

0 commit comments

Comments
 (0)