Skip to content

Commit

Permalink
add ImagePullSecret property for setting an image pull secret if needed
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Baum <[email protected]>
  • Loading branch information
mikebaum committed May 6, 2024
1 parent e86812c commit 5349bbd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 36 deletions.
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

0 comments on commit 5349bbd

Please sign in to comment.