resque-kubernetes 1.3.0 → 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
- SHA1:
3
- metadata.gz: c90637618ea819269c20b91f9cc752e28b435da0
4
- data.tar.gz: 94391752da8c4a799442d22e31f5cfdf3ac8cc21
2
+ SHA256:
3
+ metadata.gz: c5705807fc4c023c6d41f4ea9de1ead2e365e1a7a4153b9c0bbf507a775c17ef
4
+ data.tar.gz: 80b8d23e4914a5d59308e46e3486b8ee8935f8da0661ecf692e4a33ad5d3075f
5
5
  SHA512:
6
- metadata.gz: 9c3dcccddc78c704a909c2abba2b0acd7236ba8df30026dbaf4a0ce11958e4823064c25dfb8bdfaf3b923510fe3468088ad70d26ec799c6ca0fe037711db2f89
7
- data.tar.gz: f9257d78372f47e6a94be98d022095d05d3af32f960b402c126a760cf247060e28fd7dca34c402898e8db6d591fb79e63f6162042da130b77f4767da3c16ca02
6
+ metadata.gz: a406b7260bbb127425fa7522bb7ab579594236190f88a5a992071161da966b4a96d3a12dd442fea0a5fb4134d515a2e044b0728303858dea3c9bdab593c22b77
7
+ data.tar.gz: 71e8a8a42de666cd4a43ab5ba311349d07311bc956733c9a464203118bd098b7ab4b36928e7e800087b7efd7258b4b444f26958ccd84f509433c365619b47460
data/.rubocop.yml CHANGED
@@ -1,13 +1,17 @@
1
- Documentation:
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+
5
+ Style/Documentation:
2
6
  Exclude:
3
7
  - "**/railtie.rb"
4
8
  - "spec/**/*"
5
9
 
6
10
  Style/StringLiterals:
7
11
  EnforcedStyle: double_quotes
8
- Metrics/LineLength:
12
+ Layout/LineLength:
9
13
  Max: 120
10
- Layout/AlignHash:
14
+ Layout/HashAlignment:
11
15
  EnforcedHashRocketStyle: table
12
16
  EnforcedColonStyle: table
13
17
  Layout/SpaceInsideHashLiteralBraces:
@@ -16,9 +20,9 @@ Style/RaiseArgs:
16
20
  EnforcedStyle: compact
17
21
  Style/EmptyMethod:
18
22
  EnforcedStyle: expanded
19
- Layout/IndentArray:
23
+ Layout/FirstArrayElementIndentation:
20
24
  IndentationWidth: 4
21
- Layout/IndentHash:
25
+ Layout/FirstHashElementIndentation:
22
26
  IndentationWidth: 4
23
27
  Style/ConditionalAssignment:
24
28
  EnforcedStyle: assign_inside_condition
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 3.0.5
data/Appraisals CHANGED
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise "kubeclient-3" do
4
- gem "kubeclient", "3.1.2"
5
- end
6
-
7
3
  appraise "kubeclient-4" do
8
- gem "kubeclient", "4.0.0"
4
+ gem "kubeclient", "4.11.0"
9
5
  end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,43 @@
1
+ # V3.0.0
2
+ **Breaking Change:**
3
+ - Drop support for Ruby 2.7.
4
+ - Drop support for `kubeclient` 3.x.
5
+
6
+ **Changes:**
7
+ - Add support for Ruby 3.0.
8
+ - Requires `kubeclient` >= 4.9.3.
9
+
10
+ # V2.0.0
11
+ **Breaking Change:**
12
+ - The `environments` configuration as been replaced by a more flexible `enabled` property.
13
+
14
+ Here's how to migrate from the `environments` property to the `enabled` property:
15
+
16
+ Before:
17
+ ```ruby
18
+ # config/initializers/resque-kubernetes.rb
19
+
20
+ Resque::Kubernetes.configuration do |config|
21
+ config.environments << "staging"
22
+ config.max_workers = 10
23
+ end
24
+ ```
25
+
26
+ After:
27
+ ```ruby
28
+ # config/initializers/resque-kubernetes.rb
29
+
30
+ Resque::Kubernetes.configuration do |config|
31
+ config.enabled = Rails.env.production? || Rails.env.staging?
32
+ config.max_workers = 10
33
+ end
34
+ ```
35
+
36
+ ⚠️ By default, this gem is not enabled.
37
+
38
+ **Changes:**
39
+ - Allow resque 2.0 but retain support for 1.26 or later.
40
+
1
41
  # v1.3.0
