Add ability to provide annotations to the jobs.

This commit is contained in:
2024-09-11 13:09:54 +01:00
parent bbb41681df
commit fffbae11d8
33 changed files with 143 additions and 85 deletions
+2
View File
@@ -27,3 +27,5 @@ go.work
*~ *~
**/.DS_Store **/.DS_Store
config/samples config/samples
**/__pycache__
+1 -1
View File
@@ -54,7 +54,7 @@ help: ## Display this help.
.PHONY: manifests .PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=mr-raczylo-com crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases $(CONTROLLER_GEN) rbac:roleName=impex-mgr crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
.PHONY: generate .PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
+2
View File
@@ -30,6 +30,8 @@ kind: ClusterImageExport
metadata: metadata:
name: backup-20240901 name: backup-20240901
spec: spec:
jobAnnotations:
my-fancy-export: 11-09-2024
# Excludes will remove all images with listed wording from the backup list # Excludes will remove all images with listed wording from the backup list
# excludes: # excludes:
# - nginx # - nginx
+9 -8
View File
@@ -28,14 +28,15 @@ import (
// +kubebuilder:printcolumn:name="Path",type="string",JSONPath=".spec.exportPath" // +kubebuilder:printcolumn:name="Path",type="string",JSONPath=".spec.exportPath"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type ClusterImageSpec struct { type ClusterImageSpec struct {
Image string `json:"image,omitempty"` Image string `json:"image,omitempty"`
Tag string `json:"tag,omitempty"` Tag string `json:"tag,omitempty"`
Sha string `json:"sha,omitempty"` Sha string `json:"sha,omitempty"`
FullName string `json:"fullName,omitempty"` // Because I'm lazy and it's easier to pull that way FullName string `json:"fullName,omitempty"` // Because I'm lazy and it's easier to pull that way
Storage string `json:"storage,omitempty"` Storage string `json:"storage,omitempty"`
ExportName string `json:"exportName"` ExportName string `json:"exportName"`
ExportPath string `json:"exportPath,omitempty"` ExportPath string `json:"exportPath,omitempty"`
ImageNamespace string `json:"imageNamespace,omitempty"` ImageNamespace string `json:"imageNamespace,omitempty"`
JobAnnotations map[string]string `json:"jobAnnotations,omitempty"`
} }
// ClusterImageStatus defines the observed state of ClusterImage // ClusterImageStatus defines the observed state of ClusterImage
@@ -60,8 +60,9 @@ type ClusterImageExportSpec struct {
// Base path for the export - both file and S3 // Base path for the export - both file and S3
// +kubebuilder:validation:MinLength=1 // +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=255 // +kubebuilder:validation:MaxLength=255
BasePath string `json:"basePath"` BasePath string `json:"basePath"`
Storage ClusterImageStorageSpec `json:"storage"` Storage ClusterImageStorageSpec `json:"storage"`
JobAnnotations map[string]string `json:"jobAnnotations,omitempty"`
// +kubebuilder:validation.Minimum=1 // +kubebuilder:validation.Minimum=1
// +kubebuilder:validation.Maximum=100 // +kubebuilder:validation.Maximum=100
MaxConcurrentJobs int `json:"maxConcurrentJobs"` MaxConcurrentJobs int `json:"maxConcurrentJobs"`
+15 -1
View File
@@ -29,7 +29,7 @@ func (in *ClusterImage) DeepCopyInto(out *ClusterImage) {
*out = *in *out = *in
out.TypeMeta = in.TypeMeta out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec in.Spec.DeepCopyInto(&out.Spec)
out.Status = in.Status out.Status = in.Status
} }
@@ -135,6 +135,13 @@ func (in *ClusterImageExportSpec) DeepCopyInto(out *ClusterImageExportSpec) {
copy(*out, *in) copy(*out, *in)
} }
out.Storage = in.Storage out.Storage = in.Storage
if in.JobAnnotations != nil {
in, out := &in.JobAnnotations, &out.JobAnnotations
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
} }
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterImageExportSpec. // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterImageExportSpec.
@@ -197,6 +204,13 @@ func (in *ClusterImageList) DeepCopyObject() runtime.Object {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterImageSpec) DeepCopyInto(out *ClusterImageSpec) { func (in *ClusterImageSpec) DeepCopyInto(out *ClusterImageSpec) {
*out = *in *out = *in
if in.JobAnnotations != nil {
in, out := &in.JobAnnotations, &out.JobAnnotations
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
} }
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterImageSpec. // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterImageSpec.
+2 -2
View File
@@ -10,9 +10,9 @@ description: |
type: application type: application
version: 0.1.18 version: 0.1.20
appVersion: "0.1.18" appVersion: "0.1.20"
home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator
+4
View File
@@ -78,6 +78,10 @@ spec:
type: string type: string
imageNamespace: imageNamespace:
type: string type: string
jobAnnotations:
additionalProperties:
type: string
type: object
sha: sha:
type: string type: string
storage: storage:
@@ -75,6 +75,10 @@ spec:
items: items:
type: string type: string
type: array type: array
jobAnnotations:
additionalProperties:
type: string
type: object
maxConcurrentJobs: maxConcurrentJobs:
type: integer type: integer
name: name:
@@ -1,14 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "chart.fullname" . }}-cm-raczylo-com-metrics-service
labels:
control-plane: cm-raczylo-com
{{- include "chart.labels" . | nindent 4 }}
spec:
type: {{ .Values.cmRaczyloComMetricsService.type }}
selector:
control-plane: cm-raczylo-com
{{- include "chart.selectorLabels" . | nindent 4 }}
ports:
{{- .Values.cmRaczyloComMetricsService.ports | toYaml | nindent 2 }}
+15 -11
View File
@@ -1,32 +1,36 @@
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: {{ include "chart.fullname" . }}-cm-raczylo-com name: {{ include "chart.fullname" . }}-sa
labels: labels:
control-plane: cm-raczylo-com control-plane: sa
{{- include "chart.labels" . | nindent 4 }} {{- include "chart.labels" . | nindent 4 }}
spec: spec:
replicas: {{ .Values.cmRaczyloCom.replicas }} replicas: {{ .Values.sa.replicas }}
selector: selector:
matchLabels: matchLabels:
control-plane: cm-raczylo-com control-plane: sa
{{- include "chart.selectorLabels" . | nindent 6 }} {{- include "chart.selectorLabels" . | nindent 6 }}
template: template:
metadata: metadata:
labels: labels:
control-plane: cm-raczylo-com control-plane: sa
{{- include "chart.selectorLabels" . | nindent 8 }} {{- include "chart.selectorLabels" . | nindent 8 }}
annotations: annotations:
kubectl.kubernetes.io/default-container: manager kubectl.kubernetes.io/default-container: manager
spec: spec:
containers: containers:
- args: {{- toYaml .Values.cmRaczyloCom.manager.args | nindent 8 }} - args: {{- toYaml .Values.sa.manager.args | nindent 8 }}
command: command:
- /manager - /manager
env: env:
- name: POD_SERVICE_ACCOUNT
valueFrom:
fieldRef:
fieldPath: spec.serviceAccountName
- name: KUBERNETES_CLUSTER_DOMAIN - name: KUBERNETES_CLUSTER_DOMAIN
value: {{ quote .Values.kubernetesClusterDomain }} value: {{ quote .Values.kubernetesClusterDomain }}
image: {{ .Values.cmRaczyloCom.manager.image.repository }}:{{ .Values.cmRaczyloCom.manager.image.tag image: {{ .Values.sa.manager.image.repository }}:{{ .Values.sa.manager.image.tag
| default .Chart.AppVersion }} | default .Chart.AppVersion }}
livenessProbe: livenessProbe:
httpGet: httpGet:
@@ -41,10 +45,10 @@ spec:
port: 8081 port: 8081
initialDelaySeconds: 5 initialDelaySeconds: 5
periodSeconds: 10 periodSeconds: 10
resources: {{- toYaml .Values.cmRaczyloCom.manager.resources | nindent 10 }} resources: {{- toYaml .Values.sa.manager.resources | nindent 10 }}
securityContext: {{- toYaml .Values.cmRaczyloCom.manager.containerSecurityContext securityContext: {{- toYaml .Values.sa.manager.containerSecurityContext | nindent
| nindent 10 }} 10 }}
securityContext: securityContext:
runAsNonRoot: true runAsNonRoot: true
serviceAccountName: {{ include "chart.fullname" . }}-cm-raczylo-com serviceAccountName: {{ include "chart.fullname" . }}-sa
terminationGracePeriodSeconds: 10 terminationGracePeriodSeconds: 10
@@ -1,7 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole kind: ClusterRole
metadata: metadata:
name: {{ include "chart.fullname" . }}-mr-raczylo-com name: {{ include "chart.fullname" . }}-impex-mgr
labels: labels:
{{- include "chart.labels" . | nindent 4 }} {{- include "chart.labels" . | nindent 4 }}
rules: rules:
@@ -1,14 +1,14 @@
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding kind: ClusterRoleBinding
metadata: metadata:
name: {{ include "chart.fullname" . }}-mr-raczylo-combinding name: {{ include "chart.fullname" . }}-impex-mgrbinding
labels: labels:
{{- include "chart.labels" . | nindent 4 }} {{- include "chart.labels" . | nindent 4 }}
roleRef: roleRef:
apiGroup: rbac.authorization.k8s.io apiGroup: rbac.authorization.k8s.io
kind: ClusterRole kind: ClusterRole
name: '{{ include "chart.fullname" . }}-mr-raczylo-com' name: '{{ include "chart.fullname" . }}-impex-mgr'
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: '{{ include "chart.fullname" . }}-cm-raczylo-com' name: '{{ include "chart.fullname" . }}-sa'
namespace: '{{ .Release.Namespace }}' namespace: '{{ .Release.Namespace }}'
@@ -10,5 +10,5 @@ roleRef:
name: '{{ include "chart.fullname" . }}-metrics-auth-raczylo' name: '{{ include "chart.fullname" . }}-metrics-auth-raczylo'
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: '{{ include "chart.fullname" . }}-cm-raczylo-com' name: '{{ include "chart.fullname" . }}-sa'
namespace: '{{ .Release.Namespace }}' namespace: '{{ .Release.Namespace }}'
@@ -10,5 +10,5 @@ roleRef:
name: '{{ include "chart.fullname" . }}-raczylo-com-leader' name: '{{ include "chart.fullname" . }}-raczylo-com-leader'
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: '{{ include "chart.fullname" . }}-cm-raczylo-com' name: '{{ include "chart.fullname" . }}-sa'
namespace: '{{ .Release.Namespace }}' namespace: '{{ .Release.Namespace }}'
+14
View File
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "chart.fullname" . }}-sa-metrics-service
labels:
control-plane: sa
{{- include "chart.labels" . | nindent 4 }}
spec:
type: {{ .Values.saMetricsService.type }}
selector:
control-plane: sa
{{- include "chart.selectorLabels" . | nindent 4 }}
ports:
{{- .Values.saMetricsService.ports | toYaml | nindent 2 }}
+2 -2
View File
@@ -1,8 +1,8 @@
apiVersion: v1 apiVersion: v1
kind: ServiceAccount kind: ServiceAccount
metadata: metadata:
name: {{ include "chart.fullname" . }}-cm-raczylo-com name: {{ include "chart.fullname" . }}-sa
labels: labels:
{{- include "chart.labels" . | nindent 4 }} {{- include "chart.labels" . | nindent 4 }}
annotations: annotations:
{{- toYaml .Values.cmRaczyloCom.serviceAccount.annotations | nindent 4 }} {{- toYaml .Values.sa.serviceAccount.annotations | nindent 4 }}
+4 -4
View File
@@ -1,4 +1,5 @@
cmRaczyloCom: kubernetesClusterDomain: cluster.local
sa:
manager: manager:
args: args:
- --metrics-bind-address=:8443 - --metrics-bind-address=:8443
@@ -11,7 +12,7 @@ cmRaczyloCom:
- ALL - ALL
image: image:
repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator
tag: 0.1.18 tag: 0.1.20
resources: resources:
limits: limits:
cpu: 500m cpu: 500m
@@ -22,11 +23,10 @@ cmRaczyloCom:
replicas: 1 replicas: 1
serviceAccount: serviceAccount:
annotations: {} annotations: {}
cmRaczyloComMetricsService: saMetricsService:
ports: ports:
- name: https - name: https
port: 8443 port: 8443
protocol: TCP protocol: TCP
targetPort: 8443 targetPort: 8443
type: ClusterIP type: ClusterIP
kubernetesClusterDomain: cluster.local
@@ -75,6 +75,10 @@ spec:
items: items:
type: string type: string
type: array type: array
jobAnnotations:
additionalProperties:
type: string
type: object
maxConcurrentJobs: maxConcurrentJobs:
type: integer type: integer
name: name:
@@ -77,6 +77,10 @@ spec:
type: string type: string
imageNamespace: imageNamespace:
type: string type: string
jobAnnotations:
additionalProperties:
type: string
type: object
sha: sha:
type: string type: string
storage: storage:
+3 -3
View File
@@ -2,10 +2,10 @@ apiVersion: v1
kind: Service kind: Service
metadata: metadata:
labels: labels:
control-plane: cm-raczylo-com control-plane: sa
app.kubernetes.io/name: kubernetes-images-sync-operator app.kubernetes.io/name: kubernetes-images-sync-operator
app.kubernetes.io/managed-by: kustomize app.kubernetes.io/managed-by: kustomize
name: cm-raczylo-com-metrics-service name: sa-metrics-service
namespace: system namespace: system
spec: spec:
ports: ports:
@@ -14,4 +14,4 @@ spec:
protocol: TCP protocol: TCP
targetPort: 8443 targetPort: 8443
selector: selector:
control-plane: cm-raczylo-com control-plane: sa
+11 -6
View File
@@ -2,7 +2,7 @@ apiVersion: v1
kind: Namespace kind: Namespace
metadata: metadata:
labels: labels:
control-plane: cm-raczylo-com control-plane: sa
app.kubernetes.io/name: kubernetes-images-sync-operator app.kubernetes.io/name: kubernetes-images-sync-operator
app.kubernetes.io/managed-by: kustomize app.kubernetes.io/managed-by: kustomize
name: system name: system
@@ -10,23 +10,23 @@ metadata:
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: cm-raczylo-com name: sa
namespace: system namespace: system
labels: labels:
control-plane: cm-raczylo-com control-plane: sa
app.kubernetes.io/name: kubernetes-images-sync-operator app.kubernetes.io/name: kubernetes-images-sync-operator
app.kubernetes.io/managed-by: kustomize app.kubernetes.io/managed-by: kustomize
spec: spec:
selector: selector:
matchLabels: matchLabels:
control-plane: cm-raczylo-com control-plane: sa
replicas: 1 replicas: 1
template: template:
metadata: metadata:
annotations: annotations:
kubectl.kubernetes.io/default-container: manager kubectl.kubernetes.io/default-container: manager
labels: labels:
control-plane: cm-raczylo-com control-plane: sa
spec: spec:
# TODO(user): Uncomment the following code to configure the nodeAffinity expression # TODO(user): Uncomment the following code to configure the nodeAffinity expression
# according to the platforms which are supported by your solution. # according to the platforms which are supported by your solution.
@@ -63,6 +63,11 @@ spec:
args: args:
- --leader-elect - --leader-elect
- --health-probe-bind-address=:8081 - --health-probe-bind-address=:8081
env:
- name: POD_SERVICE_ACCOUNT
valueFrom:
fieldRef:
fieldPath: spec.serviceAccountName
image: controller:latest image: controller:latest
name: manager name: manager
securityContext: securityContext:
@@ -91,5 +96,5 @@ spec:
requests: requests:
cpu: 10m cpu: 10m
memory: 64Mi memory: 64Mi
serviceAccountName: cm-raczylo-com serviceAccountName: sa
terminationGracePeriodSeconds: 10 terminationGracePeriodSeconds: 10
@@ -12,7 +12,7 @@ metadata:
spec: spec:
podSelector: podSelector:
matchLabels: matchLabels:
control-plane: cm-raczylo-com control-plane: sa
policyTypes: policyTypes:
- Ingress - Ingress
ingress: ingress:
+3 -3
View File
@@ -3,10 +3,10 @@ apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor kind: ServiceMonitor
metadata: metadata:
labels: labels:
control-plane: cm-raczylo-com control-plane: sa
app.kubernetes.io/name: kubernetes-images-sync-operator app.kubernetes.io/name: kubernetes-images-sync-operator
app.kubernetes.io/managed-by: kustomize app.kubernetes.io/managed-by: kustomize
name: cm-raczylo-com-metrics-monitor name: sa-metrics-monitor
namespace: system namespace: system
spec: spec:
endpoints: endpoints:
@@ -27,4 +27,4 @@ spec:
insecureSkipVerify: true insecureSkipVerify: true
selector: selector:
matchLabels: matchLabels:
control-plane: cm-raczylo-com control-plane: sa
@@ -11,5 +11,5 @@ roleRef:
name: raczylo-com-leader name: raczylo-com-leader
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: cm-raczylo-com name: sa
namespace: system namespace: system
+1 -1
View File
@@ -8,5 +8,5 @@ roleRef:
name: metrics-auth-raczylo name: metrics-auth-raczylo
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: cm-raczylo-com name: sa
namespace: system namespace: system
+1 -1
View File
@@ -2,7 +2,7 @@
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole kind: ClusterRole
metadata: metadata:
name: mr-raczylo-com name: impex-mgr
rules: rules:
- apiGroups: - apiGroups:
- "" - ""
+3 -3
View File
@@ -4,12 +4,12 @@ metadata:
labels: labels:
app.kubernetes.io/name: kubernetes-images-sync-operator app.kubernetes.io/name: kubernetes-images-sync-operator
app.kubernetes.io/managed-by: kustomize app.kubernetes.io/managed-by: kustomize
name: mr-raczylo-combinding name: impex-mgrbinding
roleRef: roleRef:
apiGroup: rbac.authorization.k8s.io apiGroup: rbac.authorization.k8s.io
kind: ClusterRole kind: ClusterRole
name: mr-raczylo-com name: impex-mgr
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: cm-raczylo-com name: sa
namespace: system namespace: system
+1 -1
View File
@@ -4,5 +4,5 @@ metadata:
labels: labels:
app.kubernetes.io/name: kubernetes-images-sync-operator app.kubernetes.io/name: kubernetes-images-sync-operator
app.kubernetes.io/managed-by: kustomize app.kubernetes.io/managed-by: kustomize
name: cm-raczylo-com name: sa
namespace: system namespace: system
@@ -3,6 +3,7 @@ package raczylocom
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"strings" "strings"
"time" "time"
@@ -34,6 +35,7 @@ type ClusterImageReconciler struct {
// +kubebuilder:rbac:groups=raczylo.com,resources=*/finalizers,verbs=update // +kubebuilder:rbac:groups=raczylo.com,resources=*/finalizers,verbs=update
// # additional RBAC rules - create and manage jobs // # additional RBAC rules - create and manage jobs
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="",resources=pods,verbs=get;list;watch;create;update;patch;delete
func (r *ClusterImageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { func (r *ClusterImageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
l := log.FromContext(ctx) l := log.FromContext(ctx)
@@ -227,10 +229,12 @@ func (r *ClusterImageReconciler) createBackupJob(ctx context.Context, clusterIma
defaultCommands = append(defaultCommands, "rm -f /tmp/"+normalisedImageName+".tar") defaultCommands = append(defaultCommands, "rm -f /tmp/"+normalisedImageName+".tar")
jobParams := shared.JobParams{ jobParams := shared.JobParams{
Name: fmt.Sprintf("img-export-%s", clusterImage.Name), Name: fmt.Sprintf("img-export-%s", clusterImage.Name),
Namespace: clusterImage.Namespace, Namespace: clusterImage.Namespace,
Image: shared.BACKUP_JOB_IMAGE, Image: shared.BACKUP_JOB_IMAGE,
Commands: defaultCommands, Annotations: clusterImage.Spec.JobAnnotations,
Commands: defaultCommands,
ServiceAccount: os.Getenv("POD_SERVICE_ACCOUNT"),
OwnerReferences: []metav1.OwnerReference{ OwnerReferences: []metav1.OwnerReference{
{ {
APIVersion: clusterImage.APIVersion, APIVersion: clusterImage.APIVersion,
@@ -4,6 +4,7 @@ import (
"context" "context"
"crypto/md5" "crypto/md5"
"fmt" "fmt"
"os"
"strings" "strings"
"time" "time"
@@ -138,6 +139,7 @@ func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.R
Storage: clusterImageExport.Spec.Storage.StorageTarget, Storage: clusterImageExport.Spec.Storage.StorageTarget,
ExportName: clusterImageExport.Name, ExportName: clusterImageExport.Name,
ExportPath: clusterImageExport.Spec.BasePath, ExportPath: clusterImageExport.Spec.BasePath,
JobAnnotations: clusterImageExport.Spec.JobAnnotations,
}, },
} }
@@ -267,10 +269,12 @@ func (r *ClusterImageExportReconciler) runCleanupJob(ctx context.Context, cluste
} }
jobParams := shared.JobParams{ jobParams := shared.JobParams{
Name: normalisedImageName, Name: normalisedImageName,
Namespace: clusterImageExport.Namespace, Namespace: clusterImageExport.Namespace,
Image: shared.BACKUP_JOB_IMAGE, Image: shared.BACKUP_JOB_IMAGE,
Commands: defaultCommands, Commands: defaultCommands,
Annotations: clusterImageExport.Spec.JobAnnotations,
ServiceAccount: os.Getenv("POD_SERVICE_ACCOUNT"),
} }
cleanupJob := shared.CreateJob(jobParams, func(raczylocomv1.ClusterImageExport) []string { return nil }) cleanupJob := shared.CreateJob(jobParams, func(raczylocomv1.ClusterImageExport) []string { return nil })
+6 -1
View File
@@ -14,10 +14,12 @@ import (
type JobParams struct { type JobParams struct {
Name string Name string
Namespace string Namespace string
Annotations map[string]string
Image string Image string
Commands []string Commands []string
EnvVars []corev1.EnvVar EnvVars []corev1.EnvVar
OwnerReferences []metav1.OwnerReference OwnerReferences []metav1.OwnerReference
ServiceAccount string
} }
func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job { func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job {
@@ -29,6 +31,7 @@ func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job
Labels: map[string]string{ Labels: map[string]string{
"app": "image-export", "app": "image-export",
}, },
Annotations: params.Annotations,
}, },
Spec: batchv1.JobSpec{ Spec: batchv1.JobSpec{
Template: corev1.PodTemplateSpec{ Template: corev1.PodTemplateSpec{
@@ -36,9 +39,11 @@ func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job
Labels: map[string]string{ Labels: map[string]string{
"app": "image-export", "app": "image-export",
}, },
Annotations: params.Annotations,
}, },
Spec: corev1.PodSpec{ Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyOnFailure, RestartPolicy: corev1.RestartPolicyOnFailure,
ServiceAccountName: params.ServiceAccount,
Containers: []corev1.Container{ Containers: []corev1.Container{
{ {
Name: "export", Name: "export",
+4 -4
View File
@@ -76,17 +76,17 @@ var _ = Describe("controller", Ordered, func() {
_, err = utils.Run(cmd) _, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred()) ExpectWithOffset(1, err).NotTo(HaveOccurred())
By("deploying the cm-raczylo-com") By("deploying the sa")
cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectimage)) cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectimage))
_, err = utils.Run(cmd) _, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred()) ExpectWithOffset(1, err).NotTo(HaveOccurred())
By("validating that the cm-raczylo-com pod is running as expected") By("validating that the sa pod is running as expected")
verifyControllerUp := func() error { verifyControllerUp := func() error {
// Get pod name // Get pod name
cmd = exec.Command("kubectl", "get", cmd = exec.Command("kubectl", "get",
"pods", "-l", "control-plane=cm-raczylo-com", "pods", "-l", "control-plane=sa",
"-o", "go-template={{ range .items }}"+ "-o", "go-template={{ range .items }}"+
"{{ if not .metadata.deletionTimestamp }}"+ "{{ if not .metadata.deletionTimestamp }}"+
"{{ .metadata.name }}"+ "{{ .metadata.name }}"+
@@ -101,7 +101,7 @@ var _ = Describe("controller", Ordered, func() {
return fmt.Errorf("expect 1 controller pods running, but got %d", len(podNames)) return fmt.Errorf("expect 1 controller pods running, but got %d", len(podNames))
} }
controllerPodName = podNames[0] controllerPodName = podNames[0]
ExpectWithOffset(2, controllerPodName).Should(ContainSubstring("cm-raczylo-com")) ExpectWithOffset(2, controllerPodName).Should(ContainSubstring("sa"))
// Validate pod status // Validate pod status
cmd = exec.Command("kubectl", "get", cmd = exec.Command("kubectl", "get",