Skip to content

Commit

Permalink
update: finalizer changes | clean up fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ramantehlan committed Jun 6, 2024
1 parent 5eebffb commit 1c600ad
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
13 changes: 8 additions & 5 deletions operator/internal/controller/elastiservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,10 @@ func (r *ElastiServiceReconciler) Reconcile(ctx context.Context, req ctrl.Reques

if !es.ObjectMeta.DeletionTimestamp.IsZero() {
if controllerutil.ContainsFinalizer(es, v1alpha1.ElastiServiceFinalizer) {
r.Logger.Info("ElastiService is being deleted", zap.String("name", es.Name), zap.Any("deletionTimestamp", es.ObjectMeta.DeletionTimestamp))
go r.Watcher.StopInformer(es.Spec.DeploymentName, req.Namespace)
if err = r.cleanUp(ctx, es); err != nil {
if err = r.finalizeElastiService(ctx, es); err != nil {
r.Logger.Error("Failed to server mode", zap.Error(err))
return res, err
}
r.Logger.Info("Serve mode enabled")
controllerutil.RemoveFinalizer(es, v1alpha1.ElastiServiceFinalizer)
if err := r.Update(ctx, es); err != nil {
return res, err
Expand Down Expand Up @@ -225,7 +222,12 @@ func (r *ElastiServiceReconciler) enableServeMode(ctx context.Context, es *v1alp
return nil
}

func (r *ElastiServiceReconciler) cleanUp(ctx context.Context, es *v1alpha1.ElastiService) error {
func (r *ElastiServiceReconciler) finalizeElastiService(ctx context.Context, es *v1alpha1.ElastiService) error {
r.Logger.Info("ElastiService is being deleted", zap.String("name", es.Name), zap.Any("deletionTimestamp", es.ObjectMeta.DeletionTimestamp))
// Stop target service informer
go r.Watcher.StopInformer(es.Spec.DeploymentName, es.Namespace)
// Stop resolver informer
go r.Watcher.StopInformer(resolverDeploymentName, resolverNamespace)
targetNamespacedName := types.NamespacedName{
Name: es.Spec.Service,
Namespace: es.Namespace,
Expand All @@ -236,6 +238,7 @@ func (r *ElastiServiceReconciler) cleanUp(ctx context.Context, es *v1alpha1.Elas
if err := r.DeletePrivateService(ctx, targetNamespacedName); err != nil {
return err
}
r.Logger.Info("Serve mode enabled")
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions operator/internal/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ func (r *ElastiServiceReconciler) CreateOrUpdateEndpointsliceToResolver(ctx cont
r.Logger.Error("failed to update sliceToResolver", zap.Any("namespacedName", EndpointsliceNamespacedName), zap.Error(err))
return err
}
r.Logger.Info("EndpointSlice updated successfully", zap.Any("namespacedName", EndpointsliceNamespacedName))
} else {
if err := r.Create(ctx, newEndpointSlice); err != nil {
r.Logger.Error("failed to create sliceToResolver", zap.Any("namespacedName", EndpointsliceNamespacedName), zap.Error(err))
return err
}
r.Logger.Info("EndpointSlice created successfully", zap.Any("namespacedName", EndpointsliceNamespacedName))
}

return nil
Expand Down
8 changes: 0 additions & 8 deletions operator/temp.py

This file was deleted.

2 changes: 1 addition & 1 deletion resolver/config/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
namespace: elasti
spec:
selector:
app: resolver
app: elasti-resolver
ports:
- name: http-playground
protocol: TCP
Expand Down

0 comments on commit 1c600ad

Please sign in to comment.