Skip to content

Commit 1b50174

Browse files
Cleanup: Add new imagePullSecret field to CRD
1 parent 4448fa3 commit 1b50174

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
@@ -149,6 +149,11 @@ type Spec struct {
149149
// ServiceAccountName is the name of the service account that the objects
150150
// created by the onload operator will use.
151151
ServiceAccountName string `json:"serviceAccountName"`
152+
153+
// +optional
154+
// ImagePullSecret is an optional secret that gets used by the objects
155+
// created by the operator when pulling images from container registries.
156+
ImagePullSecret *v1.LocalObjectReference `json:"imagePullSecret,omitempty"`
152157
}
153158

154159
// 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
@@ -89,6 +89,17 @@ spec:
8989
x-kubernetes-validations:
9090
- message: SetPreload and MountOnload mutually exclusive
9191
rule: '!(self.setPreload && self.mountOnload)'
92+
imagePullSecret:
93+
description: ImagePullSecret is an optional secret that gets used
94+
by the objects created by the operator when pulling images from
95+
container registries.
96+
properties:
97+
name:
98+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
99+
TODO: Add other useful fields. apiVersion, kind, uid?'
100+
type: string
101+
type: object
102+
x-kubernetes-map-type: atomic
92103
onload:
93104
description: Onload is the specification of the version of onload
94105
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
@@ -862,7 +862,8 @@ func createModule(
862862
Version: onload.Spec.Onload.Version,
863863
},
864864
},
865-
Selector: onload.Spec.Selector,
865+
ImageRepoSecret: onload.Spec.ImagePullSecret,
866+
Selector: onload.Spec.Selector,
866867
},
867868
}
868869

@@ -1119,6 +1120,7 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
11191120
Labels: dsLabels,
11201121
},
11211122
Spec: corev1.PodSpec{
1123+
ImagePullSecrets: []corev1.LocalObjectReference{},
11221124
ServiceAccountName: onload.Spec.ServiceAccountName,
11231125
Containers: []corev1.Container{
11241126
devicePluginContainer,
@@ -1156,6 +1158,10 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
11561158
},
11571159
}
11581160

1161+
if onload.Spec.ImagePullSecret != nil {
1162+
devicePlugin.Spec.Template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{*onload.Spec.ImagePullSecret}
1163+
}
1164+
11591165
err = controllerutil.SetControllerReference(onload, devicePlugin, r.Scheme)
11601166
if err != nil {
11611167
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
@@ -871,5 +871,27 @@ var _ = Describe("onload controller", func() {
871871
"-libMountPath=qux",
872872
),
873873
)
874+
875+
It("should pass through imagepullsecret", func() {
876+
devicePlugin := appsv1.DaemonSet{}
877+
devicePluginName := types.NamespacedName{
878+
Name: onload.Name + "-onload-device-plugin-ds",
879+
Namespace: onload.Namespace,
880+
}
881+
882+
onload.Spec.ImagePullSecret = &corev1.LocalObjectReference{Name: "Steven"}
883+
Expect(k8sClient.Create(ctx, onload)).To(BeNil())
884+
885+
Eventually(func() bool {
886+
err := k8sClient.Get(ctx, devicePluginName, &devicePlugin)
887+
return err == nil
888+
}, timeout, pollingInterval).Should(BeTrue())
889+
890+
Expect(devicePlugin.Spec.Template.Spec.ImagePullSecrets).Should(
891+
ContainElement(MatchFields(IgnoreExtras, Fields{
892+
"Name": Equal("Steven"),
893+
})),
894+
)
895+
})
874896
})
875897
})

0 commit comments

Comments
 (0)