kustomizer 0.1.8 → 0.1.13

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: 1260ca0cca8efac0126311bef3132cdf7bc365f972796cc79af0f93f104ffdf9
4
- data.tar.gz: a185196ef16998e4ff770e3c3de43bebdd73803b8191f1d2848e85df0139bcc5
3
+ metadata.gz: c26e9c88c31679ffb0f02a8467f32d09a515e3946c830c8f12bd43c7f5f2a063
4
+ data.tar.gz: 9791c34a8675be353010c0d071b9e0a473b3a30ae5a5242b32d2658d31ec9dcb
5
5
  SHA512:
6
- metadata.gz: 2cc5cf3fab625e3e33acc67beba765bd59d8601484648107ba777814df91c0f789dd9f672ebb8912752d6e4021a60cc092f4b36482be73507b25aaaf126ce8e6
7
- data.tar.gz: efe6654e4cfbebf32c6fc93a9cebfaed0c8ee67dfd4dcbb44a38fddbf5d65031fb7c76f5282b370d53dd27eb390e8a7947ac2628d16e8edc6d3b7b5e13c66a6f
6
+ metadata.gz: 9f7020ba34798dca0f89e2dba3a22d672efe21f87ae998d3ae7c9388aa8aa8e638b922b154a04f9fa4f2ae4ce205efd7493d64e99c7f1b7d49e7e4d1968f1dce
7
+ data.tar.gz: 6ffde7fa3184ec41c5e49a04af80da0fbe4efcc8e5d6864071b5b0fde49d06d035683b18cb251730e52ba4f1aa868bdcaedd647fc6f0637917170df1a4b2da78
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /vendor/
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kustomizer (0.1.8)
5
- accessory (~> 0.1.9)
4
+ kustomizer (0.1.13)
5
+ accessory (~> 0.1.11)
6
6
  base32-multi
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- accessory (0.1.10)
11
+ accessory (0.1.11)
12
12
  base32-multi (0.1.1)
13
13
  diff-lcs (1.4.4)
14
14
  rake (13.0.3)
@@ -21,18 +21,15 @@ GEM
21
21
  rspec-expectations (3.10.1)
22
22
  diff-lcs (>= 1.2.0, < 2.0)
23
23
  rspec-support (~> 3.10.0)
24
- rspec-mocks (3.10.1)
24
+ rspec-mocks (3.10.2)
25
25
  diff-lcs (>= 1.2.0, < 2.0)
26
26
  rspec-support (~> 3.10.0)
27
- rspec-support (3.10.1)
27
+ rspec-support (3.10.2)
28
28
 
29
29
  PLATFORMS
30
- x86_64-darwin-20
30
+ ruby
31
31
 
32
32
  DEPENDENCIES
33
33
  kustomizer!
34
34
  rake (~> 13.0)
35
35
  rspec (~> 3.0)
36
-
37
- BUNDLED WITH
38
- 2.2.7
data/README.md CHANGED
@@ -19,8 +19,8 @@ Enough Library to solve our own problems :wink:)
19
19
  Status of `kustomization.yaml` feature support:
20
20
 
21
21
  * [x] `bases`
22
- * [ ] `commonAnnotations`
23
- * [ ] `commonLabels`
22
+ * [x] `commonAnnotations`
23
+ * [x] `commonLabels`
24
24
  * [ ] `configMapGenerator` and `secretGenerator`
25
25
  * [ ] `crds`
