Skip to content

Commit

Permalink
Add imagePullSecrets to PodSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
Micro committed Apr 23, 2020
1 parent 7345ce9 commit 501a6bf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions runtime/kubernetes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service {
kdeploy.Spec.Template.Metadata.Annotations = make(map[string]string)
}

// set the image pull secrets
kdeploy.Spec.Template.PodSpec.ImagePullSecrets = c.ImagePullSecrets

// create if non existent
if s.Metadata == nil {
s.Metadata = make(map[string]string)
Expand Down
9 changes: 9 additions & 0 deletions runtime/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type CreateOptions struct {
Retries int
// Specify the image to use
Image string
// Specify secrets to use when pulling the image
ImagePullSecrets []string
}

// ReadOptions queries runtime services
Expand All @@ -92,6 +94,13 @@ func CreateImage(img string) CreateOption {
}
}

// CreateImagePullSecret sets a secret to use
func CreateImagePullSecret(secret string) CreateOption {
return func(o *CreateOptions) {
o.ImagePullSecrets = append(o.ImagePullSecrets, secret)
}
}

// WithCommand specifies the command to execute
func WithCommand(cmd ...string) CreateOption {
return func(o *CreateOptions) {
Expand Down
5 changes: 5 additions & 0 deletions util/kubernetes/client/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ spec:
{{- end }}
{{- end }}
spec:
imagePullSecrets:
{{- with .Spec.Template.PodSpec.ImagePullSecrets }}
{{- range . }}
- {{ . }}
{{ end }}
containers:
{{- with .Spec.Template.PodSpec.Containers }}
{{- range . }}
Expand Down
3 changes: 2 additions & 1 deletion util/kubernetes/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ type Metadata struct {

// PodSpec is a pod
type PodSpec struct {
Containers []Container `json:"containers"`
Containers []Container `json:"containers"`
ImagePullSecrets []string `json:"imagePullSecrets"`
}

// PodList
Expand Down

0 comments on commit 501a6bf

Please sign in to comment.