|
4 | 4 | "context" |
5 | 5 | "fmt" |
6 | 6 | "strings" |
| 7 | + "time" |
7 | 8 |
|
8 | 9 | corev1 "k8s.io/api/core/v1" |
9 | 10 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
@@ -117,3 +118,38 @@ func (j *Janitor) kubeEachResource(ctx context.Context, gvr schema.GroupVersionR |
117 | 118 |
|
118 | 119 | return nil |
119 | 120 | } |
| 121 | + |
| 122 | +func (j *Janitor) kubeCreateEventFromResource(ctx context.Context, namespace string, resource unstructured.Unstructured, message, reason string) error { |
| 123 | + timestamp := metav1.Time{Time: time.Now()} |
| 124 | + |
| 125 | + event := corev1.Event{ |
| 126 | + ObjectMeta: metav1.ObjectMeta{ |
| 127 | + GenerateName: "kube-janitor-", |
| 128 | + Namespace: resource.GetNamespace(), |
| 129 | + }, |
| 130 | + ReportingInstance: "kube-janitor", |
| 131 | + InvolvedObject: corev1.ObjectReference{ |
| 132 | + APIVersion: resource.GetAPIVersion(), |
| 133 | + Kind: resource.GetKind(), |
| 134 | + Namespace: resource.GetNamespace(), |
| 135 | + Name: resource.GetName(), |
| 136 | + UID: resource.GetUID(), |
| 137 | + }, |
| 138 | + Reason: reason, |
| 139 | + Message: message, |
| 140 | + Source: corev1.EventSource{ |
| 141 | + Component: "kube-janitor", |
| 142 | + }, |
| 143 | + FirstTimestamp: timestamp, |
| 144 | + LastTimestamp: timestamp, |
| 145 | + Count: 1, |
| 146 | + Type: "Normal", |
| 147 | + Series: nil, |
| 148 | + Action: "Deleted", |
| 149 | + Related: nil, |
| 150 | + ReportingController: "kube-janitor", |
| 151 | + } |
| 152 | + |
| 153 | + _, err := j.kubeClient.CoreV1().Events(namespace).Create(ctx, &event, metav1.CreateOptions{}) |
| 154 | + return err |
| 155 | +} |
0 commit comments