Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion api/v1beta2/job_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ type JobConfig struct {
//
// +optional
VolumeMounts []VolumeMountApplyConfiguration `json:"volumeMounts,omitempty"`

// ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling
// backup and restore job images. This applies specifically to the backup CronJob and restore Job Pods.
// To configure imagePullSecrets for the MySQLCluster's StatefulSet Pods, use `podTemplate.spec.imagePullSecrets` instead.
//
// +optional
ImagePullSecrets []LocalObjectReferenceApplyConfiguration `json:"imagePullSecrets,omitempty"`
}

// VolumeSourceApplyConfiguration is the type defined to implement the DeepCopy method.
Expand Down Expand Up @@ -210,7 +217,7 @@ type BucketConfig struct {
// AffinityApplyConfiguration is the type defined to implement the DeepCopy method.
type AffinityApplyConfiguration corev1ac.AffinityApplyConfiguration

// DeepCopy is copying the receiver, creating a new EnvVarApplyConfiguration.
// DeepCopy is copying the receiver, creating a new AffinityApplyConfiguration.
func (in *AffinityApplyConfiguration) DeepCopy() *AffinityApplyConfiguration {
out := new(AffinityApplyConfiguration)
bytes, err := json.Marshal(in)
Expand All @@ -223,3 +230,20 @@ func (in *AffinityApplyConfiguration) DeepCopy() *AffinityApplyConfiguration {
}
return out
}

// LocalObjectReferenceApplyConfiguration is the type defined to implement the DeepCopy method.
type LocalObjectReferenceApplyConfiguration corev1ac.LocalObjectReferenceApplyConfiguration

// DeepCopy is copying the receiver, creating a new LocalObjectReferenceApplyConfiguration.
func (in *LocalObjectReferenceApplyConfiguration) DeepCopy() *LocalObjectReferenceApplyConfiguration {
out := new(LocalObjectReferenceApplyConfiguration)
bytes, err := json.Marshal(in)
if err != nil {
panic("Failed to marshal")
}
err = json.Unmarshal(bytes, out)
if err != nil {
panic("Failed to unmarshal")
}
return out
}
13 changes: 13 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions charts/moco/templates/generated/crds/moco_crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,15 @@ spec:
type: object
type: object
type: array
imagePullSecrets:
description: ImagePullSecrets is a list of references to...
items:
description: LocalObjectReferenceApplyConfiguration is the...
properties:
name:
type: string
type: object
type: array
maxCpu:
anyOf:
- type: integer
Expand Down Expand Up @@ -6714,6 +6723,15 @@ spec:
type: object
type: object
type: array
imagePullSecrets:
description: ImagePullSecrets is a list of references to...
items:
description: LocalObjectReferenceApplyConfiguration is the...
properties:
name:
type: string
type: object
type: array
maxCpu:
anyOf:
- type: integer
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/moco.cybozu.com_backuppolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,15 @@ spec:
type: object
type: object
type: array
imagePullSecrets:
description: ImagePullSecrets is a list of references to...
items:
description: LocalObjectReferenceApplyConfiguration is the...
properties:
name:
type: string
type: object
type: array
maxCpu:
anyOf:
- type: integer
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/moco.cybozu.com_mysqlclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4823,6 +4823,15 @@ spec:
type: object
type: object
type: array
imagePullSecrets:
description: ImagePullSecrets is a list of references to...
items:
description: LocalObjectReferenceApplyConfiguration is the...
properties:
name:
type: string
type: object
type: array
maxCpu:
anyOf:
- type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,15 @@ spec:
type: object
type: object
type: array
imagePullSecrets:
description: ImagePullSecrets is a list of references to...
items:
description: LocalObjectReferenceApplyConfiguration is the...
properties:
name:
type: string
type: object
type: array
maxCpu:
anyOf:
- type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4823,6 +4823,15 @@ spec:
type: object
type: object
type: array
imagePullSecrets:
description: ImagePullSecrets is a list of references to...
items:
description: LocalObjectReferenceApplyConfiguration is the...
properties:
name:
type: string
type: object
type: array
maxCpu:
anyOf:
- type: integer
Expand Down
16 changes: 16 additions & 0 deletions controllers/mysqlcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,14 @@ func (r *MySQLClusterReconciler) reconcileV1BackupJob(ctx context.Context, req c
}
return volumes
}()...).
WithImagePullSecrets(func() []*corev1ac.LocalObjectReferenceApplyConfiguration {
imagePullSecrets := make([]*corev1ac.LocalObjectReferenceApplyConfiguration, 0, len(jc.ImagePullSecrets))
for _, s := range jc.ImagePullSecrets {
s := s
imagePullSecrets = append(imagePullSecrets, (*corev1ac.LocalObjectReferenceApplyConfiguration)(&s))
}
return imagePullSecrets
}()...).
WithContainers(container).
WithSecurityContext(corev1ac.PodSecurityContext().
WithFSGroup(constants.ContainerGID).
Expand Down Expand Up @@ -1579,6 +1587,14 @@ func (r *MySQLClusterReconciler) reconcileV1RestoreJob(ctx context.Context, req
}
return volumes
}()...).
WithImagePullSecrets(func() []*corev1ac.LocalObjectReferenceApplyConfiguration {
imagePullSecrets := make([]*corev1ac.LocalObjectReferenceApplyConfiguration, 0, len(jc.ImagePullSecrets))
for _, s := range jc.ImagePullSecrets {
s := s
imagePullSecrets = append(imagePullSecrets, (*corev1ac.LocalObjectReferenceApplyConfiguration)(&s))
}
return imagePullSecrets
}()...).
WithContainers(container).
WithSecurityContext(corev1ac.PodSecurityContext().
WithFSGroup(constants.ContainerGID).
Expand Down
10 changes: 10 additions & 0 deletions controllers/mysqlcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func testNewBackUpPolicy() *mocov1beta2.BackupPolicy {
MountPath: ptr.To[string]("/path/to/dir"),
},
}
jc.ImagePullSecrets = []mocov1beta2.LocalObjectReferenceApplyConfiguration{
{Name: ptr.To[string]("my-registry-secret")},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shunki-fujita
Please update your branch with the latest changes from main.
Also, please replace the k8s.io/utils/ptr.To() calls with Go 1.26's new new(expr) builtin once you've updated. That would let us drop the k8s.io/utils/ptr dependency here.

}
jc.BucketConfig.BucketName = "mybucket"
jc.BucketConfig.EndpointURL = "https://foo.bar.baz"
jc.BucketConfig.Region = "us-east-1"
Expand Down Expand Up @@ -1421,6 +1424,8 @@ dummyKey: dummyValue
Expect(js.Template.Spec.Affinity).NotTo(BeNil())
Expect(js.Template.Spec.RestartPolicy).To(Equal(corev1.RestartPolicyNever))
Expect(js.Template.Spec.ServiceAccountName).To(Equal("foo"))
Expect(js.Template.Spec.ImagePullSecrets).To(HaveLen(1))
Expect(js.Template.Spec.ImagePullSecrets[0].Name).To(Equal("my-registry-secret"))
Expect(js.Template.Spec.Volumes).To(HaveLen(2))
Expect(js.Template.Spec.Volumes[0].EmptyDir).NotTo(BeNil())
Expect(js.Template.Spec.Volumes[1].EmptyDir).NotTo(BeNil())
Expand Down Expand Up @@ -1621,6 +1626,9 @@ dummyKey: dummyValue
MountPath: ptr.To[string]("/path/to/dir"),
},
}
jc.ImagePullSecrets = []mocov1beta2.LocalObjectReferenceApplyConfiguration{
{Name: ptr.To[string]("my-registry-secret")},
}
jc.BucketConfig.BucketName = "mybucket"
jc.BucketConfig.EndpointURL = "https://foo.bar.baz"
jc.BucketConfig.Region = "us-east-1"
Expand Down Expand Up @@ -1654,6 +1662,8 @@ dummyKey: dummyValue
Expect(js.Template.Labels).NotTo(BeEmpty())
Expect(js.Template.Spec.RestartPolicy).To(Equal(corev1.RestartPolicyNever))
Expect(js.Template.Spec.ServiceAccountName).To(Equal("foo"))
Expect(js.Template.Spec.ImagePullSecrets).To(HaveLen(1))
Expect(js.Template.Spec.ImagePullSecrets[0].Name).To(Equal("my-registry-secret"))
Expect(js.Template.Spec.Volumes).To(HaveLen(2))
Expect(js.Template.Spec.Volumes[0].EmptyDir).NotTo(BeNil())
Expect(js.Template.Spec.Volumes[1].EmptyDir).NotTo(BeNil())
Expand Down
1 change: 1 addition & 0 deletions docs/crd_backuppolicy_v1beta2.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ JobConfig is a set of parameters for backup and restore job Pods.
| affinity | If specified, the pod's scheduling constraints. | *[AffinityApplyConfiguration](https://pkg.go.dev/k8s.io/client-go/applyconfigurations/core/v1#AffinityApplyConfiguration) | false |
| volumes | Volumes defines the list of volumes that can be mounted by containers in the Pod. | []VolumeApplyConfiguration | false |
| volumeMounts | VolumeMounts describes a list of volume mounts that are to be mounted in a container. | []VolumeMountApplyConfiguration | false |
| imagePullSecrets | ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling backup and restore job images. This applies specifically to the backup CronJob and restore Job Pods. To configure imagePullSecrets for the MySQLCluster's StatefulSet Pods, use `podTemplate.spec.imagePullSecrets` instead. | []LocalObjectReferenceApplyConfiguration | false |

[Back to Custom Resources](#custom-resources)
1 change: 1 addition & 0 deletions docs/crd_mysqlcluster_v1beta2.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,6 @@ JobConfig is a set of parameters for backup and restore job Pods.
| affinity | If specified, the pod's scheduling constraints. | *[AffinityApplyConfiguration](https://pkg.go.dev/k8s.io/client-go/applyconfigurations/core/v1#AffinityApplyConfiguration) | false |
| volumes | Volumes defines the list of volumes that can be mounted by containers in the Pod. | []VolumeApplyConfiguration | false |
| volumeMounts | VolumeMounts describes a list of volume mounts that are to be mounted in a container. | []VolumeMountApplyConfiguration | false |
| imagePullSecrets | ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling backup and restore job images. This applies specifically to the backup CronJob and restore Job Pods. To configure imagePullSecrets for the MySQLCluster's StatefulSet Pods, use `podTemplate.spec.imagePullSecrets` instead. | []LocalObjectReferenceApplyConfiguration | false |

[Back to Custom Resources](#custom-resources)
Loading