krane 2.1.10 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +4 -0
- data/dev.yml +1 -1
- data/lib/krane/cli/deploy_command.rb +10 -0
- data/lib/krane/cli/global_deploy_command.rb +10 -0
- data/lib/krane/deploy_task.rb +5 -1
- data/lib/krane/global_deploy_task.rb +5 -1
- data/lib/krane/kubernetes_resource.rb +4 -0
- data/lib/krane/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46134385171fa351edf5611c3ecd248c299339d2134cf4ff64f6227d68470b96
|
4
|
+
data.tar.gz: c30ad94176b02c7c402fa50ec5b73aa0c2c289a64401eefcc95494feb64354b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0792b68c262c3c310b7c51801c206f5422a2b65832eda020a2c0d58c804bb14adc755f9db5ff335b084d982303fbd376b846c5ff6af46d489530ffe6cfe2ae4b'
|
7
|
+
data.tar.gz: 185a56c603ccbc5dfcdbd7d247d6b7bec512da59a69f2a3e873f41243e79a70f3281596d5346829a4cd26ac1453c8d458cf45f41f498d8e61f1c5cf4e77a13ad
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -117,6 +117,7 @@ Refer to `krane help` for the authoritative set of options.
|
|
117
117
|
- `--global-timeout=duration`: Raise a timeout error if it takes longer than _duration_ for any
|
118
118
|
resource to deploy.
|
119
119
|
- `--selector`: Instructs krane to only prune resources which match the specified label selector, such as `environment=staging`. If you use this option, all resource templates must specify matching labels. See [Sharing a namespace](#sharing-a-namespace) below.
|
120
|
+
- `--selector-as-filter`: Instructs krane to only deploy resources that are filtered by the specified labels in `--selector`. The deploy will not fail if not all resources match the labels. This is useful if you only want to deploy a subset of resources within a given YAML file. See [Sharing a namespace](#sharing-a-namespace) below.
|
120
121
|
- `--no-verify-result`: Skip verification that workloads correctly deployed.
|
121
122
|
- `--protected-namespaces=default kube-system kube-public`: Fail validation if a deploy is targeted at a protected namespace.
|
122
123
|
- `--verbose-log-prefix`: Add [context][namespace] to the log prefix
|
@@ -132,6 +133,8 @@ If you need to, you may specify `--no-prune` to disable all pruning behaviour, b
|
|
132
133
|
|
133
134
|
If you need to share a namespace with resources which are managed by other tools or indeed other krane deployments, you can supply the `--selector` option, such that only resources with labels matching the selector are considered for pruning.
|
134
135
|
|
136
|
+
If you need to share a namespace with different set of resources using the same YAML file, you can supply the `--selector` and `--selector-as-filter` options, such that only the resources that match with the labels will be deployed. In each run of deploy, you can use different labels in `--selector` to deploy a different set of resources. Only the deployed resources in each run are considered for pruning.
|
137
|
+
|
135
138
|
### Using templates
|
136
139
|
|
137
140
|
All templates must be YAML formatted.
|
@@ -441,6 +444,7 @@ Refer to `krane global-deploy help` for the authoritative set of options.
|
|
441
444
|
- `--filenames / -f [PATHS]`: Accepts a list of directories and/or filenames to specify the set of directories/files that will be deployed. Use `-` to specify STDIN.
|
442
445
|
- `--no-prune`: Skips pruning of resources that are no longer in your Kubernetes template set. Not recommended, as it allows your namespace to accumulate cruft that is not reflected in your deploy directory.
|
443
446
|
- `--selector`: Instructs krane to only prune resources which match the specified label selector, such as `environment=staging`. By using this option, all resource templates must specify matching labels. See [Sharing a namespace](#sharing-a-namespace) below.
|
447
|
+
- `--selector-as-filter`: Instructs krane to only deploy resources that are filtered by the specified labels in `--selector`. The deploy will not fail if not all resources match the labels. This is useful if you only want to deploy a subset of resources within a given YAML file. See [Sharing a namespace](#sharing-a-namespace) below.
|
444
448
|
- `--global-timeout=duration`: Raise a timeout error if it takes longer than _duration_ for any
|
445
449
|
resource to deploy.
|
446
450
|
- `--no-verify-result`: Skip verification that resources correctly deployed.
|
data/dev.yml
CHANGED
@@ -13,7 +13,7 @@ up:
|
|
13
13
|
- custom:
|
14
14
|
name: Minikube Cluster
|
15
15
|
met?: test $(minikube status | grep Running | wc -l) -ge 2 && $(minikube status | grep -q 'Configured')
|
16
|
-
meet: minikube start --kubernetes-version=v1.
|
16
|
+
meet: minikube start --kubernetes-version=v1.18.18 --vm-driver=hyperkit
|
17
17
|
down: minikube stop
|
18
18
|
commands:
|
19
19
|
reset-minikube: minikube delete && rm -rf ~/.minikube
|
@@ -25,6 +25,10 @@ module Krane
|
|
25
25
|
default: true },
|
26
26
|
"selector" => { type: :string, banner: "'label=value'",
|
27
27
|
desc: "Select workloads by selector(s)" },
|
28
|
+
"selector-as-filter" => { type: :boolean,
|
29
|
+
desc: "Use --selector as a label filter to deploy only a subset "\
|
30
|
+
"of the provided resources",
|
31
|
+
default: false },
|
28
32
|
"verbose-log-prefix" => { type: :boolean, desc: "Add [context][namespace] to the log prefix",
|
29
33
|
default: false },
|
30
34
|
"verify-result" => { type: :boolean, default: true,
|
@@ -37,6 +41,11 @@ module Krane
|
|
37
41
|
require 'krane/label_selector'
|
38
42
|
|
39
43
|
selector = ::Krane::LabelSelector.parse(options[:selector]) if options[:selector]
|
44
|
+
selector_as_filter = options['selector-as-filter']
|
45
|
+
|
46
|
+
if selector_as_filter && !selector
|
47
|
+
raise(Thor::RequiredArgumentMissingError, '--selector must be set when --selector-as-filter is set')
|
48
|
+
end
|
40
49
|
|
41
50
|
logger = ::Krane::FormattedLogger.build(namespace, context,
|
42
51
|
verbose_prefix: options['verbose-log-prefix'])
|
@@ -60,6 +69,7 @@ module Krane
|
|
60
69
|
logger: logger,
|
61
70
|
global_timeout: ::Krane::DurationParser.new(options["global-timeout"]).parse!.to_i,
|
62
71
|
selector: selector,
|
72
|
+
selector_as_filter: selector_as_filter,
|
63
73
|
protected_namespaces: protected_namespaces,
|
64
74
|
)
|
65
75
|
|
@@ -16,6 +16,10 @@ module Krane
|
|
16
16
|
desc: "Verify workloads correctly deployed" },
|
17
17
|
"selector" => { type: :string, banner: "'label=value'", required: true,
|
18
18
|
desc: "Select workloads owned by selector(s)" },
|
19
|
+
"selector-as-filter" => { type: :boolean,
|
20
|
+
desc: "Use --selector as a label filter to deploy only a subset "\
|
21
|
+
"of the provided resources",
|
22
|
+
default: false },
|
19
23
|
"prune" => { type: :boolean, desc: "Enable deletion of resources that match"\
|
20
24
|
" the provided selector and do not appear in the provided templates",
|
21
25
|
default: true },
|
@@ -28,6 +32,11 @@ module Krane
|
|
28
32
|
require 'krane/duration_parser'
|
29
33
|
|
30
34
|
selector = ::Krane::LabelSelector.parse(options[:selector])
|
35
|
+
selector_as_filter = options['selector-as-filter']
|
36
|
+
|
37
|
+
if selector_as_filter && !selector
|
38
|
+
raise(Thor::RequiredArgumentMissingError, '--selector must be set when --selector-as-filter is set')
|
39
|
+
end
|
31
40
|
|
32
41
|
filenames = options[:filenames].dup
|
33
42
|
filenames << "-" if options[:stdin]
|
@@ -41,6 +50,7 @@ module Krane
|
|
41
50
|
filenames: paths,
|
42
51
|
global_timeout: ::Krane::DurationParser.new(options["global-timeout"]).parse!.to_i,
|
43
52
|
selector: selector,
|
53
|
+
selector_as_filter: selector_as_filter,
|
44
54
|
)
|
45
55
|
|
46
56
|
deploy.run!(
|
data/lib/krane/deploy_task.rb
CHANGED
@@ -100,12 +100,13 @@ module Krane
|
|
100
100
|
# @param bindings [Hash] Bindings parsed by Krane::BindingsParser
|
101
101
|
# @param global_timeout [Integer] Timeout in seconds
|
102
102
|
# @param selector [Hash] Selector(s) parsed by Krane::LabelSelector
|
103
|
+
# @param selector_as_filter [Boolean] Allow selecting a subset of Kubernetes resource templates to deploy
|
103
104
|
# @param filenames [Array<String>] An array of filenames and/or directories containing templates (*required*)
|
104
105
|
# @param protected_namespaces [Array<String>] Array of protected Kubernetes namespaces (defaults
|
105
106
|
# to Krane::DeployTask::PROTECTED_NAMESPACES)
|
106
107
|
# @param render_erb [Boolean] Enable ERB rendering
|
107
108
|
def initialize(namespace:, context:, current_sha: nil, logger: nil, kubectl_instance: nil, bindings: {},
|
108
|
-
global_timeout: nil, selector: nil, filenames: [], protected_namespaces: nil,
|
109
|
+
global_timeout: nil, selector: nil, selector_as_filter: false, filenames: [], protected_namespaces: nil,
|
109
110
|
render_erb: false, kubeconfig: nil)
|
110
111
|
@logger = logger || Krane::FormattedLogger.build(namespace, context)
|
111
112
|
@template_sets = TemplateSets.from_dirs_and_files(paths: filenames, logger: @logger, render_erb: render_erb)
|
@@ -118,6 +119,7 @@ module Krane
|
|
118
119
|
@kubectl = kubectl_instance
|
119
120
|
@global_timeout = global_timeout
|
120
121
|
@selector = selector
|
122
|
+
@selector_as_filter = selector_as_filter
|
121
123
|
@protected_namespaces = protected_namespaces || PROTECTED_NAMESPACES
|
122
124
|
@render_erb = render_erb
|
123
125
|
end
|
@@ -273,6 +275,7 @@ module Krane
|
|
273
275
|
|
274
276
|
confirm_ejson_keys_not_prunable if prune
|
275
277
|
@logger.info("Using resource selector #{@selector}") if @selector
|
278
|
+
@logger.info("Only deploying resources filtered by labels in selector") if @selector && @selector_as_filter
|
276
279
|
@namespace_tags |= tags_from_namespace_labels
|
277
280
|
@logger.info("All required parameters and files are present")
|
278
281
|
end
|
@@ -295,6 +298,7 @@ module Krane
|
|
295
298
|
batchable_resources, individuals = partition_dry_run_resources(resources.dup)
|
296
299
|
batch_dry_run_success = kubectl.server_dry_run_enabled? && validate_dry_run(batchable_resources)
|
297
300
|
individuals += batchable_resources unless batch_dry_run_success
|
301
|
+
resources.select! { |r| r.selected?(@selector) } if @selector_as_filter
|
298
302
|
Krane::Concurrency.split_across_threads(resources) do |r|
|
299
303
|
r.validate_definition(kubectl: kubectl, selector: @selector, dry_run: individuals.include?(r))
|
300
304
|
end
|
@@ -33,8 +33,10 @@ module Krane
|
|
33
33
|
# @param context [String] Kubernetes context (*required*)
|
34
34
|
# @param global_timeout [Integer] Timeout in seconds
|
35
35
|
# @param selector [Hash] Selector(s) parsed by Krane::LabelSelector (*required*)
|
36
|
+
# @param selector_as_filter [Boolean] Allow selecting a subset of Kubernetes resource templates to deploy
|
36
37
|
# @param filenames [Array<String>] An array of filenames and/or directories containing templates (*required*)
|
37
|
-
def initialize(context:, global_timeout: nil, selector: nil,
|
38
|
+
def initialize(context:, global_timeout: nil, selector: nil, selector_as_filter: false,
|
39
|
+
filenames: [], logger: nil, kubeconfig: nil)
|
38
40
|
template_paths = filenames.map { |path| File.expand_path(path) }
|
39
41
|
|
40
42
|
@task_config = TaskConfig.new(context, nil, logger, kubeconfig)
|
@@ -42,6 +44,7 @@ module Krane
|
|
42
44
|
logger: @task_config.logger, render_erb: false)
|
43
45
|
@global_timeout = global_timeout
|
44
46
|
@selector = selector
|
47
|
+
@selector_as_filter = selector_as_filter
|
45
48
|
end
|
46
49
|
|
47
50
|
# Runs the task, returning a boolean representing success or failure
|
@@ -130,6 +133,7 @@ module Krane
|
|
130
133
|
def validate_resources(resources)
|
131
134
|
validate_globals(resources)
|
132
135
|
|
136
|
+
resources.select! { |r| r.selected?(@selector) } if @selector_as_filter
|
133
137
|
Concurrency.split_across_threads(resources) do |r|
|
134
138
|
r.validate_definition(kubectl: @kubectl, selector: @selector)
|
135
139
|
end
|
data/lib/krane/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: krane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katrina Verey
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-06-
|
13
|
+
date: 2021-06-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|