Skip to content

Commit

Permalink
fix config init
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinon committed Dec 9, 2021
1 parent ba0fb22 commit de15b72
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Not all kubeconfig options are supported, only the following kubeconfig options
##### With overrides

```crystal
client = Kube::Client.config(K8s::Config.load_file("~/.kube/config"),
client = Kube::Client.config(Kube::Config.load_file("~/.kube/config"),
server: "http://localhost:8001",
)
```
Expand All @@ -93,15 +93,16 @@ This will fetch the API resource lists for all API groups in a single pipelined

```crystal
client.api("v1").resource("pods", namespace: "default").list(label_selector: {"role" => "test"}).each do |pod|
puts "namespace=#{pod.metadata.namespace} pod: #{pod.metadata.name} node=#{pod.spec.node_name}"
pod = pod.as(K8S::Api::Core::V1::Pod)
puts "namespace=#{pod.metadata!.namespace} pod: #{pod.metadata!.name} node=#{pod.spec.try &.node_name}"
end
```

### Updating resources

```crystal
node = client.api("v1").resource("nodes").get("test-node")
node.spec.unschedulable = true
node.as(K8S::Api::Core::V1::Node).spec.not_nil!.unschedulable = true
client.api("v1").resource("nodes").update_resource(node)
```

Expand Down
4 changes: 2 additions & 2 deletions src/kube/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Kube
@version : K8S::Apimachinery::Version::Info? = nil

def self.config(config : Kube::Config, namespace : String? = nil, **options) : Kube::Client
Client.new(Transport.new(config, **options), namespace)
Client.new(Transport.config(config, **options), namespace)
end

# An `Kube::Client` instance from in-cluster config within a kube pod, using the kubernetes service envs and serviceaccount secrets
Expand Down Expand Up @@ -54,7 +54,7 @@ module Kube
File.join(Path.home, ".kube", "config"),
"/etc/kubernetes/admin.conf",
"/etc/kubernetes/kubelet.conf",
].find { |path| File.exist?(path) && File.readable?(path) }
].find { |path| File.exists?(path) && File.readable?(path) }
if found_config
Kube::Config.load_file(found_config)
else
Expand Down
6 changes: 3 additions & 3 deletions src/kube/transport.cr
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ module Kube
new(
"https://#{host}:#{port}",
**options.merge({
ssl_verify_peer: true,
ssl_ca_file: File.join(ENV.fetch("TELEPRESENCE_ROOT", "/"), "var/run/secrets/kubernetes.io/serviceaccount/ca.crt"),
auth_token: File.read(File.join(ENV.fetch("TELEPRESENCE_ROOT", "/"), "var/run/secrets/kubernetes.io/serviceaccount/token")),
verify_ssl: OpenSSL::SSL::VerifyMode::PEER,
ssl_ca_file: File.join(ENV.fetch("TELEPRESENCE_ROOT", "/"), "var/run/secrets/kubernetes.io/serviceaccount/ca.crt"),
auth_token: File.read(File.join(ENV.fetch("TELEPRESENCE_ROOT", "/"), "var/run/secrets/kubernetes.io/serviceaccount/token")),
}),
)
end
Expand Down

0 comments on commit de15b72

Please sign in to comment.