kubes 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68eb4fe2f49953dd133ed6d5baece88f47ff0078162576a0cc41238bf571b6fc
4
- data.tar.gz: 29821780f33d80b168f20d2f42e38074776230ed7cde8fc474d947c70bc6f099
3
+ metadata.gz: 4068263aefa8212b17485e3a257813b806e0efc0617c01e7210db576759c2f27
4
+ data.tar.gz: e649b39644516f59a09c08ec33d05c9ceb9adde006c6bda386f370bec8e205d8
5
5
  SHA512:
6
- metadata.gz: 0c6de28da8411c1a62cc6fb310e0057aaae12d4e219c14399002b81731f5ecc3f20b596247a367068a5c83695f7d25ffdb0583004e8e7b3812eaf57646b86709
7
- data.tar.gz: 828253eb8e9943dd39218de79a73cb6ae2c6652b4f6e88e4aebe1b1ab5b6be44ff9aee199cee9208a8abc5f038608c5ad1ead7836799c57813df37f49ed5e0db
6
+ metadata.gz: 0f65b2736c9967eee1a24b65513bed5bb79177c54f8870871e1428e4ba6ff4b2e2501e5d6a1a78ada9f2db971763a6b1f6d35b4818fcfaf76df95baa37aba049
7
+ data.tar.gz: cfb8c9a0371d7efd6e9a4d8deeb1c503a18c63fd291a0a89275b9bf84996fa7a6ce7f3dfc7c83e8ff98546fc94c80a65bf41f953121833b0f3614c5a635098de
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.6.2]
7
+ - [#36](https://github.com/boltops-tools/kubes/pull/36) add plugin hooks support
8
+
6
9
  ## [0.6.1]
7
10
  - update gemspec dependency to plugins that provide the secrets helpers
8
11
 
data/README.md CHANGED
@@ -18,13 +18,6 @@ Kubes will:
18
18
  2. Compile Kubernetes YAML files from YAML/ERB or a DSL and adjusts the Docker build image
19
19
  3. Deploy via kubectl apply on the compiled Kubernetes YAML files
20
20
 
21
- Features:
22
-
23
- * Automation: [Builds the Docker image](docs/docker.md) and updates the compiled YAML files
24
- * Syntactic Sugar: Use an optional [ERB/YAML](docs/yaml.md) or [DSL](docs/dsl.md) to write your Kubernetes YAML files. You can use a mix of DSL and YAML definitions in the `.kubes/resources` folder.
25
- * Layering: Use the same Kubernetes YAML to build multiple environments like dev and prod with [layering](docs/layering.md).
26
- * CLI Customizations: You can customize the [cli args](docs/kubectl.md). You can also run hooks before and after kubectl commands.
27
-
28
21
  ## Usage
29
22
 
30
23
  kubes init # creates .kubes structure
@@ -13,6 +13,7 @@ Hook | Description
13
13
  compile | When kubes compiles the `.kubes/resources` to `.kubes/output`.
14
14
  apply | When kubes runs all the `kubectl apply` commands.
15
15
  delete | When kubes runs all the `kubectl delete` commands.
16
+ prune | When kubes prunes. IE: To clean old secrets.
16
17
 
17
18
  ## Lifecycle At Kubes Level
18
19
 
@@ -39,7 +39,9 @@ Using multiple files is the general recommended approach.
39
39
 
40
40
  ## Multiple Resources: Block Form
41
41
 
42
- You can also use a block form to create multiple resources. You name the resource files with plural names. An example helps explain:
42
+ You can also use a block form to create multiple resources. The multiple resources block form is an experimental feature.
43
+
44
+ You name the resource files with plural names. An example helps explain:
43
45
 
44
46
  .kubes
45
47
  └── resources
@@ -0,0 +1,33 @@
1
+ ---
2
+ title: GKE Whitelisting
3
+ nav_text: GKE
4
+ categories: helpers-google
5
+ ---
6
+
7
+ This page covers how to enable GKE IP Whitelisting. This feature is useful for deploying from a CloudBuild with GKE Private Clusters.
8
+
9
+ GKE Private Clusters whitelist and only allow authorized IPs to communicate with the Kubernetes control plane. An issue with CloudBuild is that the IP address is not well-known. Google creates a VM to run the CI scripts and throws it away when finished. Kubes can detect the IP of the CloudBuild machine, add it to the cluster, deploy, and remove the IP afterward.
10
+
11
+ ## Setup
12
+
13
+ To enable the GKE IP whitelisting feature, it's a single line:
14
+
15
+ .kubes/config/env/dev.rb
16
+
17
+ ```ruby
18
+ KubesGoogle.configure do |config|
19
+ config.gke.cluster_name = "projects/#{ENV['GOOGLE_PROJECT']}/locations/us-central1/clusters/dev-cluster"
20
+ end
21
+ ```
22
+
23
+ This enables `kubes apply` before and after hooks to add and remove the current machine IP.
24
+
25
+ ## Options
26
+
27
+ Here are the `config.gke` settings:
28
+
29
+ Name | Description | Default
30
+ ---|---|---
31
+ cluster_name | GKE cluster name. This is required. | nil
32
+ enable_hooks | This will be true when the cluster_name is set. So there's no need to set it. The option provides a quick way to override and disable running the hooks. | true
33
+ whitelist_ip | Explicit IP to whitelist. By default the IP address of the current machine is automatically detected and used. | nil
@@ -70,7 +70,7 @@ spec:
70
70
 
71
71
  ## Output
72
72
 
73
- The result is the merge layered files.
73
+ The result is the merged layered files.
74
74
 
75
75
  ```yaml
76
76
  metadata:
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  # core helper libs
32
32
  spec.add_dependency "kubes_aws", "~> 0.2.0"
33
- spec.add_dependency "kubes_google", "~> 0.2.0"
33
+ spec.add_dependency "kubes_google", "~> 0.3.0"
34
34
 
35
35
  spec.add_development_dependency "bundler"
36
36
  spec.add_development_dependency "byebug"
@@ -4,7 +4,6 @@ class Kubes::CLI
4
4
  compile
5
5
  logger.info "Deploying kubes resources"
6
6
  Kubes::Kubectl::Dispatcher.new(:apply, @options).run
7
- Prune.new(@options.merge(yes: true, quiet: true)).run if Kubes.config.auto_prune # prune old secrets and config maps
8
7
  end
9
8
  end
10
9
  end
@@ -2,15 +2,17 @@ class Kubes::CLI
2
2
  class Prune < Base
3
3
  KINDS = %w[ConfigMap Secret]
4
4
  extend Memoist
5
+ include Kubes::Hooks::Concern
5
6
  include Kubes::Util::Sure
6
7
 
7
8
  def run
8
9
  return unless anything_to_prune?
9
10
  logger.info "Pruning old resources: #{KINDS.join(', ')}"
10
-
11
11
  perform(preview: true) unless @options[:yes]
12
12
  sure?("This will prune/delete resources. Are you sure?")
13
- perform(preview: false)
13
+ run_hooks("kubes.rb", name: "prune") do
14
+ perform(preview: false)
15
+ end
14
16
  end
15
17
 
16
18
  def fetcher
@@ -5,7 +5,7 @@ module Kubes::Compiler::Shared
5
5
  def load_plugin_helpers
6
6
  return if @@plugin_helpers_loaded
7
7
  Kubes::Plugin.plugins.each do |klass|
8
- helpers_class = "#{klass}::Helpers".constantize
8
+ helpers_class = "#{klass}::Helpers".constantize # IE: KubesAws::Helpers
9
9
  self.class.send :include, helpers_class
10
10
  end
11
11
  @@plugin_helpers_loaded = true
@@ -81,9 +81,22 @@ module Kubes
81
81
  yield(@config)
82
82
  end
83
83
 
84
+ # Load configs example:
85
+ #
86
+ # .kubes/config.rb
87
+ # .kubes/config/env/dev.rb
88
+ # .kubes/config/plugins/google.rb
89
+ # .kubes/config/plugins/google/dev.rb
90
+ #
84
91
  def load_configs
85
92
  evaluate_file(".kubes/config.rb")
86
93
  evaluate_file(".kubes/config/env/#{Kubes.env}.rb")
94
+ Kubes::Plugin.plugins.each do |klass|
95
+ # klass: IE: KubesAws, KubesGoogle
96
+ name = klass.to_s.underscore.sub('kubes_','') # kubes_google => google
97
+ evaluate_file(".kubes/config/plugins/#{name}.rb")
98
+ evaluate_file(".kubes/config/plugins/#{name}/#{Kubes.env}.rb")
99
+ end
87
100
  end
88
101
  end
89
102
  end
@@ -6,8 +6,9 @@ module Kubes::Hooks
6
6
  include Kubes::Logging
7
7
 
8
8
  attr_accessor :name
9
- def initialize(dsl_file, options={})
10
- @dsl_file, @options = dsl_file, options # IE: .kubes/config/hooks/kubectl.rb
9
+ def initialize(file, options={})
10
+ @file, @options = file, options # IE: .kubes/config/hooks/kubectl.rb
11
+ @dsl_file = "#{Kubes.root}/.kubes/config/hooks/#{@file}"
11
12
  @output_file = options[:file] # IE: .kubes/output/web/service.yaml
12
13
  @name = options[:name].to_s
13
14
  @hooks = {before: {}, after: {}}
@@ -16,10 +17,26 @@ module Kubes::Hooks
16
17
  def build
17
18
  return @hooks unless File.exist?(@dsl_file)
18
19
  evaluate_file(@dsl_file)
20
+ evaluate_plugin_hooks
19
21
  @hooks.deep_stringify_keys!
20
22
  end
21
23
  memoize :build
22
24
 
25
+ def evaluate_plugin_hooks
26
+ Kubes::Plugin.plugins.each do |klass|
27
+ hooks_class = hooks_class(klass)
28
+ next unless hooks_class
29
+ plugin_hooks = hooks_class.new
30
+ path = "#{plugin_hooks.path}/#{@file}"
31
+ evaluate_file(path)
32
+ end
33
+ end
34
+
35
+ def hooks_class(klass)
36
+ "#{klass}::Hooks".constantize # IE: KubesGoogle::Hooks
37
+ rescue NameError
38
+ end
39
+
23
40
  def run_hooks
24
41
  build
25
42
  run_each_hook("before")
@@ -42,8 +59,7 @@ module Kubes::Hooks
42
59
  id = "#{command} #{type} #{@name}"
43
60
  on = " on: #{hook["on"]}" if hook["on"]
44
61
  label = " label: #{hook["label"]}" if hook["label"]
45
- logger.info "Running #{id} hook.#{on}#{label}"
46
- logger.debug "Hook options: #{hook}"
62
+ logger.info "Hook: Running #{id} hook.#{on}#{label}"
47
63
  Runner.new(hook).run
48
64
  end
49
65
 
@@ -2,7 +2,7 @@ module Kubes::Hooks
2
2
  module Concern
3
3
  # options example: {:name=>"apply", :file=>".kubes/output/web/service.yaml"}
4
4
  def run_hooks(file, options={}, &block)
5
- hooks = Kubes::Hooks::Builder.new("#{Kubes.root}/.kubes/config/hooks/#{file}", options)
5
+ hooks = Kubes::Hooks::Builder.new(file, options)
6
6
  hooks.build # build hooks
7
7
  hooks.run_hooks(&block)
8
8
  end
@@ -22,10 +22,17 @@ class Kubes::Kubectl
22
22
  Kubes::Kubectl.run(@name, @options.merge(file: file))
23
23
  end
24
24
  end
25
+ prune # important to call within run_hooks for case of GKE IP whitelisting
25
26
  end
26
27
  end
27
28
  end
28
29
 
30
+ def prune
31
+ return unless @name == "apply" # only run for apply
32
+ return unless Kubes.config.auto_prune # prune old secrets and config maps
33
+ Kubes::CLI::Prune.new(@options.merge(yes: true, quiet: true)).run
34
+ end
35
+
29
36
  def switch_context(&block)
30
37
  kubectl = Kubes.config.kubectl
31
38
  context = kubectl.context
@@ -1,3 +1,3 @@
1
1
  module Kubes
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-09 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.2.0
159
+ version: 0.3.0
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 0.2.0
166
+ version: 0.3.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: bundler
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -312,6 +312,7 @@ files:
312
312
  - docs/_docs/helpers/google.md
313
313
  - docs/_docs/helpers/google/advanced.md
314
314
  - docs/_docs/helpers/google/advanced/secrets.md
315
+ - docs/_docs/helpers/google/gke.md
315
316
  - docs/_docs/helpers/google/secrets.md
316
317
  - docs/_docs/helpers/google/service-account.md
317
318
  - docs/_docs/intro.md