Skip to content

Commit db81820

Browse files
tcrawley-xilinxThomas Crawley
authored andcommitted
Cleanup: Add new imagePullSecret field to CRD
1 parent eabdb17 commit db81820

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

api/v1alpha1/onload_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ type Spec struct {
165165
// ServiceAccountName is the name of the service account that the objects
166166
// created by the Onload Operator will use.
167167
ServiceAccountName string `json:"serviceAccountName"`
168+
169+
// +optional
170+
// ImagePullSecret is an optional secret that gets used by the objects
171+
// created by the operator when pulling images from container registries.
172+
// Used by both the Modules (as the ImageRepoSecret field) and the Daemonset
173+
// (as the ImagePullSecrets field) created by the container.
174+
ImagePullSecret *v1.LocalObjectReference `json:"imagePullSecret,omitempty"`
168175
}
169176

170177
// 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ spec:
9191
x-kubernetes-validations:
9292
- message: SetPreload and MountOnload mutually exclusive
9393
rule: '!(self.setPreload && self.mountOnload)'
94+
imagePullSecret:
95+
description: ImagePullSecret is an optional secret that gets used
96+
by the objects created by the operator when pulling images from
97+
container registries. Used by both the Modules (as the ImageRepoSecret
98+
field) and the Daemonset (as the ImagePullSecrets field) created
99+
by the container.
100+
properties:
101+
name:
102+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
103+
TODO: Add other useful fields. apiVersion, kind, uid?'
104+
type: string
105+
type: object
106+
x-kubernetes-map-type: atomic
94107
onload:
95108
description: Onload is the specification of the version of Onload
96109
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
@@ -53,6 +53,8 @@ spec:
5353
# ServiceAccountName is the name of the service account that the objects
5454
# created by the Onload Operator will use. Required.
5555
serviceAccountName: onload-operator-sa
56+
# imagePullSecret:
57+
# name: secret-name
5658

5759
# Selector defines the set of nodes that this Onload CR will run on. Required.
5860
selector:

controllers/onload_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,8 @@ func createModule(
869869
Version: onload.Spec.Onload.Version,
870870
},
871871
},
872-
Selector: onload.Spec.Selector,
872+
ImageRepoSecret: onload.Spec.ImagePullSecret,
873+
Selector: onload.Spec.Selector,
873874
},
874875
}
875876

@@ -1139,6 +1140,7 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
11391140
Labels: dsPodLabels,
11401141
},
11411142
Spec: corev1.PodSpec{
1143+
ImagePullSecrets: []corev1.LocalObjectReference{},
11421144
ServiceAccountName: onload.Spec.ServiceAccountName,
11431145
Containers: []corev1.Container{
11441146
devicePluginContainer,
@@ -1176,6 +1178,10 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
11761178
},
11771179
}
11781180

1181+
if onload.Spec.ImagePullSecret != nil {
1182+
devicePlugin.Spec.Template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{*onload.Spec.ImagePullSecret}
1183+
}
1184+
11791185
err = controllerutil.SetControllerReference(onload, devicePlugin, r.Scheme)
11801186
if err != nil {
11811187
log.Error(err, "Failed to set controller reference for Device Plugin")

controllers/onload_controller_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,5 +923,26 @@ var _ = Describe("onload controller", func() {
923923
),
924924
)
925925

926+
It("should pass through imagepullsecret", func() {
927+
devicePlugin := appsv1.DaemonSet{}
928+
devicePluginName := types.NamespacedName{
929+
Name: onload.Name + "-onload-device-plugin-ds",
930+
Namespace: onload.Namespace,
931+
}
932+
933+
onload.Spec.ImagePullSecret = &corev1.LocalObjectReference{Name: "Steven"}
934+
Expect(k8sClient.Create(ctx, onload)).To(BeNil())
935+
936+
Eventually(func() bool {
937+
err := k8sClient.Get(ctx, devicePluginName, &devicePlugin)
938+
return err == nil
939+
}, timeout, pollingInterval).Should(BeTrue())
940+
941+
Expect(devicePlugin.Spec.Template.Spec.ImagePullSecrets).Should(
942+
ContainElement(MatchFields(IgnoreExtras, Fields{
943+
"Name": Equal("Steven"),
944+
})),
945+
)
946+
})
926947
})
927948
})

0 commit comments

Comments
 (0)