Skip to content

Commit

Permalink
feat: Sync namespace for Event to the Application namespace (#847) (#848
Browse files Browse the repository at this point in the history
)

Signed-off-by: Jort Koopmans <[email protected]>
  • Loading branch information
jortkoopmans authored Sep 6, 2024
1 parent d829685 commit 5990a9b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
15 changes: 15 additions & 0 deletions manifests/base/rbac/argocd-image-updater-clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: argocd-image-updater
app.kubernetes.io/part-of: argocd-image-updater
app.kubernetes.io/component: controller
name: argocd-image-updater
rules:
- apiGroups:
- ""
resources:
- events
verbs:
- create
15 changes: 15 additions & 0 deletions manifests/base/rbac/argocd-image-updater-clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
app.kubernetes.io/name: argocd-image-updater
app.kubernetes.io/part-of: argocd-image-updater
app.kubernetes.io/component: controller
name: argocd-image-updater
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: argocd-image-updater
subjects:
- kind: ServiceAccount
name: argocd-image-updater
7 changes: 0 additions & 7 deletions manifests/base/rbac/argocd-image-updater-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,3 @@ rules:
- list
- update
- patch
- apiGroups:
- ""
resources:
- events
verbs:
- create

2 changes: 2 additions & 0 deletions manifests/base/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- argocd-image-updater-clusterrole.yaml
- argocd-image-updater-clusterrolebinding.yaml
- argocd-image-updater-role.yaml
- argocd-image-updater-rolebinding.yaml
- argocd-image-updater-sa.yaml
26 changes: 26 additions & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ rules:
- list
- update
- patch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/name: argocd-image-updater
app.kubernetes.io/part-of: argocd-image-updater
name: argocd-image-updater
rules:
- apiGroups:
- ""
resources:
Expand All @@ -57,6 +67,22 @@ subjects:
- kind: ServiceAccount
name: argocd-image-updater
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/name: argocd-image-updater
app.kubernetes.io/part-of: argocd-image-updater
name: argocd-image-updater
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: argocd-image-updater
subjects:
- kind: ServiceAccount
name: argocd-image-updater
---
apiVersion: v1
kind: ConfigMap
metadata:
Expand Down
6 changes: 3 additions & 3 deletions pkg/kube/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kube/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit 5990a9b

Please sign in to comment.