krane 2.4.9 → 3.0.0

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: 19143bcc0bff115c5217d341827f0ff1d599598d86aa580fcbb73c53ddc035dd
4
- data.tar.gz: 05fa737ceb0bf4150b27be5e9d80ad24e37fed4479805bc54dfbe93f0feff081
3
+ metadata.gz: aeb4645e62609672df9a1a4fbe8323e801cdc904d45ae79aaa047d1f1cb8f1e7
4
+ data.tar.gz: de5c4a20c870041a532d22208c23d002f14c5ff0b6dae8ba8db1b9cc2d088c36
5
5
  SHA512:
6
- metadata.gz: 1bb4fc65f921987387d8858b468fba3ed1f1f8fb00539e64ca75fa0c0cc817a87d87f9f59503feae19315d08ce54f0037b803a7c3638149cabc0eec46af99d94
7
- data.tar.gz: 61efdb8c0a9a6ccfeee0414b0df447b64a4dabe5a88afcd10a630819c8b26629f14ac05f09eb11e5d68d48a8f4b2c899abbfe40e5effc78666a33907d2cc3304
6
+ metadata.gz: a8e4b1a9d17a537c533c8ecab1a7146c093ef6b0ddaedcbab76b7451d9ff18541ea73788614ba74739d1804a08146bb98e26d3f984b902dc6d609bcc8ca95a5a
7
+ data.tar.gz: 45aff6ae937b76ffb4cbb1f7fe3ffd4eceb73ae48442f8260c2a97689191cbfc991ba7767736aa2b048db51d5f1f169f8062d3e0d1c0c60acd8ee550c66e0690
@@ -6,64 +6,46 @@ jobs:
6
6
  ruby-tests:
7
7
  runs-on: ubuntu-latest
8
8
 
9
- name: "Tests - Ruby ${{ matrix.ruby }} with k8s ${{ matrix.kubernetes_version }}"
9
+ name: "Tests - Ruby ${{ matrix.ruby }} with Kubernetes ${{ matrix.kubernetes_version }}"
10
10
  strategy:
11
11
  fail-fast: false
12
12
  matrix:
13
13
  ruby:
14
- # Use unique Ruby versions, or GitHub gets confused when building the rest of the matrix
15
- - '3.1.2' # With k8s 1.23
16
- - '3.0.3' # With k8s 1.23
17
- - '3.0.2' # With k8s 1.22
18
- - '3.0.1' # With k8s 1.21
19
- - '3.0' # With k8s 1.20
20
- - '2.7' # With k8s 1.19
14
+ - "3.1.2"
15
+ - "3.0.4"
16
+ - "2.7.6"
17
+ kubernetes_version:
18
+ - "1.24.6"
19
+ - "1.23.12"
20
+ - "1.22.15"
21
21
  include:
22
- # Match kind images with chosen version https://github.com/kubernetes-sigs/kind/releases
23
- - ruby: '3.1.2'
24
- kind_version: 'v0.11.1'
25
- kubernetes_version: '1.23.0'
26
- kind_image: 'kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac'
27
- - ruby: '3.0.3'
28
- kind_version: 'v0.11.1'
29
- kubernetes_version: '1.23.0'
30
- kind_image: 'kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac'
31
- - ruby: '3.0.2'
32
- kind_version: 'v0.11.1'
33
- kubernetes_version: '1.22.0'
34
- kind_image: 'kindest/node:v1.22.0@sha256:b8bda84bb3a190e6e028b1760d277454a72267a5454b57db34437c34a588d047'
35
- - ruby: '3.0.1'
36
- kind_version: 'v0.11.1'
37
- kubernetes_version: '1.21.1'
38
- kind_image: 'kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6'
39
- - ruby: '3.0'
40
- kind_version: 'v0.11.1'
41
- kubernetes_version: '1.20.7'
42
- kind_image: 'kindest/node:v1.20.7@sha256:cbeaf907fc78ac97ce7b625e4bf0de16e3ea725daf6b04f930bd14c67c671ff9'
43
- - ruby: '2.7'
44
- kind_version: 'v0.11.1'
45
- kubernetes_version: '1.19.11'
46
- kind_image: 'kindest/node:v1.19.11@sha256:07db187ae84b4b7de440a73886f008cf903fcf5764ba8106a9fd5243d6f32729'
22
+ - kubernetes_version: "1.24.6"
23
+ kind_image: "kindest/node:v1.24.6@sha256:97e8d00bc37a7598a0b32d1fabd155a96355c49fa0d4d4790aab0f161bf31be1"
24
+ - kubernetes_version: "1.23.12"
25
+ kind_image: "kindest/node:v1.23.12@sha256:9402cf1330bbd3a0d097d2033fa489b2abe40d479cc5ef47d0b6a6960613148a"
26
+ - kubernetes_version: "1.22.15"
27
+ kind_image: "kindest/node:v1.22.15@sha256:bfd5eaae36849bfb3c1e3b9442f3da17d730718248939d9d547e86bbac5da586"
47
28
 
