kuby-azure 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: 005be68800cb10ba770e629b590f8a28351f0ff3486341bac289c8e1b1294b52
4
+ data.tar.gz: 9b9d4d95f9dbc7f2142cd85a5a77a29a338bd9f3abe77e9b779845e62e5074ab
5
+ SHA512:
6
+ metadata.gz: b28395e1dc1fea92e5eaf98627ae0eb2f83373372b426485e8b222288aed86d866b632dc0978bf455125062f85a822c86d5072322a330c2324d51db37df06fe0
7
+ data.tar.gz: c9ebb9d52f0850b780f0d3ac95e33c2ac7911fb77c707630ea48c774484582f1b2d0b25532263a044c3fb8fd204d02c339383da581e461439315062ec929c3a8
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ * Birthday!
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'kuby-core', path: '../kuby-core'
6
+
7
+ group :development, :test do
8
+ gem 'pry-byebug'
9
+ gem 'rake'
10
+ end
11
+
12
+ group :test do
13
+ gem 'rspec', '~> 3.0'
14
+ 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/azure'
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,21 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
+ require 'kuby/azure/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'kuby-azure'
6
+ s.version = ::Kuby::Azure::VERSION
7
+ s.authors = ['Cameron Dutro']
8
+ s.email = ['camertron@gmail.com']
9
+ s.homepage = 'http://github.com/getkuby/kuby-azure'
10
+
11
+ s.description = s.summary = 'Azure provider for Kuby.'
12
+
13
+ s.platform = Gem::Platform::RUBY
14
+
15
+ s.add_dependency 'faraday', '~> 0.17'
16
+ s.add_dependency 'kube-dsl', '~> 0.1'
17
+ s.add_dependency 'azure_mgmt_container_service', '~> 0.20'
18
+
19
+ s.require_path = 'lib'
20
+ s.files = Dir['{lib,spec}/**/*', 'Gemfile', 'LICENSE', 'CHANGELOG.md', 'README.md', 'Rakefile', 'kuby-azure.gemspec']
21
+ end
@@ -0,0 +1,10 @@
1
+ require 'kuby'
2
+ require 'kuby/azure/provider'
3
+
4
+ module Kuby
5
+ module Azure
6
+ autoload :Config, 'kuby/azure/config'
7
+ end
8
+ end
9
+
10
+ Kuby.register_provider(:azure, Kuby::Azure::Provider)
@@ -0,0 +1,12 @@
1
+ require 'kube-dsl'
2
+
3
+ module Kuby
4
+ module Azure
5
+ class Config
6
+ extend ::KubeDSL::ValueFields
7
+
8
+ value_fields :tenant_id, :client_id, :client_secret, :subscription_id
9
+ value_fields :resource_group_name, :resource_name
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,79 @@
1
+ require 'fileutils'
2
+ require 'azure_mgmt_container_service'
3
+
4
+ module Kuby
5
+ module Azure
6
+ class Provider < Kuby::Kubernetes::Provider
7
+ STORAGE_CLASS_NAME = 'default'.freeze
8
+
9
+ attr_reader :config
10
+
11
+ def configure(&block)
12
+ config.instance_eval(&block)
13
+ end
14
+
15
+ def kubeconfig_path
16
+ @kubeconfig_path ||= kubeconfig_dir.join(
17
+ "#{definition.app_name.downcase}-kubeconfig.yaml"
18
+ ).to_s
19
+ end
20
+
21
+ def after_configuration
22
+ refresh_kubeconfig
23
+ end
24
+
25
+ def storage_class_name
26
+ STORAGE_CLASS_NAME
27
+ end
28
+
29
+ private
30
+
31
+ def after_initialize
32
+ @config = Config.new
33
+ end
34
+
35
+ def client
36
+ @client ||= ::Azure::ContainerService::Profiles::Latest::Mgmt::Client.new(
37
+ tenant_id: config.tenant_id,
38
+ client_id: config.client_id,
39
+ client_secret: config.client_secret,
40
+ subscription_id: config.subscription_id
41
+ )
42
+ end
43
+
44
+ def refresh_kubeconfig
45
+ return unless should_refresh_kubeconfig?
46
+
47
+ FileUtils.mkdir_p(kubeconfig_dir)
48
+
49
+ Kuby.logger.info('Refreshing kubeconfig...')
50
+
51
+ cred = client.managed_clusters.list_cluster_user_credentials(
52
+ config.resource_group_name,
53
+ config.resource_name
54
+ )
55
+
56
+ kubeconfig = cred.kubeconfigs.first.value.pack('C*')
57
+ File.write(kubeconfig_path, kubeconfig)
58
+
59
+ Kuby.logger.info('Successfully refreshed kubeconfig!')
60
+ end
61
+
62
+ def should_refresh_kubeconfig?
63
+ !File.exist?(kubeconfig_path) || !can_communicate_with_cluster?
64
+ end
65
+
66
+ def can_communicate_with_cluster?
67
+ cmd = [kubernetes_cli.executable, '--kubeconfig', kubeconfig_path, 'get', 'ns']
68
+ `#{cmd.join(' ')}`
69
+ $?.success?
70
+ end
71
+
72
+ def kubeconfig_dir
73
+ @kubeconfig_dir ||= definition.app.root.join(
74
+ 'tmp', 'kuby-azure'
75
+ )
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,5 @@
1
+ module Kuby
2
+ module Azure
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kuby-azure
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-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.17'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.17'
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
+ - !ruby/object:Gem::Dependency
42
+ name: azure_mgmt_container_service
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.20'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.20'
55
+ description: Azure 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-azure.gemspec
67
+ - lib/kuby/azure.rb
68
+ - lib/kuby/azure/config.rb
69
+ - lib/kuby/azure/provider.rb
70
+ - lib/kuby/azure/version.rb
71
+ homepage: http://github.com/getkuby/kuby-azure
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: Azure provider for Kuby.
93
+ test_files: []