kuby-eks 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +14 -0
- data/LICENSE +21 -0
- data/Rakefile +14 -0
- data/kuby-eks.gemspec +21 -0
- data/lib/kuby/eks.rb +10 -0
- data/lib/kuby/eks/config.rb +11 -0
- data/lib/kuby/eks/provider.rb +124 -0
- data/lib/kuby/eks/version.rb +5 -0
- metadata +93 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 535a85c908e83e1a62bb3fa0c51c5f61af955205c265f408bee09be7bd7ad328
         | 
| 4 | 
            +
              data.tar.gz: 137b6e800231b10e304e93d5ef723450320884571625c1e9ebb190c1ce801a92
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: aa451b6a7aa43879170b2e5d2c4d2ef3620348a005afcfc730cad536de0d4a67be93b01527eb988d2cc218fca59ba0c63bf2fe74adbf5622e5ced9a8cc84796a
         | 
| 7 | 
            +
              data.tar.gz: e5575e4f1c9f70ea62f450e32ace593e35889ed92ac2e5dc8cfe16c02cc9b7a392d40f9bb3091545188c19b37f5d62e70ecaf1670951dcb95214f6b8420e241b
         | 
    
        data/CHANGELOG.md
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            The MIT License (MIT)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) 2020 Cameron Dutro
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 6 | 
            +
            of this software and associated documentation files (the "Software"), to deal
         | 
| 7 | 
            +
            in the Software without restriction, including without limitation the rights
         | 
| 8 | 
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 9 | 
            +
            copies of the Software, and to permit persons to whom the Software is
         | 
| 10 | 
            +
            furnished to do so, subject to the following conditions:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            The above copyright notice and this permission notice shall be included in all
         | 
| 13 | 
            +
            copies or substantial portions of the Software.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 16 | 
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 17 | 
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 18 | 
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 19 | 
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 20 | 
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         | 
| 21 | 
            +
            SOFTWARE.
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            require 'bundler'
         | 
| 2 | 
            +
            require 'rspec/core/rake_task'
         | 
| 3 | 
            +
            require 'rubygems/package_task'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            require 'kuby/eks'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Bundler::GemHelper.install_tasks
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            task default: :spec
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            desc 'Run specs'
         | 
| 12 | 
            +
            RSpec::Core::RakeTask.new do |t|
         | 
| 13 | 
            +
              t.pattern = './spec/**/*_spec.rb'
         | 
| 14 | 
            +
            end
         | 
    
        data/kuby-eks.gemspec
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            $:.unshift File.join(File.dirname(__FILE__), 'lib')
         | 
| 2 | 
            +
            require 'kuby/eks/version'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Gem::Specification.new do |s|
         | 
| 5 | 
            +
              s.name     = 'kuby-eks'
         | 
| 6 | 
            +
              s.version  = ::Kuby::EKS::VERSION
         | 
| 7 | 
            +
              s.authors  = ['Cameron Dutro']
         | 
| 8 | 
            +
              s.email    = ['camertron@gmail.com']
         | 
| 9 | 
            +
              s.homepage = 'http://github.com/getkuby/kuby-eks'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              s.description = s.summary = 'Amazon EKS provider for Kuby.'
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              s.platform = Gem::Platform::RUBY
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              s.add_dependency 'kube-dsl', '~> 0.1'
         | 
| 16 | 
            +
              s.add_dependency 'aws-sdk-eks', '~> 1.38'
         | 
| 17 | 
            +
              s.add_dependency 'aws-iam-authenticator-rb', '~> 0.1'
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              s.require_path = 'lib'
         | 
| 20 | 
            +
              s.files = Dir['{lib,spec}/**/*', 'Gemfile', 'LICENSE', 'CHANGELOG.md', 'README.md', 'Rakefile', 'kuby-eks.gemspec']
         | 
| 21 | 
            +
            end
         | 
    
        data/lib/kuby/eks.rb
    ADDED
    
    
| @@ -0,0 +1,124 @@ | |
| 1 | 
            +
            require 'fileutils'
         | 
| 2 | 
            +
            require 'aws-sdk-eks'
         | 
| 3 | 
            +
            require 'aws-iam-authenticator-rb'
         | 
| 4 | 
            +
            require 'yaml'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module Kuby
         | 
| 7 | 
            +
              module EKS
         | 
| 8 | 
            +
                class Provider < Kuby::Kubernetes::Provider
         | 
| 9 | 
            +
                  STORAGE_CLASS_NAME = 'gp2'.freeze
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  attr_reader :config
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def configure(&block)
         | 
| 14 | 
            +
                    config.instance_eval(&block)
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def kubeconfig_path
         | 
| 18 | 
            +
                    @kubeconfig_path ||= kubeconfig_dir.join(
         | 
| 19 | 
            +
                      "#{definition.app_name.downcase}-kubeconfig.yaml"
         | 
| 20 | 
            +
                    ).to_s
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  def after_configuration
         | 
| 24 | 
            +
                    refresh_kubeconfig
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  def storage_class_name
         | 
| 28 | 
            +
                    STORAGE_CLASS_NAME
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  private
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def after_initialize
         | 
| 34 | 
            +
                    @config = Config.new
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  # Double .credentials call here to convert instance into
         | 
| 38 | 
            +
                  # a Credentials object, which contains an access key ID
         | 
| 39 | 
            +
                  # and a secret access key. All the various credentials
         | 
| 40 | 
            +
                  # objects respond to this method, including
         | 
| 41 | 
            +
                  # SharedCredentials, InstanceProfileCredentials, etc.
         | 
| 42 | 
            +
                  #
         | 
| 43 | 
            +
                  # See: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Credentials.html
         | 
| 44 | 
            +
                  #
         | 
| 45 | 
            +
                  def credentials
         | 
| 46 | 
            +
                    config.credentials.credentials
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  def client
         | 
| 50 | 
            +
                    @client ||= ::Aws::EKS::Client.new(
         | 
| 51 | 
            +
                      region: config.region,
         | 
| 52 | 
            +
                      credentials: config.credentials
         | 
| 53 | 
            +
                    )
         | 
| 54 | 
            +
                  end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  def refresh_kubeconfig
         | 
| 57 | 
            +
                    return unless should_refresh_kubeconfig?
         | 
| 58 | 
            +
                    FileUtils.mkdir_p(kubeconfig_dir)
         | 
| 59 | 
            +
                    Kuby.logger.info('Refreshing kubeconfig...')
         | 
| 60 | 
            +
                    File.write(kubeconfig_path, YAML.dump(kubeconfig))
         | 
| 61 | 
            +
                    Kuby.logger.info('Successfully refreshed kubeconfig!')
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  def kubeconfig
         | 
| 65 | 
            +
                    @kubeconfig ||= {
         | 
| 66 | 
            +
                      'apiVersion' => 'v1',
         | 
| 67 | 
            +
                      'clusters' => [{
         | 
| 68 | 
            +
                        'cluster' => {
         | 
| 69 | 
            +
                          'server' => cluster.endpoint,
         | 
| 70 | 
            +
                          'certificate-authority-data' => cluster.certificate_authority.data
         | 
| 71 | 
            +
                        },
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                        'name' => 'kubernetes'
         | 
| 74 | 
            +
                      }],
         | 
| 75 | 
            +
                      'contexts' => [{
         | 
| 76 | 
            +
                        'context' => {
         | 
| 77 | 
            +
                          'cluster' => 'kubernetes',
         | 
| 78 | 
            +
                          'user' => 'aws'
         | 
| 79 | 
            +
                        },
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                        'name' => 'aws'
         | 
| 82 | 
            +
                      }],
         | 
| 83 | 
            +
                      'current-context' => 'aws',
         | 
| 84 | 
            +
                      'kind' => 'Config',
         | 
| 85 | 
            +
                      'preferences' => {},
         | 
| 86 | 
            +
                      'users' => [{
         | 
| 87 | 
            +
                        'name' => 'aws',
         | 
| 88 | 
            +
                        'user' => {
         | 
| 89 | 
            +
                          'exec' => {
         | 
| 90 | 
            +
                            'apiVersion' => 'client.authentication.k8s.io/v1alpha1',
         | 
| 91 | 
            +
                            'command' => AwsIamAuthenticatorRb.executable,
         | 
| 92 | 
            +
                            'args' => ['token', '-i', config.cluster_name],
         | 
| 93 | 
            +
                            'env' => [
         | 
| 94 | 
            +
                              { 'name' => 'AWS_ACCESS_KEY_ID', 'value' => credentials.access_key_id },
         | 
| 95 | 
            +
                              { 'name' => 'AWS_SECRET_ACCESS_KEY', 'value' => credentials.secret_access_key }
         | 
| 96 | 
            +
                            ]
         | 
| 97 | 
            +
                          }
         | 
| 98 | 
            +
                        }
         | 
| 99 | 
            +
                      }]
         | 
| 100 | 
            +
                    }
         | 