48
29
  steps:
49
30
  - uses: actions/checkout@v2
50
31
 
51
- - name: Set up Ruby ${{ matrix.ruby }}
32
+ - name: Setup Ruby ${{ matrix.ruby }}
52
33
  uses: ruby/setup-ruby@v1
53
34
  with:
54
35
  ruby-version: ${{ matrix.ruby }}
55
36
  bundler-cache: true
56
37
 
57
- - name: Setup kubectl
38
+ - name: Setup kubectl ${{ matrix.kubernetes_version }}
58
39
  run: |
59
40
  mkdir -p "${GITHUB_WORKSPACE}/bin"
60
41
  curl -o "${GITHUB_WORKSPACE}/bin/kubectl" -LO "https://dl.k8s.io/release/v${{ matrix.kubernetes_version }}/bin/linux/amd64/kubectl"
61
42
  chmod +x "${GITHUB_WORKSPACE}/bin/kubectl"
62
43
  echo "PATH=$GITHUB_WORKSPACE/bin:${PATH}" >> $GITHUB_ENV
63
44
 
64
- - uses: engineerd/setup-kind@v0.5.0
45
+ - name: Setup Kind v0.16.0
46
+ uses: engineerd/setup-kind@v0.5.0
65
47
  with:
66
- version: "${{ matrix.kind_version }}"
48
+ version: v0.16.0
67
49
  image: "${{ matrix.kind_image }}"
68
50
 
69
51
  - name: Run tests
@@ -0,0 +1,22 @@
1
+ name: Contributor License Agreement (CLA)
2
+
3
+ on:
4
+ pull_request_target:
5
+ types: [opened, synchronize]
6
+ issue_comment:
7
+ types: [created]
8
+
9
+ jobs:
10
+ cla:
11
+ runs-on: ubuntu-latest
12
+ if: |
13
+ (github.event.issue.pull_request
14
+ && !github.event.issue.pull_request.merged_at
15
+ && contains(github.event.comment.body, 'signed')
16
+ )
17
+ || (github.event.pull_request && !github.event.pull_request.merged)
18
+ steps:
19
+ - uses: Shopify/shopify-cla-action@v1
20
+ with:
21
+ github-token: ${{ secrets.GITHUB_TOKEN }}
22
+ cla-token: ${{ secrets.CLA_TOKEN }}
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## next
2
2
 
