Skip to content

Commit

Permalink
Remove the ServiceBlockDeletion Annotation once the virtual service e…
Browse files Browse the repository at this point in the history
…xists
  • Loading branch information
neogopher authored and cbron committed Jan 30, 2025
1 parent a62e8f5 commit 647ea88
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/controllers/resources/services/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func (s *serviceSyncer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.
// created, because vcluster intercepts those calls and first creates a service inside the host
// cluster and then inside the virtual cluster.
pService := pObj.(*corev1.Service)
if pService.Annotations != nil && pService.Annotations[ServiceBlockDeletion] == "true" {
return ctrl.Result{Requeue: true}, nil
if pService.Annotations != nil && pService.Annotations[ServiceBlockDeletion] == "true" && time.Since(pService.CreationTimestamp.Time) < 2*time.Minute {
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
}

return syncer.DeleteObject(ctx, pObj, "virtual object was deleted")
Expand Down
5 changes: 2 additions & 3 deletions pkg/controllers/resources/services/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ func (s *serviceSyncer) translateUpdate(ctx context.Context, pObj, vObj *corev1.
// check annotations
_, updatedAnnotations, updatedLabels := s.TranslateMetadataUpdate(ctx, vObj, pObj)
// remove the ServiceBlockDeletion annotation if it's not needed
if vObj.Spec.ClusterIP == pObj.Spec.ClusterIP {
delete(updatedAnnotations, ServiceBlockDeletion)
}
delete(updatedAnnotations, ServiceBlockDeletion)

if !equality.Semantic.DeepEqual(updatedAnnotations, pObj.Annotations) || !equality.Semantic.DeepEqual(updatedLabels, pObj.Labels) {
updated = translator.NewIfNil(updated, pObj)
updated.Annotations = updatedAnnotations
Expand Down

0 comments on commit 647ea88

Please sign in to comment.