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

uninitialized constant Kubeclient::GoogleApplicationDefaultCredentials #324

Closed
Stono opened this issue May 14, 2018 · 6 comments
Closed

Comments

@Stono
Copy link

Stono commented May 14, 2018

Hey:

require 'helpers/tcp'
require 'kubeclient'
require 'googleauth'

RSpec.describe '#at-to-gcp' do                                                                                                                                                             before do
  auth_options = {
        bearer_token: Kubeclient::GoogleApplicationDefaultCredentials.token                                                                                                                     
  }
end

Gives me:

  1) #at-to-gcp when the echo-server service is running should be able to establish a tcp connection
     Failure/Error: bearer_token: Kubeclient::GoogleApplicationDefaultCredentials.token

     NameError:
       uninitialized constant Kubeclient::GoogleApplicationDefaultCredentials
     # ./spec/at_to_gcp.spec:9:in `block (2 levels) in <top (required)>'

Gemfile:

❯ cat Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem 'rspec'
gem 'kubeclient'
gem 'googleauth'

any ideas?

@moolitayer
Copy link
Collaborator

As far as I can tell we have no released version with the feature you are using.

@Stono are you looking to have this feature included in a release?

@Stono
Copy link
Author

Stono commented May 15, 2018

@moolitayer
Copy link
Collaborator

The README at github reflects master. If you want to view the README for the version you are using it's best to view the one distributed with the gem.

Anyway I understand a new release is required. I will try to get to that tomorrow. Please bug me if you get no response.
cc @cben

@Stono
Copy link
Author

Stono commented May 15, 2018

Ah that makes sense, thank you :-) I've worked around it for now so no rush:

module Helpers
  module Kubernetes
    def cluster(project_id, zone, cluster_id)
      return @cluster if not @cluster.nil?

      scopes = [
        'https://www.googleapis.com/auth/cloud-platform'
      ]
      service = Google::Apis::ContainerV1::ContainerService.new
      service.authorization = Google::Auth.get_application_default(scopes)

      cluster_info = service.get_zone_cluster(project_id, zone, cluster_id).to_h
      master_endpoint = "https://#{cluster_info[:endpoint]}"

      cert_store = OpenSSL::X509::Store.new
      master_ca = cluster_info[:master_auth][:cluster_ca_certificate]
      master_ca = Base64.decode64(master_ca)
      cert_store.add_cert(OpenSSL::X509::Certificate.new(master_ca))

      ssl_options = {
        cert_store: cert_store,
        verify_ssl: OpenSSL::SSL::VERIFY_PEER
      }

      log("Using #{master_endpoint} as Kubernetes host")
      auth_options = {
        bearer_token: service.authorization.access_token
      }

      @cluster = Kubeclient::Client.new(
        master_endpoint,
        'v1',
        auth_options: auth_options,
        ssl_options: ssl_options
      )
      @cluster
    end
  end
end

@cben
Copy link
Collaborator

cben commented May 27, 2018

We just released 3.1.0 that should include this (changelog: #328). Please test.

@cben
Copy link
Collaborator

cben commented Jun 27, 2018

Closing as I believe this is solved — 3.1.* releases contain Kubeclient::GoogleApplicationDefaultCredentials.

@cben cben closed this as completed Jun 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants