Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup: Add new imagePullSecret field to CRD #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions api/v1alpha1/onload_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,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 @@ -91,6 +91,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 @@ -53,6 +53,8 @@ spec:
# ServiceAccountName is the name of the service account that the objects
# created by the Onload Operator will use. Required.
serviceAccountName: onload-operator-sa
# imagePullSecret:
# name: secret-name

# Selector defines the set of nodes that this Onload CR will run on. Required.
selector:
Expand Down
8 changes: 7 additions & 1 deletion controllers/onload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,8 @@ func createModule(
Version: onload.Spec.Onload.Version,
},
},
Selector: onload.Spec.Selector,
ImageRepoSecret: onload.Spec.ImagePullSecret,
Selector: onload.Spec.Selector,
},
}

Expand Down Expand Up @@ -1139,6 +1140,7 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
Labels: dsPodLabels,
},
Spec: corev1.PodSpec{
ImagePullSecrets: []corev1.LocalObjectReference{},
ServiceAccountName: onload.Spec.ServiceAccountName,
Containers: []corev1.Container{
devicePluginContainer,
Expand Down Expand Up @@ -1176,6 +1178,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
21 changes: 21 additions & 0 deletions controllers/onload_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,5 +923,26 @@ var _ = Describe("onload controller", func() {
),
)

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"),
})),
)
})
})
})
Loading