mirror of
https://github.com/lukaszraczylo/kubernetes-images-sync-operator.git
synced 2026-07-08 03:54:26 +00:00
Ensure that jobs run with the controller service account if no service account is specified.
This commit is contained in:
+2
-2
@@ -10,9 +10,9 @@ description: |
|
|||||||
|
|
||||||
type: application
|
type: application
|
||||||
|
|
||||||
version: 0.1.33
|
version: 0.2.17
|
||||||
|
|
||||||
appVersion: "0.1.33"
|
appVersion: "0.2.17"
|
||||||
|
|
||||||
home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator
|
home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ sa:
|
|||||||
- ALL
|
- ALL
|
||||||
image:
|
image:
|
||||||
repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator
|
repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator
|
||||||
tag: 0.1.33
|
tag: 0.2.17
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: 500m
|
cpu: 500m
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package raczylocom
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -259,7 +258,7 @@ func (r *ClusterImageReconciler) createBackupJob(ctx context.Context, clusterIma
|
|||||||
Image: shared.BACKUP_JOB_IMAGE,
|
Image: shared.BACKUP_JOB_IMAGE,
|
||||||
Annotations: clusterImage.Spec.JobAnnotations,
|
Annotations: clusterImage.Spec.JobAnnotations,
|
||||||
Commands: defaultCommands,
|
Commands: defaultCommands,
|
||||||
ServiceAccount: os.Getenv("POD_SERVICE_ACCOUNT"),
|
ServiceAccount: "",
|
||||||
ImagePullSecrets: clusterImage.Spec.ImagePullSecrets,
|
ImagePullSecrets: clusterImage.Spec.ImagePullSecrets,
|
||||||
OwnerReferences: []metav1.OwnerReference{
|
OwnerReferences: []metav1.OwnerReference{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -286,7 +285,7 @@ func (r *ClusterImageExportReconciler) runCleanupJob(ctx context.Context, cluste
|
|||||||
Image: shared.BACKUP_JOB_IMAGE,
|
Image: shared.BACKUP_JOB_IMAGE,
|
||||||
Commands: defaultCommands,
|
Commands: defaultCommands,
|
||||||
Annotations: clusterImageExport.Spec.JobAnnotations,
|
Annotations: clusterImageExport.Spec.JobAnnotations,
|
||||||
ServiceAccount: os.Getenv("POD_SERVICE_ACCOUNT"),
|
ServiceAccount: "",
|
||||||
ImagePullSecrets: clusterImageExport.Spec.ImagePullSecrets,
|
ImagePullSecrets: clusterImageExport.Spec.ImagePullSecrets,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package shared
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
raczylocomv1 "github.com/lukaszraczylo/kubernetes-images-sync-operator/api/raczylo.com/v1"
|
raczylocomv1 "github.com/lukaszraczylo/kubernetes-images-sync-operator/api/raczylo.com/v1"
|
||||||
@@ -19,7 +20,7 @@ type JobParams struct {
|
|||||||
Commands []string
|
Commands []string
|
||||||
EnvVars []corev1.EnvVar
|
EnvVars []corev1.EnvVar
|
||||||
OwnerReferences []metav1.OwnerReference
|
OwnerReferences []metav1.OwnerReference
|
||||||
ServiceAccount string
|
ServiceAccount string // Can be empty to use controller's service account
|
||||||
ImagePullSecrets []corev1.LocalObjectReference
|
ImagePullSecrets []corev1.LocalObjectReference
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +46,11 @@ func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serviceAccount := params.ServiceAccount
|
||||||
|
if serviceAccount == "" {
|
||||||
|
serviceAccount = os.Getenv("POD_SERVICE_ACCOUNT")
|
||||||
|
}
|
||||||
|
|
||||||
j := &batchv1.Job{
|
j := &batchv1.Job{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
@@ -65,7 +71,7 @@ func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job
|
|||||||
},
|
},
|
||||||
Spec: corev1.PodSpec{
|
Spec: corev1.PodSpec{
|
||||||
RestartPolicy: corev1.RestartPolicyOnFailure,
|
RestartPolicy: corev1.RestartPolicyOnFailure,
|
||||||
ServiceAccountName: params.ServiceAccount,
|
ServiceAccountName: serviceAccount,
|
||||||
ImagePullSecrets: params.ImagePullSecrets,
|
ImagePullSecrets: params.ImagePullSecrets,
|
||||||
Volumes: volumes,
|
Volumes: volumes,
|
||||||
Containers: []corev1.Container{
|
Containers: []corev1.Container{
|
||||||
|
|||||||
Reference in New Issue
Block a user