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

add ImagePullSecret property for setting an image pull secret if needed #21

Merged
merged 1 commit into from
May 18, 2024
Merged
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
4 changes: 4 additions & 0 deletions api/v1alpha1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type PipelineSpec struct {
// +optional
Image string `json:"image,omitempty"`

// ImagePullSecret is an optional reference to a secret in the same namespace to use for pulling the image used by
// the benthos Pod. Similar to ImagePullSecrets, see v1.PodSpec#ImagePullSecrets.
ImagePullSecret string `json:"imagePullSecret,omitempty"`

// ConfigFiles Additional configuration, as Key/Value pairs, that will be mounted as files with the /config
// directory on the pod. The key should be the file name and the value should be its content.
ConfigFiles map[string]string `json:"configFiles,omitempty"`
Expand Down
7 changes: 6 additions & 1 deletion config/crd/bases/captain.benthos.dev_pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ spec:
directory on the pod. The key should be the file name and the value should be its content.
type: object
env:
description: Env Environment Variable to set in the benthos pipeline
description: Env Environment Variables to set in the benthos pipeline
pod.
items:
description: EnvVar represents an environment variable present in
Expand Down Expand Up @@ -187,6 +187,11 @@ spec:
description: Image defines the image and tag to use for the Benthos
deployment.
type: string
imagePullSecret:
description: |-
ImagePullSecret is an optional reference to a secret in the same namespace to use for pulling the image used by
the benthos Pod. Similar to ImagePullSecrets, see v1.PodSpec#ImagePullSecrets.
type: string
replicas:
description: Replicas defines the amount of replicas to create for
the Benthos deployment.
Expand Down
78 changes: 43 additions & 35 deletions internal/pkg/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,48 @@ func NewDeployment(name string, namespace string, scope captainv1.PipelineSpec)
image = scope.Image
}

podSpec := corev1.PodSpec{
Containers: []corev1.Container{{
Image: image,
ImagePullPolicy: corev1.PullAlways,
Name: "benthos",
Ports: []corev1.ContainerPort{{
ContainerPort: 4195,
Name: "http",
}},
Args: []string{
"-c",
"/config/benthos.yaml",
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "config",
MountPath: "/config",
ReadOnly: true,
},
},
Env: scope.Env,
}},
Volumes: []corev1.Volume{
{
Name: "config",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "benthos-" + name,
},
},
},
},
},
}

if scope.ImagePullSecret != "" {
podSpec.ImagePullSecrets = []corev1.LocalObjectReference{
{Name: scope.ImagePullSecret},
}
}

return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -34,41 +76,7 @@ func NewDeployment(name string, namespace string, scope captainv1.PipelineSpec)
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: image,
ImagePullPolicy: corev1.PullAlways,
Name: "benthos",
Ports: []corev1.ContainerPort{{
ContainerPort: 4195,
Name: "http",
}},
Args: []string{
"-c",
"/config/benthos.yaml",
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "config",
MountPath: "/config",
ReadOnly: true,
},
},
Env: scope.Env,
}},
Volumes: []corev1.Volume{
{
Name: "config",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "benthos-" + name,
},
},
},
},
},
},
Spec: podSpec,
},
},
}
Expand Down
Loading