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

Kubernetes adapter - support image pull secret #253

Merged
merged 2 commits into from
Apr 19, 2021
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
1 change: 1 addition & 0 deletions lib/ood_core/job/adapters/kubernetes/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def container_from_native(container, default_env)
cpu: container[:cpu],
working_dir: container[:working_dir],
restart_policy: container[:restart_policy],
image_pull_secret: container[:image_pull_secret]
)
end

Expand Down
6 changes: 4 additions & 2 deletions lib/ood_core/job/adapters/kubernetes/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def initialize(name, filename, data)

class Container
attr_accessor :name, :image, :command, :port, :env, :memory, :cpu, :working_dir,
:restart_policy, :supplemental_groups
:restart_policy, :image_pull_secret, :supplemental_groups

def initialize(
name, image, command: [], port: nil, env: {}, memory: "4Gi", cpu: "1",
working_dir: "", restart_policy: "Never", supplemental_groups: []
working_dir: "", restart_policy: "Never", image_pull_secret: nil, supplemental_groups: []
)
raise ArgumentError, "containers need valid names and images" unless name && image

Expand All @@ -29,6 +29,7 @@ def initialize(
@cpu = cpu.nil? ? "1" : cpu
@working_dir = working_dir.nil? ? "" : working_dir
@restart_policy = restart_policy.nil? ? "Never" : restart_policy
@image_pull_secret = image_pull_secret
@supplemental_groups = supplemental_groups.nil? ? [] : supplemental_groups
end

Expand All @@ -42,6 +43,7 @@ def ==(other)
cpu == other.cpu &&
working_dir == other.working_dir &&
restart_policy == other.restart_policy &&
image_pull_secret == other.image_pull_secret &&
supplemental_groups == other.supplemental_groups
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/ood_core/job/adapters/kubernetes/templates/pod.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ spec:
hostNetwork: false
hostIPC: false
hostPID: false
<%- unless spec.container.image_pull_secret.nil? -%>
imagePullSecrets:
- name: <%= spec.container.image_pull_secret %>
<%- end -%>
containers:
- name: "<%= spec.container.name %>"
image: <%= spec.container.image %>
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/output/k8s/pod_yml_from_all_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ spec:
hostNetwork: false
hostIPC: false
hostPID: false
imagePullSecrets:
- name: docker-registry-secret
containers:
- name: "rspec-test"
image: ruby:2.5
Expand Down
1 change: 1 addition & 0 deletions spec/job/adapters/kubernetes/batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def build_script(opts = {})
container: {
name: 'rspec-test',
image: 'ruby:2.5',
image_pull_secret: 'docker-registry-secret',
command: 'rake spec',
port: 8080,
env: {
Expand Down
43 changes: 37 additions & 6 deletions spec/job/adapters/kubernetes/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@
memory: '12Gi',
cpu: '6',
working_dir: '/over/there',
restart_policy: 'OnFailure'
restart_policy: 'OnFailure',
image_pull_secret: 'docker-registry-secret'
}
}

Expand All @@ -265,7 +266,8 @@
memory: '12Gi',
cpu: '6',
working_dir: '/over/there',
restart_policy: 'OnFailure'
restart_policy: 'OnFailure',
image_pull_secret: 'docker-registry-secret'
)
)
end
Expand All @@ -285,7 +287,8 @@
memory: '12Gi',
cpu: '6',
working_dir: '/over/there',
restart_policy: 'OnFailure'
restart_policy: 'OnFailure',
image_pull_secret: 'docker-registry-secret'
)
)
end
Expand All @@ -305,7 +308,8 @@
memory: '12Gi',
cpu: '6',
working_dir: '/over/there',
restart_policy: 'OnFailure'
restart_policy: 'OnFailure',
image_pull_secret: 'docker-registry-secret'
)
)
end
Expand All @@ -326,7 +330,8 @@
memory: '12Gi',
cpu: '6',
working_dir: '/over/there',
restart_policy: 'OnFailure'
restart_policy: 'OnFailure',
image_pull_secret: 'docker-registry-secret'
)
)
end
Expand All @@ -346,7 +351,8 @@
command: ['rake', 'spec'],
memory: '12Gi',
cpu: '6',
restart_policy: 'OnFailure'
restart_policy: 'OnFailure',
image_pull_secret: 'docker-registry-secret'
)
)
end
Expand All @@ -367,6 +373,30 @@
memory: '12Gi',
cpu: '6',
working_dir: '/over/there',
restart_policy: 'Never',
image_pull_secret: 'docker-registry-secret'
)
)
end

it "correctly parses container with no image_pull_secret" do
ctr_hash.delete(:image_pull_secret)

expect(helper.container_from_native(ctr_hash, default_env)).to eq(
Kubernetes::Resources::Container.new(
'ruby-test-container',
'ruby:2.5',
port: 8080,
command: ['rake', 'spec'],
env: {
HOME: '/over/here',
UID: 1000,
},
memory: '12Gi',
cpu: '6',
working_dir: '/over/there',
restart_policy: 'OnFailure',
image_pull_secret: nil
)
)
end
Expand All @@ -380,6 +410,7 @@
ctr_hash[:cpu] = '1'
ctr_hash[:restart_policy] = 'Never'
ctr_hash[:working_dir] = ''
ctr_hash[:image_pull_secret] = nil

expect(helper.container_from_native(ctr_hash, default_env)).to eq(
Kubernetes::Resources::Container.new(
Expand Down