26
26
  * [x] `generators` (see [Extending Kustomize](https://kubectl.docs.kubernetes.io/guides/extending_kustomize/))
data/kustomizer.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "A pure-ruby implementation of the Kubernetes 'kustomize' command."
13
13
  spec.homepage = "https://github.com/tsutsu/kustomize"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = spec.homepage
@@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.add_runtime_dependency "accessory", "~> 0.1.9"
27
+ spec.add_runtime_dependency "accessory", "~> 0.1.11"
28
28
  spec.add_runtime_dependency "base32-multi"
29
29
  end
data/lib/kustomize.rb CHANGED
@@ -20,7 +20,7 @@ module Kustomize
20
20
  raise ArgumentError, "must be a kustomization document or a path to one, instead got: #{rel_path_or_rc.inspect}"
21
21
  end
22
22
 
23
- Kustomize::Emitter::FinalizerEmitter.new(base_emitter)
23
+ Kustomize::Emitter::FinalizerEmitter.new(base_emitter, session: session)
24
24
  end
25
25
 
26
26
  def self.load_doc(rc, session: Kustomize::Session.new, source_path:)
@@ -6,6 +6,8 @@ require 'kustomize/emitter/generator_plugins_emitter'
6
6
  require 'kustomize/transform/json_6902_patch_transform'
7
7
  require 'kustomize/transform/image_transform'
8
8
  require 'kustomize/transform/namespace_transform'
9
+ require 'kustomize/transform/common_annotations_transform'
10
+ require 'kustomize/transform/common_labels_transform'
9
11
  require 'kustomize/transform/fingerprint_suffix_transform'
10
12
  require 'kustomize/transform/ref_fixup_transform'
11
13
  require 'kustomize/transform/purge_internal_annotations_transform'
@@ -101,12 +103,30 @@ class Kustomize::Emitter::DocumentEmitter::KustomizationDocumentEmitter < Kustom
101
103
  end
102
104
  end
103
105
 
106
+ def common_annotations_transforms
107
+ if new_annots = @doc['commonAnnotations']
108
+ [Kustomize::Transform::CommonAnnotationsTransform.create(new_annots)]
109
+ else
110
+ []
111
+ end
112
+ end
113
+
114
+ def common_labels_transforms
115
+ if new_labels = @doc['commonLabels']
116
+ [Kustomize::Transform::CommonLabelsTransform.create(new_labels)]
117
+ else
118
+ []
119
+ end
120
+ end
121
+
104
122
  def transforms
105
123
  return @transforms if @transforms
106
124
 
107
125
  @transforms = [
108
126
  self.namespace_transforms,
109
127
  self.image_transforms,
128
+ self.common_annotations_transforms,
129
+ self.common_labels_transforms,
110
130
  self.json_6902_patch_transforms,
111
131
  self.transformer_plugin_transforms
112
132
  ].flatten
@@ -2,11 +2,14 @@ require 'kustomize/emitter'
2
2
 
3
3
  require 'kustomize/transform/fingerprint_suffix_transform'
4
4
  require 'kustomize/transform/ref_fixup_transform'
5
+ require 'kustomize/transform/filter_for_session_specified_component_transform'
6
+ require 'kustomize/transform/drop_filtered_documents_transform'
5
7
  require 'kustomize/transform/purge_internal_annotations_transform'
6
8
 
7
9
  class Kustomize::Emitter::FinalizerEmitter < Kustomize::Emitter
8
- def initialize(input_emitter)
10
+ def initialize(input_emitter, session:)
9
11
  @input_emitter = input_emitter
12
+ @session = session
10
13
  end
11
14
 
12
15
  def input_emitters
@@ -16,11 +19,20 @@ class Kustomize::Emitter::FinalizerEmitter < Kustomize::Emitter
16
19
  def transforms
17
20
  return @transforms if @transforms
18
21
 
22
+ final_filters =
23
+ if comp = @session.only_emit_component
24
+ [Kustomize::Transform::FilterForSessionSpecifiedComponentTransform.create(comp)]
25
+ else
26
+ []
27
+ end
28
+
19
29
  @transforms = [
20
30
  Kustomize::Transform::FingerprintSuffixTransform.instance,
21
31
  Kustomize::Transform::RefFixupTransform.instance,
32
+ final_filters,
33
+ Kustomize::Transform::DropFilteredDocumentsTransform.instance,
22
34
  Kustomize::Transform::PurgeInternalAnnotationsTransform.instance
23
- ].flatten
35
+ ].flatten.compact
24
36
  end
25
37
 
26
38
  def emit
@@ -18,6 +18,8 @@ class Kustomize::Json6902Patch::GsubOp < Kustomize::Json6902Patch::Op
18
18
  def apply(rc)
19
19
  @lenses.inject(rc) do |doc, lens|
20
20
  lens.update_in(doc) do |orig_value|
21
+ next(:keep) unless orig_value.kind_of?(String)
22
+
21
23
  new_value = orig_value.gsub(@pattern, @replacement)
22
24
 
23
25
  if new_value != orig_value
@@ -3,12 +3,14 @@ module Kustomize; end
3
3
  require 'kustomize/plugin_manager'
4
4
 
5
5
  class Kustomize::Session
6
- def initialize(load_paths: [])
6
+ def initialize(load_paths: [], only_emit_component: nil)
7
7
  @load_paths = load_paths
8
8
  @plugin_manager = Kustomize::PluginManager.new(session: self)
9
+ @only_emit_component = only_emit_component
9
10
  end
10
11
 
11
12
  attr_reader :plugin_manager
13
+ attr_accessor :only_emit_component
12
14
 
13
15
  def builtin_load_paths
14
16
  [Pathname.new(__FILE__).expand_path.parent / 'builtin_plugins']
@@ -0,0 +1,36 @@
1
+ require 'accessory'
2
+
3
+ require 'kustomize/transform'
4
+
5
+ class Kustomize::Transform::CommonAnnotationsTransform < Kustomize::Transform
6
+ include Accessory
7
+
8
+ def initialize(new_annots)
9
+ @new_annots = new_annots
10
+ end
11
+
12
+ BASE_LENS = Lens["metadata", "annotations"]
13
+
14
+ LENS_PREFIXES = [
15
+ Lens["spec", "template"],
16
+ Lens["spec", "jobTemplate", "spec", "template"]
17
+ ]
18
+
19
+ def rewrite(rc_doc)
20
+ rc_doc = BASE_LENS.update_in(rc_doc) do |annots|
21
+ [:set, (annots || {}).merge(@new_annots)]
22
+ end
23
+
24
+ LENS_PREFIXES.inject(rc_doc) do |doc, prefix|
25
+ prefix.update_in(rc_doc) do |node|
26
+ next(:keep) unless node.kind_of?(Hash)
27
+
28
+ new_node = BASE_LENS.update_in(node) do |annots|
29
+ [:set, (annots || {}).merge(@new_annots)]
30
+ end
31
+
32
+ [:set, new_node]
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ require 'accessory'
2
+
3
+ require 'kustomize/transform'
4
+
5
+ class Kustomize::Transform::CommonLabelsTransform < Kustomize::Transform
6
+ include Accessory
7
+
8
+ def initialize(new_labels)
9
+ @new_labels = new_labels
10
+ end
11
+
12
+ LENSES_FOR_ALL = [
13
+ Lens["metadata", "labels"]
14
+ ]
15
+
16
+ LENSES_FOR_KIND = {
17
+ "Service" => [
18
+ Lens["spec", "selector"]
19
+ ],
20
+
21
+ "Deployment" => [
22
+ Lens["spec", "selector", "matchLabels"]
23
+ ],
24
+ }
25
+
26
+ def rewrite(rc_doc)
27
+ rc_kind = rc_doc['kind']
28
+ use_lenses = LENSES_FOR_ALL
29
+
30
+ if lenses_for_doc_kind = LENSES_FOR_KIND[rc_kind]
31
+ use_lenses += lenses_for_doc_kind
32
+ end
33
+
34
+ use_lenses.inject(rc_doc) do |doc, lens|
35
+ lens.update_in(doc) do |annots|
36
+ [:set, (annots || {}).merge(@new_labels)]
37
+ end
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,25 @@
1
+ require 'singleton'
2
+ require 'set'
3
+
4
+ require 'accessory'
5
+
6
+ require 'kustomize/transform'
7
+
8
+ class Kustomize::Transform::DropFilteredDocumentsTransform < Kustomize::Transform
9
+ include Accessory
10
+ include Singleton
11
+
12
+ ANNOTS_LENS = Lens['metadata', 'annotations']
13
+
14
+ DROP_ON_ANNOTS = Set[
15
+ 'config.kubernetes.io/local-config',
16
+ 'kustomizer.covalenthq.com/drop'
17
+ ]
18
+
19
+ def rewrite_all(rcs)
20
+ rcs.filter do |rc|
21
+ annot_keys = (ANNOTS_LENS.get_in(rc) || {}).keys
22
+ not(annot_keys.find{ |k| DROP_ON_ANNOTS.member?(k) })
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ require 'accessory'
2
+
3
+ require 'kustomize/transform'
4
+
5
+ class Kustomize::Transform::FilterForSessionSpecifiedComponentTransform < Kustomize::Transform
6
+ include Accessory
7
+
8
+ def initialize(component_name)
9
+ @component_name = component_name
10
+ end
11
+
12
+ ANNOTS_LENS = Lens['metadata', 'annotations']
13
+
14
+ COMPONENT_ANNOT_NAME = 'kustomizer.covalenthq.com/component-name'
15
+ DROP_ANNOT_NAME = 'kustomizer.covalenthq.com/drop'
16
+
17
+ def rewrite(rc)
18
+ ANNOTS_LENS.update_in(rc) do |orig_annots|
19
+ orig_annots ||= {}
20
+
21
+ if orig_annots[COMPONENT_ANNOT_NAME] == @component_name
22
+ :keep
23
+ else
24
+ new_annots = orig_annots.merge({DROP_ANNOT_NAME => 'true'})
25
+ [:set, new_annots]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -35,7 +35,13 @@ class Kustomize::Transform::FingerprintSuffixTransform < Kustomize::Transform
35
35
  return rc unless APPLICABLE_KINDS.member?(rc_kind)
36
36
 
37
37
  FINGERPRINT_LENS.update_in(rc) do |orig_value|
38
- next(:keep) if orig_value
38
+ if orig_value
39
+ if orig_value == ''
40
+ next(:pop)
41
+ else
42
+ next(:keep)
43
+ end
44
+ end
39
45
 
40
46
  content_part = CONTENT_LENS_BY_KIND[rc_kind].get_in(rc)
41
47
  content_ser = content_part.to_json
@@ -47,9 +53,11 @@ class Kustomize::Transform::FingerprintSuffixTransform < Kustomize::Transform
47
53
  base_name = NAME_LENS.get_in(rc)
48
54
  fingerprint = FINGERPRINT_LENS.get_in(rc)
49
55
 
50
- NAME_LENS.update_in(rc) do |base_name|
51
- suffixed_name = [base_name, fingerprint].join(SUFFIX_JOINER)
52
- [:set, suffixed_name]
56
+ if fingerprint
57
+ NAME_LENS.update_in(rc) do |base_name|
58
+ suffixed_name = [base_name, fingerprint].join(SUFFIX_JOINER)
59
+ [:set, suffixed_name]
60
+ end
53
61
  end
54
62
 
55
63
  rc
@@ -8,23 +8,32 @@ class Kustomize::Transform::PurgeInternalAnnotationsTransform < Kustomize::Trans
8
8
  include Accessory
9
9
  include Singleton
10
10
 
11
- ANNOTS_LENS = Lens['metadata', 'annotations']
12
-
13
- INTERNAL_ANNOT_PATTERN = /^kustomizer\.covalenthq\.com\//
14
-
15
- def rewrite(rc)
16
- ANNOTS_LENS.update_in(rc) do |orig_annots|
17
- next(:keep) unless orig_annots and orig_annots.length.nonzero?
18
-
19
- new_annots =
20
- orig_annots.reject{ |k, v| INTERNAL_ANNOT_PATTERN.match?(k) }
21
-
22
- if new_annots.length == orig_annots.length
23
- :keep
24
- elsif new_annots.empty?
25
- :pop
26
- else
27
- [:set, new_annots]
11
+ LENSES = [
12
+ Lens['metadata', 'annotations'],
13
+ Lens['spec', 'template', 'metadata', 'annotations'],
14
+ Lens['spec', 'jobTemplate', 'spec', 'template', 'metadata', 'annotations']
15
+ ]
16
+
17
+ INTERNAL_ANNOT_PATTERNS = [
18
+ /^config\.kubernetes\.io\//,
19
+ /^kustomizer\.covalenthq\.com\//
20
+ ]
21
+
22
+ def rewrite(rc_doc)
23
+ LENSES.inject(rc_doc) do |doc, lens|
24
+ lens.update_in(rc_doc) do |orig_annots|
25
+ next(:keep) unless orig_annots and orig_annots.length.nonzero?
26
+
27
+ new_annots =
28
+ orig_annots.reject{ |k, v| INTERNAL_ANNOT_PATTERNS.any?{ |pat| pat.match?(k) } }
29
+
30
+ if new_annots.length == orig_annots.length
31
+ :keep
32
+ elsif new_annots.empty?
33
+ :pop
34
+ else
35
+ [:set, new_annots]
36
+ end
28
37
  end
29
38
  end
30
39
  end
@@ -24,10 +24,16 @@ class Kustomize::Transform::RefFixupTransform < Kustomize::Transform
24
24
  Lens["spec", "template", "spec", "volumes", Access.all, "secret", "secretName"]
25
25
  ]
