From fd60c85546f37d7174bd2a938778a440916f215a Mon Sep 17 00:00:00 2001 From: Jort Koopmans Date: Fri, 30 Aug 2024 18:27:16 +0200 Subject: [PATCH] Sync namespace for Event to the Application namespace (#847) Signed-off-by: Jort Koopmans --- pkg/kube/kubernetes.go | 6 +++--- pkg/kube/kubernetes_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/kube/kubernetes.go b/pkg/kube/kubernetes.go index 3ec66cfd..11583314 100644 --- a/pkg/kube/kubernetes.go +++ b/pkg/kube/kubernetes.go @@ -96,14 +96,14 @@ func (client *KubernetesClient) GetSecretField(namespace string, secretName stri } } -// CreateApplicationevent creates a kubernetes event with a custom reason and message for an application. +// CreateApplicationEvent creates a kubernetes event with a custom reason and message for an application. func (client *KubernetesClient) CreateApplicationEvent(app *appv1alpha1.Application, reason string, message string, annotations map[string]string) (*v1.Event, error) { t := metav1.Time{Time: time.Now()} event := v1.Event{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%v.%x", app.ObjectMeta.Name, t.UnixNano()), - Namespace: client.Namespace, + Namespace: app.ObjectMeta.Namespace, Annotations: annotations, }, Source: v1.EventSource{ @@ -125,7 +125,7 @@ func (client *KubernetesClient) CreateApplicationEvent(app *appv1alpha1.Applicat Reason: reason, } - result, err := client.Clientset.CoreV1().Events(client.Namespace).Create(client.Context, &event, metav1.CreateOptions{}) + result, err := client.Clientset.CoreV1().Events(app.ObjectMeta.Namespace).Create(client.Context, &event, metav1.CreateOptions{}) if err != nil { return nil, err } diff --git a/pkg/kube/kubernetes_test.go b/pkg/kube/kubernetes_test.go index 56ca6204..35d69223 100644 --- a/pkg/kube/kubernetes_test.go +++ b/pkg/kube/kubernetes_test.go @@ -93,6 +93,6 @@ func Test_CreateApplicationEvent(t *testing.T) { require.NoError(t, err) require.NotNil(t, event) assert.Equal(t, "ArgocdImageUpdater", event.Source.Component) - assert.Equal(t, "default", client.Namespace) + assert.Equal(t, "argocd", event.Namespace) }) }