kustomizer 0.1.10 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/json_6902_patch/gsub_op.rb +2 -0
- 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/image_transform.rb +4 -1
- data/lib/kustomize/transform/purge_internal_annotations_transform.rb +26 -17
- data/lib/kustomize/transform/ref_fixup_transform.rb +7 -1
- 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: 24481b3d630d8c9cfa75e87096df77aba2f9037fecae595f0b96708ddd0b5a86
|
4
|
+
data.tar.gz: 2560ac97bb60ad701194aadb9bbb7706d60c599b8bbad0b769dbd61c3d97abee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c88dfae7e03f6e3387ca4109e3e805b09e6fcd9382d6cccbeabd69bc0c93ab13b5a2c63851414ae8d5a8a707251805c72e05de0460a063bae80daddda69f8144
|
7
|
+
data.tar.gz: 88eef287b8769333a795d5e566ab9aeb2352b162aaf26356348a018c97b5708cef620f007907796634f9c56e784e42dcb25a6734a9745e3ef0cb355586004a54
|
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
|
@@ -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
|
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
|
@@ -24,11 +24,14 @@ class Kustomize::Transform::ImageTransform < Kustomize::Transform
|
|
24
24
|
end
|
25
25
|
|
26
26
|
TEMPLATE_POD_SPEC_LENS = Lens["spec", "template", "spec", "containers", Access.all, "image"]
|
27
|
+
TEMPLATE_CRONJOB_SPEC_LENS = Lens["spec", "jobTemplate"] + TEMPLATE_POD_SPEC_LENS
|
27
28
|
|
28
29
|
LENS_BY_KIND = {
|
29
30
|
"Deployment" => TEMPLATE_POD_SPEC_LENS,
|
30
31
|
"DaemonSet" => TEMPLATE_POD_SPEC_LENS,
|
31
|
-
"StatefulSet" => TEMPLATE_POD_SPEC_LENS
|
32
|
+
"StatefulSet" => TEMPLATE_POD_SPEC_LENS,
|
33
|
+
"Job" => TEMPLATE_POD_SPEC_LENS,
|
34
|
+
"CronJob" => TEMPLATE_CRONJOB_SPEC_LENS
|
32
35
|
}
|
33
36
|
|
34
37
|
def rewrite(rc_doc)
|
@@ -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
|
@@ -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)
|
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.15
|
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-
|
11
|
+
date: 2021-06-24 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.15
|
117
|
+
signing_key:
|
114
118
|
specification_version: 4
|
115
119
|
summary: Pure-ruby impl of Kubernetes kustomize
|
116
120
|
test_files: []
|