kuby-digitalocean 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '08784d9abee427b4bcf5fd1df0f562dd83466213d74aaf1db49194ba0a191382'
4
+ data.tar.gz: acb36a47a21932b8302e7428d7c3a34de072b96d7f09ce8ded18544ca1b935c2
5
+ SHA512:
6
+ metadata.gz: 4ee4910d7cbb90ea81afa82814885585519942d9b710b1eb0f0c550428e4f423763f123f92a3bb2fafa668643bb675206c9e80e2fc3e64f6889d1d83147dabf7
7
+ data.tar.gz: ba6d508bf7b57d528cf821246b38ef89165fa94ba6c098eeae00a850b433f5b8e58125b953a832d367a38684bc7cae44e7eb935b0039933c4dbc2fa3fdcf3f4e
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ * Birthday!
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'kuby', path: '../kuby'
7
+ gem 'pry-byebug'
8
+ gem 'rake'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rspec', '~> 3.0'
13
+ end
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.
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubygems/package_task'
4
+
5
+ require 'kuby/digitalocean'
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
@@ -0,0 +1,20 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
+ require 'kuby/digitalocean/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'kuby-digitalocean'
6
+ s.version = ::Kuby::DigitalOcean::VERSION
7
+ s.authors = ['Cameron Dutro']
8
+ s.email = ['camertron@gmail.com']
9
+ s.homepage = 'http://github.com/getkuby/kuby-digitalocean'
10
+
11
+ s.description = s.summary = 'DigitalOcean provider for Kuby.'
12
+
13
+ s.platform = Gem::Platform::RUBY
14
+
15
+ s.add_dependency 'droplet_kit', '~> 3.5'
16
+ s.add_dependency 'kube-dsl', '~> 0.1'
17
+
18
+ s.require_path = 'lib'
19
+ s.files = Dir['{lib,spec}/**/*', 'Gemfile', 'LICENSE', 'CHANGELOG.md', 'README.md', 'Rakefile', 'kuby-digitalocean.gemspec']
20
+ end
@@ -0,0 +1,9 @@
1
+ require 'kuby/digitalocean/provider'
2
+
3
+ module Kuby
4
+ module DigitalOcean
5
+ autoload :Config, 'kuby/digitalocean/config'
6
+ end
7
+ end
8
+
9
+ Kuby.register_provider(:digitalocean, Kuby::DigitalOcean::Provider)
@@ -0,0 +1,11 @@
1
+ require 'kube-dsl'
2
+
3
+ module Kuby
4
+ module DigitalOcean
5
+ class Config
6
+ extend ::KubeDSL::ValueFields
7
+
8
+ value_fields :access_token, :cluster_id
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,94 @@
1
+ require 'kuby'
2
+ require 'droplet_kit'
3
+ require 'fileutils'
4
+
5
+ module Kuby
6
+ module DigitalOcean
7
+ class Provider < ::Kuby::Kubernetes::Provider
8
+ KUBECONFIG_EXPIRATION = 7 * 24 * 60 * 60 # 7 days
9
+ STORAGE_CLASS_NAME = 'do-block-storage'.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_initialize
24
+ kubernetes_cli.before_execute do
25
+ FileUtils.mkdir_p(kubeconfig_dir)
26
+ refresh_kubeconfig
27
+ end
28
+ end
29
+
30
+ def after_setup
31
+ if nginx_ingress = definition.kubernetes.plugin(:nginx_ingress)
32
+ service = ::KubeDSL::Resource.new(
33
+ kubernetes_cli.get_object(
34
+ 'service', nginx_ingress.namespace, nginx_ingress.service_name
35
+ )
36
+ )
37
+
38
+ # Convert from Local to Cluster here so a DigitalOcean load balancer,
39
+ # which sits in front of the ingress controller, is accessible by pods
40
+ # running on the same node as the controller. We have to do this
41
+ # because of a k8s bug:
42
+ #
43
+ # https://github.com/kubernetes/kubernetes/issues/87263
44
+ # https://github.com/kubernetes/kubernetes/issues/66607
45
+ #
46
+ # Word on the street is this is fixed in v1.17 (DO is currently on 1.16).
47
+ # Hopefully we can rip this out in the near future.
48
+ #
49
+ # This was discovered because cert-manager's self-check step attempts to
50
+ # verify external access to its ACME challenge ingress/service, but times
51
+ # out because k8s' iptables rules prevent it from going through the DO
52
+ # load balancer and therefore nginx.
53
+ service.contents['spec']['externalTrafficPolicy'] = 'Cluster'
54
+ kubernetes_cli.apply(service)
55
+ end
56
+ end
57
+
58
+ def storage_class_name
59
+ STORAGE_CLASS_NAME
60
+ end
61
+
62
+ private
63
+
64
+ def after_initialize
65
+ @config = Config.new
66
+ end
67
+
68
+ def client
69
+ @client ||= DropletKit::Client.new(
70
+ access_token: config.access_token
71
+ )
72
+ end
73
+
74
+ def refresh_kubeconfig
75
+ return unless should_refresh_kubeconfig?
76
+ Kuby.logger.info('Refreshing kubeconfig...')
77
+ kubeconfig = client.kubernetes_clusters.kubeconfig(id: config.cluster_id)
78
+ File.write(kubeconfig_path, kubeconfig)
79
+ Kuby.logger.info('Successfully refreshed kubeconfig!')
80
+ end
81
+
82
+ def should_refresh_kubeconfig?
83
+ !File.exist?(kubeconfig_path) ||
84
+ (Time.now - File.mtime(kubeconfig_path)) >= KUBECONFIG_EXPIRATION
85
+ end
86
+
87
+ def kubeconfig_dir
88
+ @kubeconfig_dir ||= definition.app.root.join(
89
+ 'tmp', 'kuby-digitalocean'
90
+ )
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,5 @@
1
+ module Kuby
2
+ module DigitalOcean
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kuby-digitalocean
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-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: droplet_kit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: kube-dsl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ description: DigitalOcean provider for Kuby.
42
+ email:
43
+ - camertron@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - Gemfile
50
+ - LICENSE
51
+ - Rakefile
52
+ - kuby-digitalocean.gemspec
53
+ - lib/kuby/digitalocean.rb
54
+ - lib/kuby/digitalocean/config.rb
55
+ - lib/kuby/digitalocean/provider.rb
56
+ - lib/kuby/digitalocean/version.rb
57
+ homepage: http://github.com/getkuby/kuby-digitalocean
58
+ licenses: []
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.0.6
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: DigitalOcean provider for Kuby.
79
+ test_files: []