3
+
4
+ ## 3.0.0
5
+
6
+ *Enhancements*
7
+
8
+ - CI test matrix now test all Krane supported Ruby and Kubernetes versions.
9
+ Ruby: 3.1.2 , 3.0.4 , 2.7.6, Kubernetes: - 1.24.6, 1.23.12, 1.22.15.
10
+
11
+ *Breaking Changes*
12
+ - Remove unsupported Kubernetes and Ruby versions from Krane and CI [#905](https://github.com/Shopify/krane/pull/905).
13
+ See supported Kubernetes and Ruby versions in [Compatibility](./CONTRIBUTING.md#compatibility).
14
+ If you are using Kubernetes <v1.22 keep using Krane v2.4.9.
15
+
3
16
  ## 2.4.9
4
17
 
5
18
  - Fixed a Ruby 3.1 regression that caused an exception when using a `--bindings=@<file>` argument to `krane render` [#900](https://github.com/Shopify/krane/pull/900)
data/CONTRIBUTING.md CHANGED
@@ -29,9 +29,7 @@ behavior to [krane@shopify.com](mailto:krane@shopify.com).
29
29
  ## Maintainers
30
30
 
31
31
  This project is currently under the stewardship of the Production Platform group at Shopify.
32
- The two primary maintainers are @knverey and @dturn. Approval from at least one primary maintainer is
33
- required for all significant feature proposals and code architecture changes. In general,
34
- two people must approve all non-trivial PRs.
32
+ In general, two people must approve all non-trivial PRs.
35
33
 
36
34
  ## What should I know before I get started?
37
35
 
@@ -113,7 +111,7 @@ This gem uses subclasses of `KubernetesResource` to implement custom success/fai
113
111
 
114
112
  If you work for Shopify, just run `dev up`, but otherwise:
115
113
 
116
- 1. [Install kubectl version 1.10.0 or higher](https://kubernetes.io/docs/user-guide/prereqs/) and make sure it is in your path
114
+ 1. [Install kubectl version 1.22.0 or higher](https://kubernetes.io/docs/user-guide/prereqs/) and make sure it is in your path
117
115
  2. [Install minikube](https://kubernetes.io/docs/getting-started-guides/minikube/#installation) (required to run the test suite)
118
116
  3. [Install any required minikube drivers](https://github.com/kubernetes/minikube/blob/master/docs/drivers.md) (on OS X, you may need the [hyperkit driver](https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperkit-driver)
119
117
  4. Check out the repo
data/README.md CHANGED
@@ -74,23 +74,28 @@ If you need the ability to render dynamic values in templates before deploying,
74
74
  ## Prerequisites
75
75
 
76
76
  * Ruby 2.7+
77
- * Your cluster must be running Kubernetes v1.19.0 or higher<sup>1</sup>
77
+ * Your cluster must be running Kubernetes v1.22.0 or higher<sup>1</sup>
78
78
 
79
- <sup>1</sup> We run integration tests against these Kubernetes versions. You can find our
80
- official compatibility chart below.
79
+ ## Compatibility
80
+
81
+ <sup>1</sup> We run integration tests against these Kubernetes versions. You can find our official compatibility chart below.
82
+
83
+ Krane provides support for official upstream supported versions [Kubernetes](https://endoflife.date/kubernetes), [Ruby](https://endoflife.date/ruby) that are part of the compatibility matrix; Nevertheless, older releases are still likely to work.
81
84
 
82
85
  | Kubernetes version | Currently Tested? | Last officially supported in gem version |
83
86
  |:------------------:|-------------------|:----------------------------------------:|
84
87
  | 1.18 | No | 2.3.7 |
85
- | 1.19 | Yes | -- |
86
- | 1.20 | Yes | -- |
87
- | 1.21 | Yes | -- |
88
+ | 1.19 | No | 2.4.9 |
89
+ | 1.20 | No | 2.4.9 |
90
+ | 1.21 | No | 2.4.9 |
88
91
  | 1.22 | Yes | -- |
89
92
  | 1.23 | Yes | -- |
93
+ | 1.24 | Yes | -- |
94
+ | 1.25 | No | -- |
90
95
 
91
96
  ## Installation
92
97
 
93
- 1. [Install kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-via-curl) (requires v1.19.0 or higher) and make sure it is available in your $PATH
98
+ 1. [Install kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-via-curl) (requires v1.22.0 or higher) and make sure it is available in your $PATH
94
99
  2. Set up your [kubeconfig file](https://kubernetes.io/docs/tasks/access-application-cluster/authenticate-across-clusters-kubeconfig/) for access to your cluster(s).
95
100
  3. `gem install krane`
96
101
 
@@ -497,7 +502,7 @@ resource to restart.
497
502
 
498
503
  ## Prerequisites
499
504
 
500
- * You've already deployed a [`PodTemplate`](https://v1-15.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.15/#podtemplate-v1-core) object with field `template` containing a `Pod` specification that does not include the `apiVersion` or `kind` parameters. An example is provided in this repo in `test/fixtures/hello-cloud/template-runner.yml`.
505
+ * You've already deployed a [`PodTemplate`](https://v1-22.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#podtemplate-v1-core) object with field `template` containing a `Pod` specification that does not include the `apiVersion` or `kind` parameters. An example is provided in this repo in `test/fixtures/hello-cloud/template-runner.yml`.
501
506
  * The `Pod` specification in that template has a container named `task-runner`.
502
507
 
503
508
  Based on this specification `krane run` will create a new pod with the entrypoint of the `task-runner ` container overridden with the supplied arguments.
data/bin/ci CHANGED
@@ -16,5 +16,5 @@ docker run --rm \
16
16
  -e VERBOSE=1 \
17
17
  -e PARALLELISM=$PARALLELISM \
18
18
  -w /usr/src/app \
19
- ruby:"${RUBY_VERSION:-2.6.6}" \
19
+ ruby:"${RUBY_VERSION:-2.7.6}" \
20
20
  bin/test
data/bin/setup CHANGED
@@ -9,8 +9,8 @@ if [ ! -x "$(which minikube)" ]; then
9
9
  fi
10
10
 
11
11
  if [ ! -x "$(which kubectl)" ]; then
12
- echo -e "\n\033[0;33mPlease install kubectl version 1.15.0 or higher:\nhttps://kubernetes.io/docs/user-guide/prereqs/\033[0m"
12
+ echo -e "\n\033[0;33mPlease install kubectl version 1.22.0 or higher:\nhttps://kubernetes.io/docs/user-guide/prereqs/\033[0m"
13
13
  else
14
14
  KUBECTL_VERSION=$(kubectl version --short --client | grep -oe "v[[:digit:]\.]\+")
15
- echo -e "\n\033[0;32mKubectl version $KUBECTL_VERSION is already installed. This gem requires version v1.15.0 or greater.\033[0m"
15
+ echo -e "\n\033[0;32mKubectl version $KUBECTL_VERSION is already installed. This gem requires version v1.22.0 or greater.\033[0m"
16
16
  fi
data/dev.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  ---
2
2
  name: krane
3
3
  up:
4
- - ruby: '3.0.3' # Matches gemspec
4
+ - ruby: '3.1.2' # Matches gemspec
5
5
  - bundler
6
6
  - podman
7
7
  - kind:
8
8
  name: krane
9
- image: kindest/node:v1.22.0@sha256:b8bda84bb3a190e6e028b1760d277454a72267a5454b57db34437c34a588d047
9
+ image: kindest/node:v1.24.6@sha256:97e8d00bc37a7598a0b32d1fabd155a96355c49fa0d4d4790aab0f161bf31be1
10
10
  commands:
11
11
  test:
12
12
  run: bin/test
data/krane.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.metadata['allowed_push_host'] = "https://rubygems.org"
27
27
 
28
- spec.required_ruby_version = '>= 2.6.0'
28
+ spec.required_ruby_version = '>= 2.7.6'
29
29
  spec.add_dependency("activesupport", ">= 5.0")
30
30
  spec.add_dependency("kubeclient", "~> 4.9")
31
31
  spec.add_dependency("googleauth", "~> 1.2")
@@ -37,19 +37,6 @@ module Krane
37
37
  end.compact.uniq { |r| "#{r['apigroup']}/#{r['kind']}" }
38
38
  end
39
39
 
40
- def fetch_mutating_webhook_configurations
41
- command = %w(get mutatingwebhookconfigurations)
42
- raw_json, err, st = kubectl.run(*command, output: "json", attempts: 5, use_namespace: false)
43
- if st.success?
44
- JSON.parse(raw_json)["items"].map do |definition|
45
- Krane::MutatingWebhookConfiguration.new(namespace: namespace, context: context, logger: logger,
46
- definition: definition, statsd_tags: @namespace_tags)
47
- end
48
- else
49
- raise FatalKubeAPIError, "Error retrieving mutatingwebhookconfigurations: #{err}"
50
- end
51
- end
52
-
53
40
  private
54
41
 
55
42
  # During discovery, the api paths may not actually be at the root, so we must programatically find it.
data/lib/krane/common.rb CHANGED
@@ -20,5 +20,5 @@ require 'krane/task_config'
20
20
  require 'krane/task_config_validator'
21
21
 
22
22
  module Krane
23
- MIN_KUBE_VERSION = '1.15.0'
23
+ MIN_KUBE_VERSION = '1.22.0'
24
24
  end
@@ -30,7 +30,6 @@ require 'krane/kubernetes_resource'
30
30
  custom_resource_definition
31
31
  horizontal_pod_autoscaler
32
32
  secret
33
- mutating_webhook_configuration
34
33
  ).each do |subresource|
35
34
  require "krane/kubernetes_resource/#{subresource}"
36
35
  end
@@ -285,26 +284,18 @@ module Krane
285
284
  end
286
285
  measure_method(:validate_configuration)
287
286
 
288
- def partition_dry_run_resources(resources)
289
- individuals = []
290
- mutating_webhook_configurations = cluster_resource_discoverer.fetch_mutating_webhook_configurations
291
- mutating_webhook_configurations.each do |mutating_webhook_configuration|
292
- mutating_webhook_configuration.webhooks.each do |webhook|
293
- individuals = (individuals + resources.select { |resource| webhook.matches_resource?(resource) }).uniq
294
- resources -= individuals
295
- end
296
- end
297
- [resources, individuals]
298
- end
299
-
300
287
  def validate_resources(resources)
301
288
  validate_globals(resources)
302
- batchable_resources, individuals = partition_dry_run_resources(resources.dup)
303
- batch_dry_run_success = kubectl.server_dry_run_enabled? && validate_dry_run(batchable_resources)
304
- individuals += batchable_resources unless batch_dry_run_success
289
+ batch_dry_run_success = validate_dry_run(resources)
305
290
  resources.select! { |r| r.selected?(@selector) } if @selector_as_filter
291
+
306
292
  Krane::Concurrency.split_across_threads(resources) do |r|
307
- r.validate_definition(kubectl: kubectl, selector: @selector, dry_run: individuals.include?(r))
293
+ # No need to pass in kubectl (and do per-resource dry run apply) if batch dry run succeeded
294
+ if batch_dry_run_success
295
+ r.validate_definition(kubectl: nil, selector: @selector, dry_run: false)
296
+ else
297
+ r.validate_definition(kubectl: kubectl, selector: @selector, dry_run: true)
298
+ end
308
299
  end
309
300
  failed_resources = resources.select(&:validation_failed?)
310
301
  if failed_resources.present?
data/lib/krane/kubectl.rb CHANGED
@@ -109,11 +109,7 @@ module Krane
109
109
  end
110
110
 
111
111
  def dry_run_flag
112
- if client_version >= Gem::Version.new("1.18")
113
- "--dry-run=server"
114
- else
115
- "--server-dry-run"
116
- end
112
+ "--dry-run=server"
117
113
  end
118
114
 
119
115
  private
@@ -226,11 +226,6 @@ module Krane
226
226
  version ? grouping : "core"
227
227
  end
228
228
 
229
- def version
230
- prefix, version = @definition.dig("apiVersion").split("/")
231
- version || prefix
232
- end
233
-
234
229
  def kubectl_resource_type
235
230
  type
236
231
  end
@@ -569,11 +564,7 @@ module Krane
569
564
 
570
565
  # Server side dry run is only supported on apply
571
566
  def validate_with_server_side_dry_run(kubectl)
572
- command = if kubectl.client_version >= Gem::Version.new('1.18')
573
- ["apply", "-f", file_path, "--dry-run=server", "--output=name"]
574
- else
575
- ["apply", "-f", file_path, "--server-dry-run", "--output=name"]
576
- end
567
+ command = ["apply", "-f", file_path, "--dry-run=server", "--output=name"]
577
568
 
578
569
  kubectl.run(*command, log_failure: false, output_is_sensitive: sensitive_template_content?,
579
570
  retry_whitelist: [:client_timeout, :empty, :context_deadline], attempts: 3)
@@ -584,11 +575,7 @@ module Krane
584
575
  # If the resource template uses generateName, validating with apply will fail
585
576
  def validate_with_local_dry_run(kubectl)
586
577
  verb = deploy_method == :apply ? "apply" : "create"
587
- command = if kubectl.client_version >= Gem::Version.new('1.18')
588
- [verb, "-f", file_path, "--dry-run=client", "--output=name"]
589
- else
590
- [verb, "-f", file_path, "--dry-run", "--output=name"]
591
- end
578
+ command = [verb, "-f", file_path, "--dry-run=client", "--output=name"]
592
579
 
593
580
  kubectl.run(*command, log_failure: false, output_is_sensitive: sensitive_template_content?,
594
581
  retry_whitelist: [:client_timeout, :empty, :context_deadline], attempts: 3, use_namespace: !global?)
data/lib/krane/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Krane
3
- VERSION = "2.4.9"
3
+ VERSION = "3.0.0"
4
4
  end
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.9
4
+ version: 3.0.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: 2022-07-28 00:00:00.000000000 Z
13
+ date: 2022-10-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -413,9 +413,9 @@ extra_rdoc_files: []
413
413
  files:
414
414
  - ".github/CODEOWNERS"
415
415
  - ".github/ISSUE_TEMPLATE.md"
416
- - ".github/probots.yml"
417
416
  - ".github/pull_request_template.md"
418
417
  - ".github/workflows/ci.yml"
418
+ - ".github/workflows/cla.yml"
419
419
  - ".gitignore"
420
420
  - ".rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml"
421
421
  - ".rubocop.yml"
@@ -472,7 +472,6 @@ files:
472
472
  - lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
473
473
  - lib/krane/kubernetes_resource/ingress.rb
474
474
  - lib/krane/kubernetes_resource/job.rb
475
- - lib/krane/kubernetes_resource/mutating_webhook_configuration.rb
476
475
  - lib/krane/kubernetes_resource/network_policy.rb
477
476
  - lib/krane/kubernetes_resource/persistent_volume_claim.rb
478
477
  - lib/krane/kubernetes_resource/pod.rb
@@ -519,7 +518,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
519
518
  requirements:
520
519
  - - ">="
521
520
  - !ruby/object:Gem::Version
522
- version: 2.6.0
521
+ version: 2.7.6
523
522
  required_rubygems_version: !ruby/object:Gem::Requirement
524
523
  requirements:
525
524
  - - ">="
data/.github/probots.yml DELETED
@@ -1,2 +0,0 @@
1
- enabled:
2
- - cla
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Krane
4
- class MutatingWebhookConfiguration < KubernetesResource
5
- GLOBAL = true
6
-
7
- class Webhook
8
- EQUIVALENT = 'Equivalent'
9
- EXACT = 'Exact'
10
-
11
- class Rule
12
- def initialize(definition)
13
- @definition = definition
14
- end
15
-
16
- def matches_resource?(resource, accept_equivalent:)
17
- groups.each do |group|
18
- versions.each do |version|
19
- resources.each do |kind|
20
- return true if (resource.group == group || group == '*' || accept_equivalent) &&
21
- (resource.version == version || version == '*' || accept_equivalent) &&
22
- (resource.type.downcase == kind.downcase.singularize || kind == "*")
23
- end
24
- end
25
- end
26
- false
27
- end
28
-
29
- def groups
30
- @definition.dig('apiGroups')
31
- end
32
-
33
- def versions
34
- @definition.dig('apiVersions')
35
- end
36
-
37
- def resources
38
- @definition.dig('resources')
39
- end
40
- end
41
-
42
- def initialize(definition)
43
- @definition = definition
44
- end
45
-
46
- def side_effects
47
- @definition.dig('sideEffects')
48
- end
49
-
50
- def has_side_effects?
51
- # Note: After K8s 1.22, this should ALWAYS be false.
52
- !%w(None NoneOnDryRun).include?(side_effects)
53
- end
54
-
55
- def match_policy
56
- @definition.dig('matchPolicy')
57
- end
58
-
59
- def matches_resource?(resource, skip_rule_if_side_effect_none: true)
60
- return false if skip_rule_if_side_effect_none && !has_side_effects?
61
- rules.any? do |rule|
62
- rule.matches_resource?(resource, accept_equivalent: match_policy == EQUIVALENT)
63
- end
64
- end
65
-
66
- def rules
67
- @definition.fetch('rules', []).map { |rule| Rule.new(rule) }
68
- end
69
- end
70
-
71
- def initialize(namespace:, context:, definition:, logger:, statsd_tags:)
72
- @webhooks = (definition.dig('webhooks') || []).map { |hook| Webhook.new(hook) }
73
- super(namespace: namespace, context: context, definition: definition,
74
- logger: logger, statsd_tags: statsd_tags)
75
- end
76
-
77
- TIMEOUT = 30.seconds
78
-
79
- def deploy_succeeded?
80
- exists?
81
- end
82
-
83
- def webhooks
84
- @definition.fetch('webhooks', []).map { |webhook| Webhook.new(webhook) }
85
- end
86
- end
87
- end