Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: event name & namespace #1969

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/controllers/resources/events/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/loft-sh/vcluster/pkg/mappings/resources"
"github.com/loft-sh/vcluster/pkg/syncer/synccontext"
"github.com/loft-sh/vcluster/pkg/util/translate"

corev1 "k8s.io/api/core/v1"
)

Expand All @@ -19,25 +18,27 @@ func (s *eventSyncer) translateEvent(ctx *synccontext.SyncContext, pEvent, vEven
tempEvent := pEvent.DeepCopy()

// set the correct involved object meta
tempEvent.Namespace = involvedObject.GetNamespace()
tempEvent.InvolvedObject.Namespace = involvedObject.GetNamespace()
tempEvent.InvolvedObject.Name = involvedObject.GetName()
tempEvent.InvolvedObject.UID = involvedObject.GetUID()
tempEvent.InvolvedObject.ResourceVersion = involvedObject.GetResourceVersion()

// rewrite name
tempEvent.Name = hostEventNameToVirtual(vEvent.Name, pEvent.InvolvedObject.Name, vEvent.InvolvedObject.Name)
namespace := involvedObject.GetNamespace()
name := hostEventNameToVirtual(vEvent.Name, pEvent.InvolvedObject.Name, vEvent.InvolvedObject.Name)

// we replace namespace/name & name in messages so that it seems correct
tempEvent.Message = strings.ReplaceAll(tempEvent.Message, pEvent.InvolvedObject.Namespace+"/"+pEvent.InvolvedObject.Name, tempEvent.InvolvedObject.Namespace+"/"+tempEvent.InvolvedObject.Name)
tempEvent.Message = strings.ReplaceAll(tempEvent.Message, pEvent.InvolvedObject.Name, tempEvent.InvolvedObject.Name)

translate.ResetObjectMetadata(tempEvent)
// keep the metadata from the virtual object
translate.ResetObjectMetadata(tempEvent)
tempEvent.ObjectMeta = vEvent.ObjectMeta
tempEvent.TypeMeta = vEvent.TypeMeta

tempEvent.DeepCopyInto(vEvent)
vEvent.Namespace = namespace
vEvent.Name = name
return nil
}

Expand Down
Loading