| 101 | 
            +
                  end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                  def cluster
         | 
| 104 | 
            +
                    @cluster ||= client.describe_cluster(name: config.cluster_name).cluster
         | 
| 105 | 
            +
                  end
         | 
| 106 | 
            +
             | 
| 107 | 
            +
                  def should_refresh_kubeconfig?
         | 
| 108 | 
            +
                    !File.exist?(kubeconfig_path) || !can_communicate_with_cluster?
         | 
| 109 | 
            +
                  end
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                  def can_communicate_with_cluster?
         | 
| 112 | 
            +
                    cmd = [kubernetes_cli.executable, '--kubeconfig', kubeconfig_path, 'get', 'ns']
         | 
| 113 | 
            +
                    `#{cmd.join(' ')}`
         | 
| 114 | 
            +
                    $?.success?
         | 
| 115 | 
            +
                  end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                  def kubeconfig_dir
         | 
| 118 | 
            +
                    @kubeconfig_dir ||= definition.app.root.join(
         | 
| 119 | 
            +
                      'tmp', 'kuby-eks'
         | 
| 120 | 
            +
                    )
         | 
| 121 | 
            +
                  end
         | 
| 122 | 
            +
                end
         | 
| 123 | 
            +
              end
         | 
| 124 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,93 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: kuby-eks
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Cameron Dutro
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2020-06-13 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: kube-dsl
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '0.1'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '0.1'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: aws-sdk-eks
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '1.38'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '1.38'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: aws-iam-authenticator-rb
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0.1'
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0.1'
         | 
| 55 | 
            +
            description: Amazon EKS provider for Kuby.
         | 
| 56 | 
            +
            email:
         | 
| 57 | 
            +
            - camertron@gmail.com
         | 
| 58 | 
            +
            executables: []
         | 
| 59 | 
            +
            extensions: []
         | 
| 60 | 
            +
            extra_rdoc_files: []
         | 
| 61 | 
            +
            files:
         | 
| 62 | 
            +
            - CHANGELOG.md
         | 
| 63 | 
            +
            - Gemfile
         | 
| 64 | 
            +
            - LICENSE
         | 
| 65 | 
            +
            - Rakefile
         | 
| 66 | 
            +
            - kuby-eks.gemspec
         | 
| 67 | 
            +
            - lib/kuby/eks.rb
         | 
| 68 | 
            +
            - lib/kuby/eks/config.rb
         | 
| 69 | 
            +
            - lib/kuby/eks/provider.rb
         | 
| 70 | 
            +
            - lib/kuby/eks/version.rb
         | 
| 71 | 
            +
            homepage: http://github.com/getkuby/kuby-eks
         | 
| 72 | 
            +
            licenses: []
         | 
| 73 | 
            +
            metadata: {}
         | 
| 74 | 
            +
            post_install_message: 
         | 
| 75 | 
            +
            rdoc_options: []
         | 
| 76 | 
            +
            require_paths:
         | 
| 77 | 
            +
            - lib
         | 
| 78 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
              requirements:
         | 
| 80 | 
            +
              - - ">="
         | 
| 81 | 
            +
                - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                  version: '0'
         | 
| 83 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 84 | 
            +
              requirements:
         | 
| 85 | 
            +
              - - ">="
         | 
| 86 | 
            +
                - !ruby/object:Gem::Version
         | 
| 87 | 
            +
                  version: '0'
         | 
| 88 | 
            +
            requirements: []
         | 
| 89 | 
            +
            rubygems_version: 3.0.6
         | 
| 90 | 
            +
            signing_key: 
         | 
| 91 | 
            +
            specification_version: 4
         | 
| 92 | 
            +
            summary: Amazon EKS provider for Kuby.
         | 
| 93 | 
            +
            test_files: []
         |