Skip to content

Commit 5990a9b

Browse files
authored
feat: Sync namespace for Event to the Application namespace (#847) (#848)
Signed-off-by: Jort Koopmans <[email protected]>
1 parent d829685 commit 5990a9b

File tree

7 files changed

+62
-11
lines changed

7 files changed

+62
-11
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: argocd-image-updater
6+
app.kubernetes.io/part-of: argocd-image-updater
7+
app.kubernetes.io/component: controller
8+
name: argocd-image-updater
9+
rules:
10+
- apiGroups:
11+
- ""
12+
resources:
13+
- events
14+
verbs:
15+
- create
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRoleBinding
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: argocd-image-updater
6+
app.kubernetes.io/part-of: argocd-image-updater
7+
app.kubernetes.io/component: controller
8+
name: argocd-image-updater
9+
roleRef:
10+
apiGroup: rbac.authorization.k8s.io
11+
kind: ClusterRole
12+
name: argocd-image-updater
13+
subjects:
14+
- kind: ServiceAccount
15+
name: argocd-image-updater

manifests/base/rbac/argocd-image-updater-role.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,3 @@ rules:
2525
- list
2626
- update
2727
- patch
28-
- apiGroups:
29-
- ""
30-
resources:
31-
- events
32-
verbs:
33-
- create
34-

manifests/base/rbac/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33

44
resources:
5+
- argocd-image-updater-clusterrole.yaml
6+
- argocd-image-updater-clusterrolebinding.yaml
57
- argocd-image-updater-role.yaml
68
- argocd-image-updater-rolebinding.yaml
79
- argocd-image-updater-sa.yaml

manifests/install.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ rules:
3434
- list
3535
- update
3636
- patch
37+
---
38+
apiVersion: rbac.authorization.k8s.io/v1
39+
kind: ClusterRole
40+
metadata:
41+
labels:
42+
app.kubernetes.io/component: controller
43+
app.kubernetes.io/name: argocd-image-updater
44+
app.kubernetes.io/part-of: argocd-image-updater
45+
name: argocd-image-updater
46+
rules:
3747
- apiGroups:
3848
- ""
3949
resources:
@@ -57,6 +67,22 @@ subjects:
5767
- kind: ServiceAccount
5868
name: argocd-image-updater
5969
---
70+
apiVersion: rbac.authorization.k8s.io/v1
71+
kind: ClusterRoleBinding
72+
metadata:
73+
labels:
74+
app.kubernetes.io/component: controller
75+
app.kubernetes.io/name: argocd-image-updater
76+
app.kubernetes.io/part-of: argocd-image-updater
77+
name: argocd-image-updater
78+
roleRef:
79+
apiGroup: rbac.authorization.k8s.io
80+
kind: ClusterRole
81+
name: argocd-image-updater
82+
subjects:
83+
- kind: ServiceAccount
84+
name: argocd-image-updater
85+
---
6086
apiVersion: v1
6187
kind: ConfigMap
6288
metadata:

pkg/kube/kubernetes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ func (client *KubernetesClient) GetSecretField(namespace string, secretName stri
9696
}
9797
}
9898

99-
// CreateApplicationevent creates a kubernetes event with a custom reason and message for an application.
99+
// CreateApplicationEvent creates a kubernetes event with a custom reason and message for an application.
100100
func (client *KubernetesClient) CreateApplicationEvent(app *appv1alpha1.Application, reason string, message string, annotations map[string]string) (*v1.Event, error) {
101101
t := metav1.Time{Time: time.Now()}
102102

103103
event := v1.Event{
104104
ObjectMeta: metav1.ObjectMeta{
105105
Name: fmt.Sprintf("%v.%x", app.ObjectMeta.Name, t.UnixNano()),
106-
Namespace: client.Namespace,
106+
Namespace: app.ObjectMeta.Namespace,
107107
Annotations: annotations,
108108
},
109109
Source: v1.EventSource{
@@ -125,7 +125,7 @@ func (client *KubernetesClient) CreateApplicationEvent(app *appv1alpha1.Applicat
125125
Reason: reason,
126126
}
127127

128-
result, err := client.Clientset.CoreV1().Events(client.Namespace).Create(client.Context, &event, metav1.CreateOptions{})
128+
result, err := client.Clientset.CoreV1().Events(app.ObjectMeta.Namespace).Create(client.Context, &event, metav1.CreateOptions{})
129129
if err != nil {
130130
return nil, err
131131
}

pkg/kube/kubernetes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ func Test_CreateApplicationEvent(t *testing.T) {
9393
require.NoError(t, err)
9494
require.NotNil(t, event)
9595
assert.Equal(t, "ArgocdImageUpdater", event.Source.Component)
96-
assert.Equal(t, "default", client.Namespace)
96+
assert.Equal(t, "argocd", event.Namespace)
9797
})
9898
}

0 commit comments

Comments
 (0)