Skip to content

Commit f8f1280

Browse files
Cleanup: Add new imagePullSecret field to CRD
1 parent 70fb55e commit f8f1280

File tree

6 files changed

+52
-1
lines changed

6 files changed

+52
-1
lines changed

api/v1alpha1/onload_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ type Spec struct {
151151
// ServiceAccountName is the name of the service account that the objects
152152
// created by the onload operator will use.
153153
ServiceAccountName string `json:"serviceAccountName"`
154+
155+
// +optional
156+
// ImagePullSecret is an optional secret that gets used by the objects
157+
// created by the operator when pulling images from container registries.
158+
ImagePullSecret *v1.LocalObjectReference `json:"imagePullSecret,omitempty"`
154159
}
155160

156161
// OnloadStatus defines the observed state of Onload

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/onload.amd.com_onloads.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ spec:
9494
x-kubernetes-validations:
9595
- message: SetPreload and MountOnload mutually exclusive
9696
rule: '!(self.setPreload && self.mountOnload)'
97+
imagePullSecret:
98+
description: ImagePullSecret is an optional secret that gets used
99+
by the objects created by the operator when pulling images from
100+
container registries.
101+
properties:
102+
name:
103+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
104+
TODO: Add other useful fields. apiVersion, kind, uid?'
105+
type: string
106+
type: object
107+
x-kubernetes-map-type: atomic
97108
onload:
98109
description: Onload is the specification of the version of onload
99110
to be used by this CR

config/samples/onload/base/onload_v1alpha1_onload.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ metadata:
4343
name: onload
4444
spec:
4545
serviceAccountName: onload-operator-sa
46+
# imagePullSecret:
47+
# name: secret-name
4648
selector:
4749
node-role.kubernetes.io/worker: ""
4850
onload:

controllers/onload_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,8 @@ func createModule(
849849
Version: onload.Spec.Onload.Version,
850850
},
851851
},
852-
Selector: onload.Spec.Selector,
852+
ImageRepoSecret: onload.Spec.ImagePullSecret,
853+
Selector: onload.Spec.Selector,
853854
},
854855
}
855856

@@ -1106,6 +1107,7 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
11061107
Labels: dsLabels,
11071108
},
11081109
Spec: corev1.PodSpec{
1110+
ImagePullSecrets: []corev1.LocalObjectReference{},
11091111
ServiceAccountName: onload.Spec.ServiceAccountName,
11101112
Containers: []corev1.Container{
11111113
devicePluginContainer,
@@ -1143,6 +1145,10 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
11431145
},
11441146
}
11451147

1148+
if onload.Spec.ImagePullSecret != nil {
1149+
devicePlugin.Spec.Template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{*onload.Spec.ImagePullSecret}
1150+
}
1151+
11461152
err = controllerutil.SetControllerReference(onload, devicePlugin, r.Scheme)
11471153
if err != nil {
11481154
log.Error(err, "Failed to set controller reference for Device Plugin")

controllers/onload_controller_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,5 +850,27 @@ var _ = Describe("onload controller", func() {
850850
"-libMountPath=qux",
851851
),
852852
)
853+
854+
It("should pass through imagepullsecret", func() {
855+
devicePlugin := appsv1.DaemonSet{}
856+
devicePluginName := types.NamespacedName{
857+
Name: onload.Name + "-onload-device-plugin-ds",
858+
Namespace: onload.Namespace,
859+
}
860+
861+
onload.Spec.ImagePullSecret = &corev1.LocalObjectReference{Name: "Steven"}
862+
Expect(k8sClient.Create(ctx, onload)).To(BeNil())
863+
864+
Eventually(func() bool {
865+
err := k8sClient.Get(ctx, devicePluginName, &devicePlugin)
866+
return err == nil
867+
}, timeout, pollingInterval).Should(BeTrue())
868+
869+
Expect(devicePlugin.Spec.Template.Spec.ImagePullSecrets).Should(
870+
ContainElement(MatchFields(IgnoreExtras, Fields{
871+
"Name": Equal("Steven"),
872+
})),
873+
)
874+
})
853875
})
854876
})

0 commit comments

Comments
 (0)