From 8d5b983b8a940c46cd4f73047d769d75226ce6b8 Mon Sep 17 00:00:00 2001 From: Nema Darban Date: Mon, 24 Oct 2022 03:39:49 -0700 Subject: [PATCH] Support image pull secrets (#145) * define input for imagePullSecrets * assign imagePullSecrets to each job type * update manifest template * add ignore for vscode * take imagePullSecrets out of spec * formatting --- .gitignore | 2 ++ api/v1alpha1/k6_types.go | 23 ++++++++++++----------- api/v1alpha1/zz_generated.deepcopy.go | 5 +++++ config/crd/bases/k6.io_k6s.yaml | 22 ++++++++++++++++++++++ pkg/resources/jobs/initializer.go | 1 + pkg/resources/jobs/runner.go | 1 + pkg/resources/jobs/starter.go | 1 + 7 files changed, 44 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index e0fd5fe1..c813d0f3 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ bin /manager kubebuilder-tools-* + +.vscode diff --git a/api/v1alpha1/k6_types.go b/api/v1alpha1/k6_types.go index 2695c116..5b56321f 100644 --- a/api/v1alpha1/k6_types.go +++ b/api/v1alpha1/k6_types.go @@ -25,17 +25,18 @@ type PodMetadata struct { } type Pod struct { - Affinity *corev1.Affinity `json:"affinity,omitempty"` - AutomountServiceAccountToken string `json:"automountServiceAccountToken,omitempty"` - Env []corev1.EnvVar `json:"env,omitempty"` - Image string `json:"image,omitempty"` - Metadata PodMetadata `json:"metadata,omitempty"` - NodeSelector map[string]string `json:"nodeselector,omitempty"` - Tolerations []corev1.Toleration `json:"tolerations,omitempty"` - Resources corev1.ResourceRequirements `json:"resources,omitempty"` - ServiceAccountName string `json:"serviceAccountName,omitempty"` - SecurityContext corev1.PodSecurityContext `json:"securityContext,omitempty"` - EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"` + Affinity *corev1.Affinity `json:"affinity,omitempty"` + AutomountServiceAccountToken string `json:"automountServiceAccountToken,omitempty"` + Env []corev1.EnvVar `json:"env,omitempty"` + Image string `json:"image,omitempty"` + ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` + Metadata PodMetadata `json:"metadata,omitempty"` + NodeSelector map[string]string `json:"nodeselector,omitempty"` + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + Resources corev1.ResourceRequirements `json:"resources,omitempty"` + ServiceAccountName string `json:"serviceAccountName,omitempty"` + SecurityContext corev1.PodSecurityContext `json:"securityContext,omitempty"` + EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"` } type K6Scuttle struct { diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 778b7423..bc7166b6 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -201,6 +201,11 @@ func (in *Pod) DeepCopyInto(out *Pod) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.ImagePullSecrets != nil { + in, out := &in.ImagePullSecrets, &out.ImagePullSecrets + *out = make([]v1.LocalObjectReference, len(*in)) + copy(*out, *in) + } in.Metadata.DeepCopyInto(&out.Metadata) if in.NodeSelector != nil { in, out := &in.NodeSelector, &out.NodeSelector diff --git a/config/crd/bases/k6.io_k6s.yaml b/config/crd/bases/k6.io_k6s.yaml index c5ddc621..aae74d73 100644 --- a/config/crd/bases/k6.io_k6s.yaml +++ b/config/crd/bases/k6.io_k6s.yaml @@ -848,6 +848,17 @@ spec: type: array image: type: string + imagePullSecrets: + items: + description: LocalObjectReference contains enough information + to let you locate the referenced object inside the same namespace. + 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 + type: array metadata: properties: annotations: @@ -1877,6 +1888,17 @@ spec: type: array image: type: string + imagePullSecrets: + items: + description: LocalObjectReference contains enough information + to let you locate the referenced object inside the same namespace. + 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 + type: array metadata: properties: annotations: diff --git a/pkg/resources/jobs/initializer.go b/pkg/resources/jobs/initializer.go index 40bf7365..06d0f9e3 100644 --- a/pkg/resources/jobs/initializer.go +++ b/pkg/resources/jobs/initializer.go @@ -84,6 +84,7 @@ func NewInitializerJob(k6 *v1alpha1.K6, argLine string) (*batchv1.Job, error) { NodeSelector: k6.Spec.Runner.NodeSelector, Tolerations: k6.Spec.Runner.Tolerations, RestartPolicy: corev1.RestartPolicyNever, + ImagePullSecrets: k6.Spec.Runner.ImagePullSecrets, Containers: []corev1.Container{ { Image: image, diff --git a/pkg/resources/jobs/runner.go b/pkg/resources/jobs/runner.go index ca4773ee..5740a889 100644 --- a/pkg/resources/jobs/runner.go +++ b/pkg/resources/jobs/runner.go @@ -149,6 +149,7 @@ func NewRunnerJob(k6 *v1alpha1.K6, index int, testRunId, token string) (*batchv1 NodeSelector: k6.Spec.Runner.NodeSelector, Tolerations: k6.Spec.Runner.Tolerations, SecurityContext: &k6.Spec.Runner.SecurityContext, + ImagePullSecrets: k6.Spec.Runner.ImagePullSecrets, Containers: []corev1.Container{{ Image: image, Name: "k6", diff --git a/pkg/resources/jobs/starter.go b/pkg/resources/jobs/starter.go index 31a6d5d9..4852e73c 100644 --- a/pkg/resources/jobs/starter.go +++ b/pkg/resources/jobs/starter.go @@ -64,6 +64,7 @@ func NewStarterJob(k6 *v1alpha1.K6, hostname []string) *batchv1.Job { Tolerations: k6.Spec.Starter.Tolerations, RestartPolicy: corev1.RestartPolicyNever, SecurityContext: &k6.Spec.Starter.SecurityContext, + ImagePullSecrets: k6.Spec.Starter.ImagePullSecrets, Containers: []corev1.Container{ containers.NewCurlContainer(hostname, starterImage, command, env), },