Skip to content

Commit

Permalink
add image pull secret
Browse files Browse the repository at this point in the history
  • Loading branch information
namesoname committed Feb 14, 2024
1 parent 95398eb commit 8f469c9
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion charts/k8up/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords:
- backup
- operator
- restic
version: 4.4.3
version: 4.4.4
sources:
- https://github.com/k8up-io/k8up
maintainers:
Expand Down
6 changes: 3 additions & 3 deletions charts/k8up/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# k8up

![Version: 4.4.3](https://img.shields.io/badge/Version-4.4.3-informational?style=flat-square)
![Version: 4.4.4](https://img.shields.io/badge/Version-4.4.4-informational?style=flat-square)

Kubernetes and OpenShift Backup Operator based on restic

Expand All @@ -13,7 +13,7 @@ helm repo add k8up-io https://k8up-io.github.io/k8up
helm install k8up k8up-io/k8up
```
```bash
kubectl apply -f https://github.com/k8up-io/k8up/releases/download/k8up-4.4.3/k8up-crd.yaml
kubectl apply -f https://github.com/k8up-io/k8up/releases/download/k8up-4.4.4/k8up-crd.yaml
```

<!---
Expand Down Expand Up @@ -53,7 +53,7 @@ Document your changes in values.yaml and let `make docs:helm` generate this sect
| k8up.backupImage.repository | string | `""` | The backup runner image repository. Defaults to `{image.registry}/{image.repository}`. Specify an image repository including registry, e.g. `example.com/repo/image` |
| k8up.backupImage.tag | string | `""` | The backup runner image tag Defaults to `{image.tag}` |
| k8up.enableLeaderElection | bool | `true` | Specifies whether leader election should be enabled. |
| k8up.envVars | list | `[]` | envVars allows the specification of additional environment variables. See [values.yaml](values.yaml) how to specify See documentation which variables are supported. |
| k8up.envVars | list | `[]` | envVars allows the specification of additional environment variables. See [values.yaml](values.yaml) how to specify See documentation which variables are supported. List of names of imagePullSecrets for backupImage Example: imagePullSecrets: "one_secret, two_secret" |
| k8up.globalResources | object | empty values | Specify the resource requests and limits that the Pods should have when they are scheduled by K8up. You are still able to override those via K8up resources, but this gives cluster administrators custom defaults. |
| k8up.globalResources.limits.cpu | string | `""` | Global CPU resource limit applied to jobs. See [supported units][resource-units]. |
| k8up.globalResources.limits.memory | string | `""` | Global Memory resource limit applied to jobs. See [supported units][resource-units]. |
Expand Down
4 changes: 4 additions & 0 deletions charts/k8up/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ spec:
env:
- name: BACKUP_IMAGE
value: "{{ include "k8up.backupImage" . }}"
{{- with .Values.k8up.imagePullSecrets }}
- name: IMAGE_SECRETS
value: "{{ . }}"
{{- end }}
{{- with .Values.k8up.timezone }}
- name: TZ
value: {{ . }}
Expand Down
4 changes: 4 additions & 0 deletions charts/k8up/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ k8up:
# -- envVars allows the specification of additional environment variables.
# See [values.yaml](values.yaml) how to specify
# See documentation which variables are supported.

# List of names of imagePullSecrets for backupImage
# Example:
# imagePullSecrets: "one_secret, two_secret"
envVars: []
# - name: BACKUP_GLOBALACCESSKEYID
# valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
leaderElectionID = "d2ab61da.syn.tools"
argCommandRestic = "command-restic"
argResticOptions = "restic-options"
listImageSecrets = "ImageSecretPulls"
)

var (
Expand Down Expand Up @@ -64,6 +65,7 @@ var (
&cli.StringFlag{Destination: &cfg.Config.GlobalMemoryResourceLimit, Name: "global-memory-limit", EnvVars: []string{"BACKUP_GLOBAL_MEMORY_LIMIT"}, Usage: "set the memory limit for scheduled jobs"},

&cli.StringFlag{Destination: &cfg.Config.BackupImage, Name: "image", EnvVars: []string{"BACKUP_IMAGE"}, Value: "ghcr.io/k8up-io/k8up:latest", Usage: "URL of the restic image"},
&cli.StringSliceFlag{Name: listImageSecrets, EnvVars: []string{"IMAGE_SECRETS"}, Usage: "Secrets for access to $BACKUP_IMAGE"},
&cli.StringSliceFlag{Name: argCommandRestic, EnvVars: []string{"BACKUP_COMMAND_RESTIC"}, Value: cli.NewStringSlice("/usr/local/bin/k8up", "restic"), Usage: "The command that is executed for restic backups."},
&cli.StringSliceFlag{Name: argResticOptions, EnvVars: []string{"BACKUP_RESTIC_OPTIONS"}, Usage: "Pass custom restic options in the form 'key=value,key2=value2'. See https://restic.readthedocs.io/en/stable/manual_rest.html?highlight=--option#usage-help"},
&cli.StringFlag{Destination: &cfg.Config.MountPath, Name: "datapath", Aliases: []string{"mountpath"}, EnvVars: []string{"BACKUP_DATAPATH"}, Value: "/data", Usage: "to which path the PVCs should get mounted in the backup container"},
Expand Down Expand Up @@ -91,6 +93,7 @@ func operatorMain(c *cli.Context) error {

cfg.Config.BackupCommandRestic = c.StringSlice(argCommandRestic)
cfg.Config.ResticOptions = strings.Join(c.StringSlice(argResticOptions), ",")
cfg.Config.ImageSecrets = c.StringSlice(listImageSecrets)

err := validateQuantityFlags(c)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions operator/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Configuration struct {
GlobalMemoryResourceRequest string
GlobalMemoryResourceLimit string
BackupImage string
ImageSecrets []string
BackupCommandRestic []string
MetricsBindAddress string
PodExecRoleName string
Expand Down
8 changes: 8 additions & 0 deletions operator/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ func MutateBatchJob(batchJob *batchv1.Job, jobObj k8upv1.JobObject, config Confi
batchJob.Spec.Template.Spec.RestartPolicy = corev1.RestartPolicyOnFailure
batchJob.Spec.Template.Spec.SecurityContext = jobObj.GetPodSecurityContext()

if len(cfg.Config.ImageSecrets) != 0 {
var imPulSecs []corev1.LocalObjectReference
for _, secret := range cfg.Config.ImageSecrets {
imPulSecs = append(imPulSecs, corev1.LocalObjectReference{Name: secret})
}
batchJob.Spec.Template.Spec.ImagePullSecrets = imPulSecs
}

containers := batchJob.Spec.Template.Spec.Containers
if len(containers) == 0 {
containers = make([]corev1.Container, 1)
Expand Down
1 change: 1 addition & 0 deletions restic/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Configuration struct {
ResticBin string
ResticRepository string
ResticOptions string
ImageSecrets []string

RestoreDir string
RestoreS3Endpoint string
Expand Down

0 comments on commit 8f469c9

Please sign in to comment.