Add ability to pull secrets.

This commit is contained in:
2024-09-11 16:36:47 +01:00
parent fffbae11d8
commit e37df8247f
11 changed files with 123 additions and 37 deletions
+4
View File
@@ -17,6 +17,7 @@ limitations under the License.
package v1 package v1
import ( import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
@@ -36,7 +37,10 @@ type ClusterImageSpec struct {
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"`
// +kubebuilder:validation:Optional
JobAnnotations map[string]string `json:"jobAnnotations,omitempty"` JobAnnotations map[string]string `json:"jobAnnotations,omitempty"`
// +kubebuilder:validation:Optional
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
} }
// ClusterImageStatus defines the observed state of ClusterImage // ClusterImageStatus defines the observed state of ClusterImage
@@ -17,6 +17,7 @@ limitations under the License.
package v1 package v1
import ( import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
@@ -62,7 +63,10 @@ type ClusterImageExportSpec struct {
// +kubebuilder:validation:MaxLength=255 // +kubebuilder:validation:MaxLength=255
BasePath string `json:"basePath"` BasePath string `json:"basePath"`
Storage ClusterImageStorageSpec `json:"storage"` Storage ClusterImageStorageSpec `json:"storage"`
// +kubebuilder:validation:Optional
JobAnnotations map[string]string `json:"jobAnnotations,omitempty"` JobAnnotations map[string]string `json:"jobAnnotations,omitempty"`
// +kubebuilder:validation:Optional
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,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"`
+2 -2
View File
@@ -10,9 +10,9 @@ description: |
type: application type: application
version: 0.1.20 version: 0.1.23
appVersion: "0.1.20" appVersion: "0.1.23"
home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator
+18
View File
@@ -78,6 +78,24 @@ spec:
type: string type: string
imageNamespace: imageNamespace:
type: string type: string
imagePullSecrets:
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.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
type: array
jobAnnotations: jobAnnotations:
additionalProperties: additionalProperties:
type: string type: string
@@ -70,6 +70,24 @@ spec:
items: items:
type: string type: string
type: array type: array
imagePullSecrets:
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.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
type: array
includes: includes:
description: Include only images which contain these strings description: Include only images which contain these strings
items: items:
+1 -1
View File
@@ -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.20 tag: 0.1.23
resources: resources:
limits: limits:
cpu: 500m cpu: 500m
@@ -70,6 +70,24 @@ spec:
items: items:
type: string type: string
type: array type: array
imagePullSecrets:
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.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
type: array
includes: includes:
description: Include only images which contain these strings description: Include only images which contain these strings
items: items:
@@ -77,6 +77,24 @@ spec:
type: string type: string
imageNamespace: imageNamespace:
type: string type: string
imagePullSecrets:
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.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
type: array
jobAnnotations: jobAnnotations:
additionalProperties: additionalProperties:
type: string type: string
@@ -36,6 +36,8 @@ type ClusterImageReconciler struct {
// # 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 // +kubebuilder:rbac:groups="",resources=pods,verbs=get;list;watch;create;update;patch;delete
// add access to secrets
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
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)
@@ -235,6 +237,7 @@ func (r *ClusterImageReconciler) createBackupJob(ctx context.Context, clusterIma
Annotations: clusterImage.Spec.JobAnnotations, Annotations: clusterImage.Spec.JobAnnotations,
Commands: defaultCommands, Commands: defaultCommands,
ServiceAccount: os.Getenv("POD_SERVICE_ACCOUNT"), ServiceAccount: os.Getenv("POD_SERVICE_ACCOUNT"),
ImagePullSecrets: clusterImage.Spec.ImagePullSecrets,
OwnerReferences: []metav1.OwnerReference{ OwnerReferences: []metav1.OwnerReference{
{ {
APIVersion: clusterImage.APIVersion, APIVersion: clusterImage.APIVersion,
@@ -140,6 +140,7 @@ func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.R
ExportName: clusterImageExport.Name, ExportName: clusterImageExport.Name,
ExportPath: clusterImageExport.Spec.BasePath, ExportPath: clusterImageExport.Spec.BasePath,
JobAnnotations: clusterImageExport.Spec.JobAnnotations, JobAnnotations: clusterImageExport.Spec.JobAnnotations,
ImagePullSecrets: clusterImageExport.Spec.ImagePullSecrets,
}, },
} }
+2
View File
@@ -20,6 +20,7 @@ type JobParams struct {
EnvVars []corev1.EnvVar EnvVars []corev1.EnvVar
OwnerReferences []metav1.OwnerReference OwnerReferences []metav1.OwnerReference
ServiceAccount string ServiceAccount string
ImagePullSecrets []corev1.LocalObjectReference
} }
func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job { func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job {
@@ -44,6 +45,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: params.ServiceAccount,
ImagePullSecrets: params.ImagePullSecrets,
Containers: []corev1.Container{ Containers: []corev1.Container{
{ {
Name: "export", Name: "export",