26
26
 
27
+ CRONJOB_TEMPLATE_LENSES = POD_TEMPLATE_LENSES.map do |lens|
28
+ Lens["spec", "jobTemplate"] + lens
29
+ end
30
+
27
31
  KEY_REF_LENSES_BY_KIND = {
28
32
  "Deployment" => POD_TEMPLATE_LENSES,
29
33
  "StatefulSet" => POD_TEMPLATE_LENSES,
30
- "DaemonSet" => POD_TEMPLATE_LENSES
34
+ "DaemonSet" => POD_TEMPLATE_LENSES,
35
+ "Job" => POD_TEMPLATE_LENSES,
36
+ "CronJob" => CRONJOB_TEMPLATE_LENSES
31
37
  }
32
38
 
33
39
  def rewrite_all(rcs)
@@ -1,3 +1,3 @@
1
1
  module Kustomize
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.13"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kustomizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Levi Aul
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-03 00:00:00.000000000 Z
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: accessory
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.9
19
+ version: 0.1.11
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.9
26
+ version: 0.1.11
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: base32-multi
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +79,10 @@ files:
79
79
  - lib/kustomize/session.rb
80
80
  - lib/kustomize/target_spec.rb
81
81
  - lib/kustomize/transform.rb
82
+ - lib/kustomize/transform/common_annotations_transform.rb
83
+ - lib/kustomize/transform/common_labels_transform.rb
84
+ - lib/kustomize/transform/drop_filtered_documents_transform.rb
85
+ - lib/kustomize/transform/filter_for_session_specified_component_transform.rb
82
86
  - lib/kustomize/transform/fingerprint_suffix_transform.rb
83
87
  - lib/kustomize/transform/image_transform.rb
84
88
  - lib/kustomize/transform/json_6902_patch_transform.rb
@@ -102,14 +106,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
106
  requirements:
103
107
  - - ">="
104
108
  - !ruby/object:Gem::Version
105
- version: 2.7.0
109
+ version: 2.6.0
106
110
  required_rubygems_version: !ruby/object:Gem::Requirement
107
111
  requirements:
108
112
  - - ">="
109
113
  - !ruby/object:Gem::Version
110
114
  version: '0'
111
115
  requirements: []
112
- rubygems_version: 3.2.3
116
+ rubygems_version: 3.2.15
113
117
  signing_key:
114
118
  specification_version: 4
115
119
  summary: Pure-ruby impl of Kubernetes kustomize