2
42
  - Retry when a timeout occurs connecting to the Kubernetes API server
3
43
 
data/Gemfile CHANGED
@@ -4,3 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in resque-kubernetes.gemspec
6
6
  gemspec
7
+
8
+ gem "appraisal"
9
+ gem "bundler", "~> 2.0"
10
+ gem "bundler-audit", "~> 0"
11
+ gem "googleauth", "~> 0.6"
12
+ gem "rake", "~> 12.3"
13
+ gem "rspec", "~> 3.7"
14
+ gem "rubocop", "~> 1.50"
data/README.md CHANGED
@@ -152,19 +152,16 @@ your project:
152
152
  # config/initializers/resque-kubernetes.rb
153
153
 
154
154
  Resque::Kubernetes.configuration do |config|
155
- config.environments << "staging"
155
+ config.enabled = Rails.env.production? || Rails.env.staging?
156
156
  config.max_workers = 10
157
157
  end
158
158
  ```
159
159
 
160
- ### `environments`
160
+ ### `enabled`
161
161
 
162
- > This only works under Rails, when `Rails.env` is set.
162
+ ⚠️ By default, the `enabled` property is set to `false` which means that, by default, this plugin will not be launched.
163
163
 
164
- By default `Resque::Kubernetes` will only manage Kubernetes Jobs in
165
- `:production`. If you want to add other environments you can update this list
166
- (`config.environments << "staging"`) or replace it (`config.environments =
167
- ["production", "development"]`).
164
+ You should not enable this Resque plugin in environments that are not run inside a Kubernetes cluster (for example, your CI env).
168
165
 
169
166
  ### `max_workers`
170
167
 
@@ -215,7 +212,7 @@ The gem will automatically connect to the Kubernetes server in the following cas
215
212
  installed
216
213
 
217
214
  There are many other ways to connect and you can do so by providing your own
218
- [configured `kubeclient`](https://github.com/abonas/kubeclient#usage):
215
+ [configured `kubeclient`](https://github.com/ManageIQ/kubeclient#usage):
219
216
 
220
217
  ```ruby
221
218
  # config/initializers/resque-kubernetes.rb
@@ -2,6 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "kubeclient", "4.0.0"
5
+ gem "kubeclient", "4.11.0"
6
6
 
7
7
  gemspec path: "../"
8
+
9
+ gem "appraisal"
10
+ gem "bundler", "~> 2.0"
11
+ gem "bundler-audit", "~> 0"
12
+ gem "googleauth", "~> 0.6"
13
+ gem "rake", "~> 12.3"
14
+ gem "rspec", "~> 3.7"
15
+ gem "rubocop", "~> 1.50"
@@ -12,6 +12,7 @@ module Resque
12
12
  #
13
13
  # name: The name of the setting.
14
14
  # default: A default value for the setting. (Optional)
15
+ # rubocop: disable Style/ClassVars
15
16
  def define_setting(name, default = nil)
16
17
  class_variable_set("@@#{name}", default)
17
18
 
@@ -23,6 +24,7 @@ module Resque
23
24
  class_variable_get("@@#{name}")
24
25
  end
25
26
  end
27
+ # rubocop: enable Style/ClassVars
26
28
 
27
29
  private
28
30
 
@@ -9,32 +9,40 @@ module Resque
9
9
  File.exist?(kubeconfig)
10
10
  end
11
11
 
12
+ # rubocop: disable Metrics/MethodLength
12
13
  def context
13
14
  config = Kubeclient::Config.read(kubeconfig)
14
15
 
