Skip to content

Commit b84fc72

Browse files
authored
Merge pull request #57 from pablochacin/add-image-pull-policy-option
Add ImagePullPolicy option to containers
2 parents 7fc194a + 71e4c1d commit b84fc72

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

pkg/jobs/jobs.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type JobOptions struct {
3838
Name string
3939
NodeName string
4040
Image string
41+
PullPolicy coreV1.PullPolicy
4142
Command []string
4243
RestartPolicy coreV1.RestartPolicy
4344
Wait string
@@ -103,17 +104,17 @@ func (obj *Jobs) Apply(yaml string, namespace string) (v1.Job, error) {
103104
// Create creates the Kubernetes resource given the supplied object
104105
func (obj *Jobs) Create(options JobOptions) (v1.Job, error) {
105106
container := coreV1.Container{
106-
Name: options.Name,
107-
Image: options.Image,
108-
Command: options.Command,
107+
Name: options.Name,
108+
Image: options.Image,
109+
ImagePullPolicy: options.PullPolicy,
110+
Command: options.Command,
109111
}
110112

111113
containers := []coreV1.Container{
112114
container,
113115
}
114116

115117
var restartPolicy coreV1.RestartPolicy = "Never"
116-
117118
if options.RestartPolicy != "" {
118119
restartPolicy = options.RestartPolicy
119120
}

pkg/pods/pods.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ type ExecResult struct {
5454

5555
// ContainerOptions describes a container to be started in a pod
5656
type ContainerOptions struct {
57-
Name string // name of the container
58-
Image string // image to be attached
57+
Name string // name of the container
58+
Image string // image to be attached
59+
PullPolicy k8sTypes.PullPolicy
5960
Command []string // command to be executed by the container
6061
Capabilities []string // capabilities to be added to the container's security context
6162
}
@@ -70,9 +71,10 @@ type Pods struct {
7071

7172
// PodOptions describe a Pod to be executed
7273
type PodOptions struct {
73-
Namespace string // namespace where the pod will be executed
74-
Name string // name of the pod
75-
Image string // image to be executed by the pod's container
74+
Namespace string // namespace where the pod will be executed
75+
Name string // name of the pod
76+
Image string // image to be executed by the pod's container
77+
PullPolicy k8sTypes.PullPolicy
7678
Command []string // command to be executed by the pod's container and its arguments
7779
RestartPolicy k8sTypes.RestartPolicy // policy for restarting containers in the pod [Always|OnFailure|Never]
7880
Wait string // timeout for waiting until the pod is running
@@ -124,9 +126,10 @@ func (obj *Pods) IsTerminating(name, namespace string) (bool, error) {
124126
// Create runs a pod specified by the options
125127
func (obj *Pods) Create(options PodOptions) (k8sTypes.Pod, error) {
126128
container := k8sTypes.Container{
127-
Name: options.Name,
128-
Image: options.Image,
129-
Command: options.Command,
129+
Name: options.Name,
130+
Image: options.Image,
131+
ImagePullPolicy: options.PullPolicy,
132+
Command: options.Command,
130133
}
131134

132135
containers := []k8sTypes.Container{
@@ -312,11 +315,12 @@ func generateEphemeralContainer(o ContainerOptions) *k8sTypes.EphemeralContainer
312315

313316
return &k8sTypes.EphemeralContainer{
314317
EphemeralContainerCommon: k8sTypes.EphemeralContainerCommon{
315-
Name: o.Name,
316-
Image: o.Image,
317-
Command: o.Command,
318-
TTY: true,
319-
Stdin: true,
318+
Name: o.Name,
319+
Image: o.Image,
320+
ImagePullPolicy: o.PullPolicy,
321+
Command: o.Command,
322+
TTY: true,
323+
Stdin: true,
320324
SecurityContext: &k8sTypes.SecurityContext{
321325
Capabilities: &k8sTypes.Capabilities{
322326
Add: capabilities,

0 commit comments

Comments
 (0)