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

feat: Sync namespace for Event to the Application namespace (#847) #848

Merged
Show file tree
Hide file tree
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
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
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)
})
}