15
- Resque::Kubernetes::ContextFactory::Context.new(
16
- config.context.api_endpoint,
17
- config.context.api_version,
18
- config.context.namespace,
16
+ options = {
19
17
  auth_options: auth_options(config),
20
18
  ssl_options: config.context.ssl_options
19
+ }
20
+
21
+ Resque::Kubernetes::ContextFactory::Context.new(
22
+ config.context.api_endpoint,
23
+ config.context.api_version,
24
+ config.context.namespace,
25
+ options
21
26
  )
22
27
  end
28
+ # rubocop: enable Metrics/MethodLength
23
29
 
24
30
  private
25
31
 
26
32
  def kubeconfig
27
- File.join(ENV["HOME"], ".kube", "config")
33
+ File.join(Dir.home, ".kube", "config")
28
34
  end
29
35
 
30
36
  def auth_options(config)
31
37
  options = config.context.auth_options
32
38
  return options unless options.empty?
39
+
33
40
  google_application_default_credentials
34
41
  end
35
42
 
36
43
  def google_application_default_credentials
37
44
  return unless defined?(Google) && defined?(Google::Auth)
45
+
38
46
  {bearer_token: Kubeclient::GoogleApplicationDefaultCredentials.token}
39
47
  end
40
48
  end
@@ -14,12 +14,16 @@ module Resque
14
14
  end
15
15
 
16
16
  def context
17
- Resque::Kubernetes::ContextFactory::Context.new(
18
- "https://kubernetes.default.svc",
19
- "v1",
20
- namespace,
17
+ options = {
21
18
  auth_options: {bearer_token_file: TOKEN_FILE},
22
19
  ssl_options: ssl_options
20
+ }
21
+
22
+ Resque::Kubernetes::ContextFactory::Context.new(
23
+ "https://kubernetes.default.svc",
24
+ "v1",
25
+ namespace,
26
+ options
23
27
  )
24
28
  end
25
29
 
@@ -27,11 +31,13 @@ module Resque
27
31
 
28
32
  def namespace
29
33
  return nil unless File.exist?(NAMESPACE_FILE)
34
+
30
35
  File.read(NAMESPACE_FILE)
31
36
  end
32
37
 
33
38
  def ssl_options
34
39
  return {} unless File.exist?(CA_FILE)
40
+
35
41
  {ca_file: CA_FILE}
36
42
  end
37
43
  end
@@ -10,7 +10,6 @@ module Resque
10
10
 
11
11
  class << self
12
12
  def context
13
- # TODO: Add ability to load this from config
14
13
  [
15
14
  Resque::Kubernetes::Context::WellKnown,
16
15
  Resque::Kubernetes::Context::Kubectl
@@ -18,6 +17,8 @@ module Resque
18
17
  context = context_type.new
19
18
  return context.context if context.applicable?
20
19
  end
20
+
21
+ nil
21
22
  end
22
23
  end
23
24
  end
@@ -78,14 +78,13 @@ module Resque
78
78
  module Job
79
79
  def self.included(base)
80
80
  return unless base.respond_to?(:before_enqueue)
81
+
81
82
  base.before_enqueue :before_enqueue_kubernetes_job
82
83
  end
83
84
 
84
85
  # A before_enqueue hook that adds worker jobs to the cluster.
85
86
  def before_enqueue_kubernetes_job(*_args)
86
- if defined? Rails
87
- return unless Resque::Kubernetes.environments.include?(Rails.env)
88
- end
87
+ return unless Resque::Kubernetes.enabled
89
88
 
90
89
  manager = JobsManager.new(self)
91
90
  manager.reap_finished_jobs
@@ -20,21 +20,17 @@ module Resque
20
20
 
21
21
  def reap_finished_jobs
22
22
  finished_jobs.each do |job|
23
- begin
24
- jobs_client.delete_job(job.metadata.name, job.metadata.namespace)
25
- rescue KubeException => e
26
- raise unless e.error_code == 404
27
- end
23
+ jobs_client.delete_job(job.metadata.name, job.metadata.namespace)
24
+ rescue KubeException => e
25
+ raise unless e.error_code == 404
28
26
  end
29
27
  end
30
28
 
31
29
  def reap_finished_pods
32
30
  finished_pods.each do |pod|
33
- begin
34
- pods_client.delete_pod(pod.metadata.name, pod.metadata.namespace)
35
- rescue KubeException => e
36
- raise unless e.error_code == 404
37
- end
31
+ pods_client.delete_pod(pod.metadata.name, pod.metadata.namespace)
32
+ rescue KubeException => e
33
+ raise unless e.error_code == 404
38
34
  end
39
35
  end
40
36
 
@@ -63,6 +59,7 @@ module Resque
63
59
 
64
60
  def client(scope)
65
61
  return RetriableClient.new(Resque::Kubernetes.kubeclient) if Resque::Kubernetes.kubeclient
62
+
66
63
  client = build_client(scope)
67
64
  RetriableClient.new(client) if client
68
65
  end
@@ -70,18 +67,19 @@ module Resque
70
67
  def build_client(scope)
71
68
  context = ContextFactory.context
72
69
  return unless context
70
+
73
71
  @default_namespace = context.namespace if context.namespace
74
72
 
75
- Kubeclient::Client.new(context.endpoint + scope, context.version, context.options)
73
+ Kubeclient::Client.new(context.endpoint + scope, context.version, **context.options)
76
74
  end
77
75
 
78
76
  def finished_jobs
79
- resque_jobs = jobs_client.get_jobs(label_selector: "resque-kubernetes=job")
77
+ resque_jobs = jobs_client.get_jobs({label_selector: "resque-kubernetes=job"})
80
78
  resque_jobs.select { |job| job.spec.completions == job.status.succeeded }
81
79
  end
82
80
 
83
81
  def finished_pods
84
- resque_jobs = pods_client.get_pods(label_selector: "resque-kubernetes=pod")
82
+ resque_jobs = pods_client.get_pods({label_selector: "resque-kubernetes=pod"})
85
83
  resque_jobs.select do |pod|
86
84
  pod.status.phase == "Succeeded" && pod.status.containerStatuses.all? do |status|
87
85
  status.state.terminated.reason == "Completed"
@@ -90,10 +88,10 @@ module Resque
90
88
  end
91
89
 
92
90
  def jobs_maxed?(name, namespace)
93
- resque_jobs = jobs_client.get_jobs(
94
- label_selector: "resque-kubernetes=job,resque-kubernetes-group=#{name}",
95
- namespace: namespace
96
- )
91
+ resque_jobs = jobs_client.get_jobs({
92
+ label_selector: "resque-kubernetes=job,resque-kubernetes-group=#{name}",
93
+ namespace: namespace
94
+ })
97
95
  running = resque_jobs.reject { |job| job.spec.completions == job.status.succeeded }
98
96
  running.size >= owner.max_workers
99
97
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Resque
4
4
  module Kubernetes
5
- VERSION = "1.3.0"
5
+ VERSION = "3.0.0"
6
6
  end
7
7
  end
@@ -19,8 +19,8 @@ module Resque
19
19
  module Kubernetes
20
20
  extend Configurable
21
21
 
22
- # By default only manage kubernetes jobs in :production
23
- define_setting :environments, ["production"]
22
+ # By default, this plugin is not active.
23
+ define_setting :enabled, false
24
24
 
25
25
  # Limit the number of workers that should be spun up, default 10
26
26
  define_setting :max_workers, 10
@@ -23,16 +23,10 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_development_dependency "appraisal"
27
- spec.add_development_dependency "bundler", "~> 1.16"
28
- spec.add_development_dependency "bundler-audit", "~> 0"
29
- spec.add_development_dependency "googleauth", "~> 0.6"
30
- spec.add_development_dependency "rake", "~> 12.3"
31
- spec.add_development_dependency "rspec", "~> 3.7"
32
- # Pinned less than 0.56.0 until this is resolved: https://github.com/rubocop-hq/rubocop/issues/5975
33
- spec.add_development_dependency "rubocop", "~> 0.52", ">= 0.52.1", "< 0.56.0"
26
+ spec.required_ruby_version = ">= 3.0"
34
27
 
35
- spec.add_dependency "kubeclient", ">= 3.1.2", "< 5.0"
36
- spec.add_dependency "resque", "~> 1.26"
28
+ spec.add_dependency "kubeclient", ">= 4.9.3", "< 5.0"
29
+ spec.add_dependency "resque", ">= 1.26"
37
30
  spec.add_dependency "retriable", "~> 3.0"
31
+ spec.metadata["rubygems_mfa_required"] = "true"
38
32
  end
metadata CHANGED
@@ -1,132 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-kubernetes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Wadsack
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-11 00:00:00.000000000 Z
11
+ date: 2023-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: appraisal
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.16'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.16'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler-audit
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: googleauth
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0.6'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0.6'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '12.3'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '12.3'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '3.7'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '3.7'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0.52'
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: 0.52.1
107
- - - "<"
108
- - !ruby/object:Gem::Version
109
- version: 0.56.0
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: '0.52'
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: 0.52.1
120
- - - "<"
121
- - !ruby/object:Gem::Version
122
- version: 0.56.0
123
13
  - !ruby/object:Gem::Dependency
124
14
  name: kubeclient
125
15
  requirement: !ruby/object:Gem::Requirement
126
16
  requirements:
127
17
  - - ">="
128
18
  - !ruby/object:Gem::Version
129
- version: 3.1.2
19
+ version: 4.9.3
130
20
  - - "<"
131
21
  - !ruby/object:Gem::Version
132
22
  version: '5.0'
@@ -136,7 +26,7 @@ dependencies:
136
26
  requirements:
137
27
  - - ">="
138
28
  - !ruby/object:Gem::Version
139
- version: 3.1.2
29
+ version: 4.9.3
140
30
  - - "<"
141
31
  - !ruby/object:Gem::Version
142
32
  version: '5.0'
@@ -144,14 +34,14 @@ dependencies:
144
34
  name: resque
145
35
  requirement: !ruby/object:Gem::Requirement
146
36
  requirements:
147
- - - "~>"
37
+ - - ">="
148
38
  - !ruby/object:Gem::Version
149
39
  version: '1.26'
150
40
  type: :runtime
151
41
  prerelease: false
152
42
  version_requirements: !ruby/object:Gem::Requirement
153
43
  requirements:
154
- - - "~>"
44
+ - - ">="
155
45
  - !ruby/object:Gem::Version
156
46
  version: '1.26'
157
47
  - !ruby/object:Gem::Dependency
@@ -189,7 +79,6 @@ files:
189
79
  - Rakefile
190
80
  - bin/console
191
81
  - bin/setup
192
- - gemfiles/kubeclient_3.gemfile
193
82
  - gemfiles/kubeclient_4.gemfile
194
83
  - lib/resque/kubernetes.rb
195
84
  - lib/resque/kubernetes/configurable.rb
@@ -207,8 +96,9 @@ files:
207
96
  homepage: https://github.com/keylimetoolbox/resque-kubernetes
208
97
  licenses:
209
98
  - MIT
210
- metadata: {}
211
- post_install_message:
99
+ metadata:
100
+ rubygems_mfa_required: 'true'
101
+ post_install_message:
212
102
  rdoc_options: []
213
103
  require_paths:
214
104
  - lib
@@ -216,16 +106,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
216
106
  requirements:
217
107
  - - ">="
218
108
  - !ruby/object:Gem::Version
219
- version: '0'
109
+ version: '3.0'
220
110
  required_rubygems_version: !ruby/object:Gem::Requirement
221
111
  requirements:
222
112
  - - ">="
223
113
  - !ruby/object:Gem::Version
224
114
  version: '0'
225
115
  requirements: []
226
- rubyforge_project:
227
- rubygems_version: 2.5.1
228
- signing_key:
116
+ rubygems_version: 3.2.33
117
+ signing_key:
229
118
  specification_version: 4
230
119
  summary: Run Resque Jobs as Kubernetes Jobs
231
120
  test_files: []
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "kubeclient", "3.1.2"
6
-
7
- gemspec path: "../"