mirror of
https://github.com/lukaszraczylo/kubernetes-images-sync-operator.git
synced 2026-07-09 04:01:45 +00:00
Add ability to pull secrets.
This commit is contained in:
@@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,15 +29,18 @@ 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"`
|
||||||
|
// +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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -60,9 +61,12 @@ 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:Optional
|
||||||
|
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
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -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)
|
||||||
|
|
||||||
@@ -229,12 +231,13 @@ 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,
|
||||||
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,
|
||||||
|
|||||||
@@ -131,15 +131,16 @@ func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.R
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: raczylocomv1.ClusterImageSpec{
|
Spec: raczylocomv1.ClusterImageSpec{
|
||||||
Image: image.Image,
|
Image: image.Image,
|
||||||
Tag: image.Tag,
|
Tag: image.Tag,
|
||||||
Sha: image.Sha,
|
Sha: image.Sha,
|
||||||
FullName: image.FullName,
|
FullName: image.FullName,
|
||||||
ImageNamespace: image.ImageNamespace,
|
ImageNamespace: image.ImageNamespace,
|
||||||
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,
|
JobAnnotations: clusterImageExport.Spec.JobAnnotations,
|
||||||
|
ImagePullSecrets: clusterImageExport.Spec.ImagePullSecrets,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-8
@@ -12,14 +12,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type JobParams struct {
|
type JobParams struct {
|
||||||
Name string
|
Name string
|
||||||
Namespace string
|
Namespace string
|
||||||
Annotations map[string]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
|
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",
|
||||||
|
|||||||
Reference in New Issue
Block a user