Skip to content

Commit

Permalink
add image pull secrets to the EventLogger api (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
xosk31 authored May 21, 2024
1 parent 8159dc0 commit ac79bd1
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ spec:

serviceAccount: "sa" # optional - if a custom ServiceAccount should be used for the pod. Default ServiceAccount is automatically created

ImagePullSecrets: # optional - list of references to secrets to use for pulling the image.
- name: name

logFields: # optional - map if custom log field names. Key then log field name / Value: the reflection fields to the value within the struct corev1.Event https://github.com/kubernetes/api/blob/master/core/v1/types.go
- name: name
path:
Expand Down
6 changes: 6 additions & 0 deletions api/v1/eventlogger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1

import (
"github.com/bakito/k8s-event-logger-operator/version"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -48,6 +49,11 @@ type EventLoggerSpec struct {
// ServiceAccount the service account to use for the logger pod
ServiceAccount string `json:"serviceAccount,omitempty"`

// ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images used by this EventLoggerSpec.
// If specified, these secrets will be passed to individual puller implementations for them to use.
// +optional
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`

// NodeSelector is a selector which must be true for the pod to fit on a node.
// Selector which must match a node's labels for the pod to be scheduled on that node.
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
Expand Down
1 change: 1 addition & 0 deletions controllers/setup/eventlogger_controller_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (r *Reconciler) podForCR(cr *eventloggerv1.EventLogger) *corev1.Pod {
container,
},
ServiceAccountName: saccName,
ImagePullSecrets: cr.Spec.ImagePullSecrets,
NodeSelector: cr.Spec.NodeSelector,
},
}
Expand Down
15 changes: 15 additions & 0 deletions controllers/setup/eventlogger_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ var _ = Describe("Logging", func() {
Ω(pod2.Spec.Containers[0].Image).Should(Equal(testImage))
})

It("should update the imagePullSecrets", func() {
el.Spec.ImagePullSecrets = []corev1.LocalObjectReference{{Name: "secret1"}, {Name: "secret2"}}

cl, res := testReconcile(el)
Ω(res.Requeue).Should(BeFalse())

pods := &corev1.PodList{}
assertEntrySize(cl, el, pods, 1)
pod2 := pods.Items[0]

Ω(len(pod2.Spec.ImagePullSecrets)).Should(Equal(2))
Ω(pod2.Spec.ImagePullSecrets[0].Name).Should(Equal("secret1"))
Ω(pod2.Spec.ImagePullSecrets[1].Name).Should(Equal("secret2"))
})

It("should use an external service account", func() {
el.Spec.ServiceAccount = "foo"

Expand Down
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: k8s-event-logger-operator
description: This operator creates a logging pod that logs corev1.Event information as structured json log. The crd allows to configure the events to be logged.
type: application
version: 1.13.8
appVersion: v1.13.8
version: 1.13.11
appVersion: v1.13.11
sources:
- https://github.com/bakito/k8s-event-logger-operator
annotations:
Expand Down
2 changes: 1 addition & 1 deletion helm/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# k8s-event-logger-operator

![Version: 1.13.8](https://img.shields.io/badge/Version-1.13.8-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v1.13.8](https://img.shields.io/badge/AppVersion-v1.13.8-informational?style=flat-square)
![Version: 1.13.11](https://img.shields.io/badge/Version-1.13.11-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v1.13.11](https://img.shields.io/badge/AppVersion-v1.13.11-informational?style=flat-square)

This operator creates a logging pod that logs corev1.Event information as structured json log. The crd allows to configure the events to be logged.

Expand Down
23 changes: 23 additions & 0 deletions helm/crds/eventlogger.bakito.ch_eventloggers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ spec:
type: string
minItems: 0
type: array
imagePullSecrets:
description: |-
ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images used by this EventLoggerSpec.
If specified, these secrets will be passed to individual puller implementations for them to use.
items:
description: |-
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
type: array
kinds:
description: Kinds the kinds to log the events for
items:
Expand Down

0 comments on commit ac79bd1

Please sign in to comment.