kustomizer 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -4
- data/README.md +2 -2
- data/lib/kustomize.rb +1 -1
- data/lib/kustomize/emitter/document_emitter/kustomization_document_emitter.rb +20 -0
- data/lib/kustomize/emitter/finalizer_emitter.rb +14 -2
- data/lib/kustomize/session.rb +3 -1
- data/lib/kustomize/transform/common_annotations_transform.rb +36 -0
- data/lib/kustomize/transform/common_labels_transform.rb +41 -0
- data/lib/kustomize/transform/drop_filtered_documents_transform.rb +25 -0
- data/lib/kustomize/transform/filter_for_session_specified_component_transform.rb +29 -0
- data/lib/kustomize/transform/purge_internal_annotations_transform.rb +26 -17
- data/lib/kustomize/version.rb +1 -1
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60295db655aa832bb933831f4dbd1854ad7705c3908423cc9e8a4e1d25faef69
|
4
|
+
data.tar.gz: a575e73284ea5bd0877543ff888767ff224b26e3ddde9509c591631492340f60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0c24c3dcfb4ee551be1b85a5c84dd52038015aa6ef4fdd439d80eccf9e4cd1046c04c56076c92a428bbccdb4cacee47dfbc3531077da9906c22c888b4faa939
|
7
|
+
data.tar.gz: 9a5b1b6641c3a9e208dcae6310891462f3cbfc3b609266d0bda66f9e4131fef3a8866b364271ee36170ed8c1cc08c7462e959672fa8284b9e63d17e799c3729e
|
data/Gemfile.lock
CHANGED
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
|
-
* [
|
23
|
-
* [
|
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/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
|
data/lib/kustomize/session.rb
CHANGED
@@ -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
|
@@ -8,23 +8,32 @@ class Kustomize::Transform::PurgeInternalAnnotationsTransform < Kustomize::Trans
|
|
8
8
|
include Accessory
|
9
9
|
include Singleton
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
:
|
26
|
-
|
27
|
-
|
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
|
data/lib/kustomize/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Levi Aul
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: accessory
|
@@ -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
|
@@ -94,7 +98,7 @@ licenses:
|
|
94
98
|
metadata:
|
95
99
|
homepage_uri: https://github.com/tsutsu/kustomize
|
96
100
|
source_code_uri: https://github.com/tsutsu/kustomize
|
97
|
-
post_install_message:
|
101
|
+
post_install_message:
|
98
102
|
rdoc_options: []
|
99
103
|
require_paths:
|
100
104
|
- lib
|
@@ -109,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
113
|
- !ruby/object:Gem::Version
|
110
114
|
version: '0'
|
111
115
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
113
|
-
signing_key:
|
116
|
+
rubygems_version: 3.2.3
|
117
|
+
signing_key:
|
114
118
|
specification_version: 4
|
115
119
|
summary: Pure-ruby impl of Kubernetes kustomize
|
116
120
|
test_files: []
|