Skip to content

Commit

Permalink
Prefix in_cluster_config paths with $TELEPRESENCE_ROOT (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
kke authored and jakolehm committed Jan 7, 2019
1 parent 66b9e65 commit 99bc979
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/k8s/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def self.in_cluster_config(**options)
new(
"https://#{host}:#{port}",
ssl_verify_peer: options.key?(:ssl_verify_peer) ? options.delete(:ssl_verify_peer) : true,
ssl_ca_file: options.delete(:ssl_ca_file) || '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt',
auth_token: options.delete(:auth_token) || File.read('/var/run/secrets/kubernetes.io/serviceaccount/token'),
ssl_ca_file: options.delete(:ssl_ca_file) || File.join((ENV['TELEPRESENCE_ROOT'] || '/'), 'var/run/secrets/kubernetes.io/serviceaccount/ca.crt'),
auth_token: options.delete(:auth_token) || File.read(File.join((ENV['TELEPRESENCE_ROOT'] || '/'), 'var/run/secrets/kubernetes.io/serviceaccount/token')),
**options
)
end
Expand Down
13 changes: 13 additions & 0 deletions spec/k8s/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
}

before do
allow(ENV).to receive(:[]).with('TELEPRESENCE_ROOT').and_return(nil)
allow(ENV).to receive(:[]).with('KUBERNETES_SERVICE_HOST').and_return(service_host)
allow(ENV).to receive(:[]).with('KUBERNETES_SERVICE_PORT_HTTPS').and_return(service_port)
allow(File).to receive(:read).with('/var/run/secrets/kubernetes.io/serviceaccount/token').and_return(sa_token)
Expand All @@ -219,6 +220,18 @@
'Authorization' => "Bearer #{sa_token}",
)
end

context 'with telepresence' do
before do
allow(ENV).to receive(:[]).with('TELEPRESENCE_ROOT').and_return('/tmp')
allow(File).to receive(:read).with('/tmp/var/run/secrets/kubernetes.io/serviceaccount/token').and_return(sa_token)
allow(File).to receive(:read).with('/tmp/var/run/secrets/kubernetes.io/serviceaccount/ca.crt').and_return(sa_cacert)
end

it 'uses the correct server' do
subject.server
end
end
end
end

Expand Down

0 comments on commit 99bc979

Please sign in to comment.