Skip to content

Commit

Permalink
Cleanup: Add new imagePullSecret field to CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
tcrawley-xilinx committed Jan 11, 2024
1 parent 4448fa3 commit d6aa14d
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
7 changes: 7 additions & 0 deletions api/v1alpha1/onload_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ type Spec struct {
// ServiceAccountName is the name of the service account that the objects
// created by the onload operator will use.
ServiceAccountName string `json:"serviceAccountName"`

// +optional
// ImagePullSecret is an optional secret that gets used by the objects
// created by the operator when pulling images from container registries.
// Used by both the Modules (as the ImageRepoSecret field) and the Daemonset
// (as the ImagePullSecrets field) created by the container.
ImagePullSecret *v1.LocalObjectReference `json:"imagePullSecret,omitempty"`
}

// OnloadStatus defines the observed state of Onload
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

13 changes: 13 additions & 0 deletions config/crd/bases/onload.amd.com_onloads.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ spec:
x-kubernetes-validations:
- message: SetPreload and MountOnload mutually exclusive
rule: '!(self.setPreload && self.mountOnload)'
imagePullSecret:
description: ImagePullSecret is an optional secret that gets used
by the objects created by the operator when pulling images from
container registries. Used by both the Modules (as the ImageRepoSecret
field) and the Daemonset (as the ImagePullSecrets field) created
by the container.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
x-kubernetes-map-type: atomic
onload:
description: Onload is the specification of the version of onload
to be used by this CR
Expand Down
2 changes: 2 additions & 0 deletions config/samples/onload/base/onload_v1alpha1_onload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ metadata:
name: onload
spec:
serviceAccountName: onload-operator-sa
# imagePullSecret:
# name: secret-name
selector:
node-role.kubernetes.io/worker: ""
onload:
Expand Down
8 changes: 7 additions & 1 deletion controllers/onload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ func createModule(
Version: onload.Spec.Onload.Version,
},
},
Selector: onload.Spec.Selector,
ImageRepoSecret: onload.Spec.ImagePullSecret,
Selector: onload.Spec.Selector,
},
}

Expand Down Expand Up @@ -1119,6 +1120,7 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
Labels: dsLabels,
},
Spec: corev1.PodSpec{
ImagePullSecrets: []corev1.LocalObjectReference{},
ServiceAccountName: onload.Spec.ServiceAccountName,
Containers: []corev1.Container{
devicePluginContainer,
Expand Down Expand Up @@ -1156,6 +1158,10 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
},
}

if onload.Spec.ImagePullSecret != nil {
devicePlugin.Spec.Template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{*onload.Spec.ImagePullSecret}
}

err = controllerutil.SetControllerReference(onload, devicePlugin, r.Scheme)
if err != nil {
log.Error(err, "Failed to set controller reference for Device Plugin")
Expand Down
22 changes: 22 additions & 0 deletions controllers/onload_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,5 +871,27 @@ var _ = Describe("onload controller", func() {
"-libMountPath=qux",
),
)

It("should pass through imagepullsecret", func() {
devicePlugin := appsv1.DaemonSet{}
devicePluginName := types.NamespacedName{
Name: onload.Name + "-onload-device-plugin-ds",
Namespace: onload.Namespace,
}

onload.Spec.ImagePullSecret = &corev1.LocalObjectReference{Name: "Steven"}
Expect(k8sClient.Create(ctx, onload)).To(BeNil())

Eventually(func() bool {
err := k8sClient.Get(ctx, devicePluginName, &devicePlugin)
return err == nil
}, timeout, pollingInterval).Should(BeTrue())

Expect(devicePlugin.Spec.Template.Spec.ImagePullSecrets).Should(
ContainElement(MatchFields(IgnoreExtras, Fields{
"Name": Equal("Steven"),
})),
)
})
})
})

0 comments on commit d6aa14d

Please sign in to comment.