cron-kubernetes 0.1.0 → 2.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: f95641f4e595e197c2205b213097349df8b5f93c4f4c6556416f66bb6c1dd636
4
- data.tar.gz: 3fb3993388b2f631c1b73e297a18340b45c197368a24486b7b5f3ca7cb7395bc
3
+ metadata.gz: 8d270469720001ff34f95dd439c0de2a23c282a33ccd4ed1b14f4286f39968c8
4
+ data.tar.gz: ab6337710606835428a34ba7a5e7bc8530bf6e8e09eca98a1f245866c4e2ea40
5
5
  SHA512:
6
- metadata.gz: 128dc9682185ff67c49804d099a05056f6403ef4f25ad6161401d8fbf10881b325e141b2dd631445db2570e67c8ba499fb05eef433372e1feedc08a813c4f03e
7
- data.tar.gz: 267f422c41cceee4a2bef3293918504322c6f468573eb4158898c71027b3d6ee28973178021af25cc951f9b7d26606c12c9fc77e65a132ca442a6ca6bb506584
6
+ metadata.gz: e5a914ae99f3475d65145458746ed5fe78c0599c1a188b96469332c6b0cf112cde6be15008f0943c3bded3e19b184008fa10077854f660628ddf0ecd241a09fd
7
+ data.tar.gz: a38265b2e4c43ddb8c3f70a10cbd9a8fe5729930c8a11ee120678323ee8e26dd934d44681da36212671314b6f791c6384ee1b38183d4340d8e192b7430d82e5e
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- /.bundle/
1
+ **/.bundle/
2
2
  /.yardoc
3
3
  /_yardoc/
4
4
  /coverage/
@@ -7,7 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /Gemfile.lock
10
-
10
+ **/*.gemfile.lock
11
11
 
12
12
  # rspec failure tracking
13
13
  .rspec_status
data/.rubocop.yml CHANGED
@@ -1,3 +1,9 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "gemfiles/*"
4
+ SuggestExtensions: false
5
+ TargetRubyVersion: 2.7
6
+
1
7
  Documentation:
2
8
  Exclude:
3
9
  - "**/railtie.rb"
@@ -5,9 +11,9 @@ Documentation:
5
11
 
6
12
  Style/StringLiterals:
7
13
  EnforcedStyle: double_quotes
8
- Metrics/LineLength:
14
+ Layout/LineLength:
9
15
  Max: 120
10
- Layout/AlignHash:
16
+ Layout/HashAlignment:
11
17
  EnforcedHashRocketStyle: table
12
18
  EnforcedColonStyle: table
13
19
  Layout/SpaceInsideHashLiteralBraces:
@@ -16,9 +22,9 @@ Style/RaiseArgs:
16
22
  EnforcedStyle: compact
17
23
  Style/EmptyMethod:
18
24
  EnforcedStyle: expanded
19
- Layout/IndentArray:
25
+ Layout/FirstArrayElementIndentation:
20
26
  IndentationWidth: 4
21
- Layout/IndentHash:
27
+ Layout/FirstHashElementIndentation:
22
28
  IndentationWidth: 4
23
29
  Style/ConditionalAssignment:
24
30
  EnforcedStyle: assign_inside_condition
@@ -31,7 +37,9 @@ Style/FormatStringToken:
31
37
  EnforcedStyle: template
32
38
  Style/AsciiComments:
33
39
  Enabled: false
34
-
40
+ Naming/FileName:
41
+ Exclude:
42
+ - "lib/cron-kubernetes.rb"
35
43
  Metrics/BlockLength:
36
44
  Exclude:
37
45
  - "*.gemspec"
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.0
1
+ 3.2.2
data/Appraisals ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise "kubeclient-3" do
4
+ gem "kubeclient", "3.1.2"
5
+ end
6
+
7
+ appraise "kubeclient-4" do
8
+ gem "kubeclient", "4.0.0"
9
+ end
data/CHANGELOG.md CHANGED
@@ -1,2 +1,20 @@
1
+ # v2.0.0
2
+ **Breaking Change:**
3
+ - Requires ruby 2.7 or later
4
+
5
+ **Changes:**
6
+ - Fix issue where running `cron_kubernetes` would fail with "ResourceNotFoundError"
7
+
8
+ # v1.1.0
9
+ - Fix issue where all cron jobs in a cluster would be removed, not just ones matching `identifier`
10
+
11
+ # v1.0.0
12
+ **Breaking Change:**
13
+ - Requires `kubeclient` 3.1.2 or 4.x
14
+
15
+ **Changes:**
16
+ - Add `kubeclient` configuration option for connecting to any Kubernetes server
17
+ - Add Appraisal for testing with kubeclient 3.1.2 and 4.x
18
+
1
19
  # v0.1.0
2
20
  - Initial Release
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
  ## Configuration
23
23
 
24
24
  You can configure global settings for your cron jobs. Add a file to your source like the example
25
- below. If you are using Rails, you can add this to something like `config/initializers/cron_kuberentes.rb`.
25
+ below. If you are using Rails, you can add this to something like `config/initializers/cron_kubernetes.rb`.
26
26
 
27
27
  You _must_ configure the `identifier` and `manifest` settings. The other settings are optional
28
28
  and default values are shown below.
@@ -95,6 +95,29 @@ replace both `ENTRYPOINT` and `CMD` in the Docker image. See
95
95
  [Define a Command and Arguments for a Container](https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/)
96
96
  for a discussion of how `command` works in Kubernetes.
97
97
 
98
+ ### kubeclient
99
+ The gem will automatically connect to the Kubernetes server in the following cases:
100
+ - You are running this in [a standard Kubernetes cluster](https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/#accessing-the-api-from-a-pod)
101
+ - You are running on a system with `kubeclient` installed and
102
+ - the default cluster context has credentials
103
+ - the default cluster is GKE and your system has
104
+ [Google application default credentials](https://developers.google.com/identity/protocols/application-default-credentials)
105
+ installed
106
+
107
+ There are many other ways to connect and you can do so by providing your own
108
+ [configured `kubeclient`](https://github.com/abonas/kubeclient#usage):
109
+
110
+ ```ruby
111
+ # config/initializers/resque-kubernetes.rb
112
+
113
+ CronKubernetes.configuration do |config|
114
+ config.kubeclient = Kubeclient::Client.new("http://localhost:8080/apis/batch", "v1")
115
+ end
116
+ ```
117
+
118
+ Because this uses the `CronJob` resource, make sure to connect to the `/apis/batch` API endpoint and
119
+ API version `v1` in your client.
120
+
98
121
  ## Usage
99
122
 
100
123
  ### Create a Schedule
@@ -111,10 +134,10 @@ CronKubernetes.schedule do
111
134
  end
112
135
  ```
113
136
 
114
- For all jobs the command with change directories to either `Rails.root` if Rails is installed
137
+ For all jobs the command will change directories to either `Rails.root` if Rails is installed
115
138
  or the current working directory. These are evaluated when the scheduled tasks are loaded.
116
139
 
117
- For all jobs you may provide a `name` to name, which will be used with the `identifier` to name the
140
+ For all jobs you may provide a `name` that will be used with the `identifier` to name the
118
141
  CronJob. If you do not provide a name `CronKubernetes` will try to figure one out from the job and
119
142
  pod templates plus a hash of the schedule and command.
120
143
 
@@ -122,15 +145,14 @@ pod templates plus a hash of the schedule and command.
122
145
 
123
146
  A `command` runs any arbitrary shell command on a schedule. The first argument is the command to run.
124
147
 
125
-
126
148
  #### Rake Tasks
127
149
 
128
150
  A `rake` call runs a `rake` task on the schedule. Rake and Bundler must be installed and on the path
129
- in the container The command it executes is `bundle exec rake ...`.
151
+ in the container. The command it executes is `bundle exec rake ...`.
130
152
 
131
153
  #### Runners
132
154
 
133
- A `runner` runs arbitrary ruby code under rails. Rails must be installed at `bin/rails` from the
155
+ A `runner` runs arbitrary ruby code under Rails. Rails must be installed at `bin/rails` from the
134
156
  working folder. The command it executes is `bin/rails runner '...'`.
135
157
 
136
158
  ### Update Your Cluster
@@ -139,7 +161,7 @@ Once you have configuration and cluster, then you can run the `cron_kubernetes`
139
161
  to update your cluster.
140
162
 
141
163
  ```bash
142
- cron_kubernetes --configuration config/initializers/cron_kubernetes.rb --schedule config/schedule.rb
164
+ bundle exec cron_kubernetes --configuration config/initializers/cron_kubernetes.rb --schedule config/schedule.rb
143
165
  ```
144
166
 
145
167
  The command will read the provided configuration and current schedule, compare to any
@@ -151,7 +173,7 @@ loaded both a configuration and a schedule. For example, if they are in the same
151
173
  just pass a single value:
152
174
 
153
175
  ```bash
154
- cron_kubernetes --schedule schedule.rb
176
+ bundle exec cron_kubernetes --schedule schedule.rb
155
177
  ```
156
178
 
157
179
  If you are running in a Rails application where the initializers are auto-loaded, and your
@@ -170,21 +192,40 @@ bin/rails runner cron_kubernetes
170
192
  at: "[H]H:mm[am|pm]"
171
193
  ```
172
194
 
173
- ## Development
195
+ ## Contributing
174
196
 
175
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
197
+ Bug reports and pull requests are welcome on GitHub at
198
+ https://github.com/keylime-toolbox/cron-kubernetes-ruby.
176
199
 
177
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
200
+ 1. Fork it (`https://github.com/[my-github-username]/cron-kubernetes-ruby/fork`)
201
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
202
+ 3. Test your changes with `rake`, add new tests if needed
203
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
204
+ 6. Push to the branch (`git push origin my-new-feature`)
205
+ 7. Open a new Pull Request
178
206
 
179
- To install this gem onto your local machine, run `bundle exec rake install`.
207
+ ### Development
180
208
 
181
- To release a new version, update the version number in `lib/cron_kubernets/version.rb` and the `CHANGELOG.md`,
182
- and then run `bundle exec rake release`, which will create a git tag for the version,
183
- push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
209
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
210
+ run `rake` to run the test suite.
184
211
 
185
- ## Contributing
212
+ You can run `bin/console` for an interactive prompt that will allow you to
213
+ experiment.
214
+
215
+ Write test for any code that you add. Test all changes by running `bin/rake`.
216
+ This does the following, which you can also run separately while working.
217
+ 1. Run unit tests: `appraisal rake spec`
218
+ 2. Make sure that your code matches the styles: `rubocop`
219
+ 3. Verify if any dependent gems have open CVEs (you must update these):
220
+ `rake bundle:audit`
221
+
222
+ ## Release
186
223
 
187
- Bug reports and pull requests are welcome on GitHub at https://github.com/keylimetoolbox/cron-kubernetes.
224
+ To release a new version, update the version number in
225
+ `lib/cron_kubernetes/version.rb` and the `CHANGELOG.md`, then run
226
+ `bundle exec rake release`, which will create a git tag for the version,
227
+ push git commits and tags, and push the `.gem` file to
228
+ [rubygems.org](https://rubygems.org).
188
229
 
189
230
  ## Acknowledgments
190
231
 
data/Rakefile CHANGED
@@ -1,16 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "appraisal/task"
4
+ require "bundler/audit/task"
3
5
  require "bundler/gem_tasks"
4
6
  require "rspec/core/rake_task"
5
7
  require "rubocop/rake_task"
6
- require "bundler/audit/task"
7
8
 
8
9
  RSpec::Core::RakeTask.new(:spec)
9
10
  RuboCop::RakeTask.new
10
11
  Bundler::Audit::Task.new
12
+ Appraisal::Task.new
11
13
 
12
14
  # Remove default and replace with a series of test tasks
13
15
  task default: []
14
16
  Rake::Task[:default].clear
15
17
 
16
- task default: %w[spec rubocop bundle:audit]
18
+ if ENV["APPRAISAL_INITIALIZED"]
19
+ task default: %i[spec]
20
+ else
21
+ task default: %i[rubocop bundle:audit appraisal]
22
+ end
data/bin/setup CHANGED
@@ -6,3 +6,4 @@ set -vx
6
6
  bundle install
7
7
 
8
8
  # Do any other automated setup that you need to do here
9
+ appraisal install
@@ -1,4 +1,3 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  lib = File.expand_path("lib", __dir__)
@@ -15,8 +14,9 @@ Gem::Specification.new do |spec|
15
14
  spec.description = "Configure and deploy Kubernetes CronJobs from ruby with a single schedule."
16
15
  spec.homepage = "https://github.com/keylimetoolbox/cron-kubernetes"
17
16
  spec.license = "MIT"
17
+ spec.required_ruby_version = ">= 2.7"
18
18
 
19
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
20
  f.match(%r{^(test|spec|features)/})
21
21
  end
22
22
  spec.require_paths = ["lib"]
@@ -24,14 +24,15 @@ Gem::Specification.new do |spec|
24
24
  spec.bindir = "bin"
25
25
  spec.executables << "cron_kubernetes"
26
26
 
27
- spec.add_dependency "kubeclient", "~> 3.0"
27
+ spec.add_dependency "kubeclient", ">= 3.1.2", "< 5.0"
28
28
 
29
- spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "appraisal"
30
+ spec.add_development_dependency "bundler", "~> 2.4"
30
31
  spec.add_development_dependency "bundler-audit", "~> 0"
31
32
  spec.add_development_dependency "mocha", "~> 1.3"
32
- spec.add_development_dependency "rake", "~> 12.3"
33
- spec.add_development_dependency "rspec", "~> 3.7"
34
- spec.add_development_dependency "rubocop", "~> 0.52", ">= 0.52.1"
33
+ spec.add_development_dependency "rake", "~> 13.1"
34
+ spec.add_development_dependency "rspec", "~> 3.12"
35
+ spec.add_development_dependency "rubocop", "~> 1.57"
35
36
 
36
37
  # For connecting to a GKE cluster in development/test
37
38
  spec.add_development_dependency "googleauth"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "kubeclient", "3.1.2"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "kubeclient", "4.0.0"
6
+
7
+ gemspec path: "../"
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "cron_kubernetes"
@@ -11,6 +11,7 @@ module CronKubernetes
11
11
  #
12
12
  # name: The name of the setting.
13
13
  # default: A default value for the setting. (Optional)
14
+ # rubocop: disable Style/ClassVars
14
15
  def define_setting(name, default = nil)
15
16
  class_variable_set("@@#{name}", default)
16
17
 
@@ -22,6 +23,7 @@ module CronKubernetes
22
23
  class_variable_get("@@#{name}")
23
24
  end
24
25
  end
26
+ # rubocop: enable Style/ClassVars
25
27
 
26
28
  private
27
29
 
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronKubernetes
4
+ module Context
5
+ # Kubeclient Context from `kubectl` config file.
6
+ class Kubectl
7
+ def applicable?
8
+ File.exist?(kubeconfig)
9
+ end
10
+
11
+ def context
12
+ config = Kubeclient::Config.read(kubeconfig)
13
+
14
+ CronKubernetes::KubeclientContext::Context.new(
15
+ config.context.api_endpoint,
16
+ config.context.api_version,
17
+ config.context.namespace,
18
+ auth_options: auth_options(config),
19
+ ssl_options: config.context.ssl_options
20
+ )
21
+ end
22
+
23
+ private
24
+
25
+ def kubeconfig
26
+ File.join(ENV["HOME"], ".kube", "config")
27
+ end
28
+
29
+ def auth_options(config)
30
+ options = config.context.auth_options
31
+ return options unless options.empty?
32
+
33
+ google_application_default_credentials
34
+ end
35
+
36
+ def google_application_default_credentials
37
+ return unless defined?(Google) && defined?(Google::Auth)
38
+
39
+ {bearer_token: Kubeclient::GoogleApplicationDefaultCredentials.token}
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronKubernetes
4
+ module Context
5
+ # Kubeclient Context from well-known locations within a Kubernetes cluster.
6
+ class WellKnown
7
+ TOKEN_FILE = "/var/run/secrets/kubernetes.io/serviceaccount/token"
8
+ CA_FILE = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
9
+ NAMESPACE_FILE = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
10
+
11
+ def applicable?
12
+ File.exist?(TOKEN_FILE)
13
+ end
14
+
15
+ def context
16
+ CronKubernetes::KubeclientContext::Context.new(
17
+ "https://kubernetes.default.svc",
18
+ "v1",
19
+ namespace,
20
+ auth_options: {bearer_token_file: TOKEN_FILE},
21
+ ssl_options: ssl_options
22
+ )
23
+ end
24
+
25
+ private
26
+
27
+ def namespace
28
+ return nil unless File.exist?(NAMESPACE_FILE)
29
+
30
+ File.read(NAMESPACE_FILE)
31
+ end
32
+
33
+ def ssl_options
34
+ return {} unless File.exist?(CA_FILE)
35
+
36
+ {ca_file: CA_FILE}
37
+ end
38
+ end
39
+ end
40
+ end
@@ -18,7 +18,7 @@ module CronKubernetes
18
18
  # rubocop:disable Metrics/MethodLength
19
19
  def cron_job_manifest
20
20
  {
21
- "apiVersion" => "batch/v1beta1",
21
+ "apiVersion" => "batch/v1",
22
22
  "kind" => "CronJob",
23
23
  "metadata" => {
24
24
  "name" => "#{identifier}-#{cron_job_name}",
@@ -39,7 +39,8 @@ module CronKubernetes
39
39
  private
40
40
 
41
41
  def namespace
42
- return job_manifest["metadata"]["namespace"] if job_manifest["metadata"]
42
+ return job_manifest["metadata"]["namespace"] if job_manifest["metadata"] && job_manifest["metadata"]["namespace"]
43
+
43
44
  "default"
44
45
  end
45
46
 
@@ -57,17 +58,17 @@ module CronKubernetes
57
58
  def cron_job_name
58
59
  return name if name
59
60
  return job_hash(job_manifest["metadata"]["name"]) if job_manifest["metadata"]
61
+
60
62
  pod_template_name
61
63
  end
62
64
 
63
- # rubocop:disable Metrics/AbcSize
64
65
  def pod_template_name
65
66
  return nil unless job_manifest["spec"] &&
66
- job_manifest["spec"]["template"] &&
67
- job_manifest["spec"]["template"]["metadata"]
67
+ job_manifest["spec"]["template"] &&
68
+ job_manifest["spec"]["template"]["metadata"]
69
+
68
70
  job_hash(job_manifest["spec"]["template"]["metadata"]["name"])
69
71
  end
70
- # rubocop:enable Metrics/AbcSize
71
72
 
72
73
  def job_hash(name)
73
74
  "#{name}-#{Digest::SHA1.hexdigest(schedule + command.join)[0..7]}"
@@ -3,13 +3,6 @@
3
3
  module CronKubernetes
4
4
  # The "table" of Kubernetes CronJobs that we manage in the cluster.
5
5
  class CronTab
6
- attr_reader :client
7
- private :client
8
-
9
- def initialize
10
- @client = CronKubernetes::KubernetesClient.new.batch_beta1_client
11
- end
12
-
13
6
  # "Apply" the new configuration
14
7
  # - remove from cluster any cron_jobs that are no longer in the schedule
15
8
  # - add new jobs
@@ -24,9 +17,13 @@ module CronKubernetes
24
17
 
25
18
  private
26
19
 
20
+ def client
21
+ @client ||= CronKubernetes::KubernetesClient.new.batch_client
22
+ end
23
+
27
24
  # Define a label for our jobs based on an identifier
28
25
  def label_selector
29
- {"cron-kubernetes-identifier" => CronKubernetes.identifier}
26
+ {label_selector: "cron-kubernetes-identifier=#{CronKubernetes.identifier}"}
30
27
  end
31
28
 
32
29
  # Find all k8s CronJobs by our label for the identifier
@@ -5,64 +5,18 @@ require "kubeclient"
5
5
  module CronKubernetes
6
6
  # Create a context for `Kubeclient` depending on the environment.
7
7
  class KubeclientContext
8
+ Context = Struct.new(:endpoint, :version, :namespace, :options)
9
+
8
10
  class << self
9
11
  def context
10
- # TODO: Add ability to load this from config
11
-
12
- if File.exist?("/var/run/secrets/kubernetes.io/serviceaccount/token")
13
- # When running in k8s cluster, use the service account secret token and ca bundle
14
- well_known_context
15
- elsif File.exist?(kubeconfig)
16
- # When running in development, use the config file for `kubectl` and default application credentials
17
- kubectl_context
12
+ [
13
+ CronKubernetes::Context::WellKnown,
14
+ CronKubernetes::Context::Kubectl
15
+ ].each do |context_type|
16
+ context = context_type.new
17
+ return context.context if context.applicable?
18
18
  end
19
19
  end
20
-
21
- private
22
-
23
- def well_known_context
24
- Kubeclient::Config::Context.new(
25
- "https://kubernetes",
26
- "v1",
27
- {ca_file: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"},
28
- bearer_token_file: "/var/run/secrets/kubernetes.io/serviceaccount/token"
29
- )
30
- end
31
-
32
- def kubectl_context
33
- config = Kubeclient::Config.read(kubeconfig)
34
- auth_options = config.context.auth_options
35
-
36
- auth_options = google_default_application_credentials(config) if auth_options.empty?
37
-
38
- Kubeclient::Config::Context.new(
39
- config.context.api_endpoint,
40
- config.context.api_version,
41
- config.context.ssl_options,
42
- auth_options
43
- )
44
- end
45
-
46
- def kubeconfig
47
- File.join(ENV["HOME"], ".kube", "config")
48
- end
49
-
50
- # TODO: Move this logic to kubeclient. See abonas/kubeclient#213
51
- def google_default_application_credentials(config)
52
- return unless defined?(Google) && defined?(Google::Auth)
53
-
54
- _cluster, user = config.send(:fetch_context, config.instance_variable_get(:@kcfg)["current-context"])
55
- return {} unless user["auth-provider"] && user["auth-provider"]["name"] == "gcp"
56
-
57
- {bearer_token: new_google_token}
58
- end
59
-
60
- def new_google_token
61
- scopes = ["https://www.googleapis.com/auth/cloud-platform"]
62
- authorization = Google::Auth.get_application_default(scopes)
63
- authorization.apply({})
64
- authorization.access_token
65
- end
66
20
  end
67
21
  end
68
22
  end
@@ -3,22 +3,27 @@
3
3
  module CronKubernetes
4
4
  # Encapsulate access to Kubernetes API for different API versions.
5
5
  class KubernetesClient
6
- def batch_beta1_client
7
- @batch_beta1_client ||= client("/apis/batch", "v1beta1")
6
+ def batch_client
7
+ @batch_client ||= client("/apis/batch", "v1")
8
+ end
9
+
10
+ def namespace
11
+ context&.namespace
8
12
  end
9
13
 
10
14
  private
11
15
 
12
16
  def client(scope, version = nil)
13
- context = KubeclientContext.context
17
+ return CronKubernetes.kubeclient if CronKubernetes.kubeclient
14
18
  return unless context
15
19
 
16
- Kubeclient::Client.new(
17
- context.api_endpoint + scope,
18
- version || context.api_version,
19
- ssl_options: context.ssl_options,
20
- auth_options: context.auth_options
21
- )
20
+ Kubeclient::Client.new(context.endpoint + scope, version || context.version, context.options)
21
+ end
22
+
23
+ def context
24
+ return nil if CronKubernetes.kubeclient
25
+
26
+ @context ||= KubeclientContext.context
22
27
  end
23
28
  end
24
29
  end
@@ -44,11 +44,11 @@ module CronKubernetes
44
44
 
45
45
  def new_cron_job(schedule, command, name)
46
46
  CronJob.new(
47
- schedule: schedule,
48
- command: make_command(command),
49
- job_manifest: CronKubernetes.manifest,
50
- name: name,
51
- identifier: @identifier
47
+ schedule: schedule,
48
+ command: make_command(command),
49
+ job_manifest: CronKubernetes.manifest,
50
+ name: name,
51
+ identifier: @identifier
52
52
  )
53
53
  end
54
54
 
@@ -58,6 +58,7 @@ module CronKubernetes
58
58
 
59
59
  def root
60
60
  return Rails.root if defined? Rails
61
+
61
62
  Dir.pwd
62
63
  end
63
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CronKubernetes
4
- VERSION = "0.1.0"
4
+ VERSION = "2.0.0"
5
5
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "cron_kubernetes/configurable"
4
+ require "cron_kubernetes/context/kubectl"
5
+ require "cron_kubernetes/context/well_known"
4
6
  require "cron_kubernetes/cron_job"
5
7
  require "cron_kubernetes/cron_tab"
6
8
  require "cron_kubernetes/kubeclient_context"
@@ -26,6 +28,9 @@ module CronKubernetes
26
28
  # Provide an identifier for this schedule (e.g. your application name)
27
29
  define_setting :identifier
28
30
 
31
+ # A `kubeclient` for connection context, default attempts to read from cluster or `~/.kube/config`
32
+ define_setting :kubeclient, nil
33
+
29
34
  class << self
30
35
  def schedule(&block)
31
36
  CronKubernetes::Scheduler.instance.instance_eval(&block)
metadata CHANGED
@@ -1,43 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cron-kubernetes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Wadsack
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-24 00:00:00.000000000 Z
11
+ date: 2023-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kubeclient
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.2
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '3.0'
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: appraisal
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
25
45
  - !ruby/object:Gem::Version
26
- version: '3.0'
46
+ version: '0'
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: bundler
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
51
  - - "~>"
32
52
  - !ruby/object:Gem::Version
33
- version: '1.16'
53
+ version: '2.4'
34
54
  type: :development
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
37
57
  requirements:
38
58
  - - "~>"
39
59
  - !ruby/object:Gem::Version
40
- version: '1.16'
60
+ version: '2.4'
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: bundler-audit
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -72,48 +92,42 @@ dependencies:
72
92
  requirements:
73
93
  - - "~>"
74
94
  - !ruby/object:Gem::Version
75
- version: '12.3'
95
+ version: '13.1'
76
96
  type: :development
77
97
  prerelease: false
78
98
  version_requirements: !ruby/object:Gem::Requirement
79
99
  requirements:
80
100
  - - "~>"
81
101
  - !ruby/object:Gem::Version
82
- version: '12.3'
102
+ version: '13.1'
83
103
  - !ruby/object:Gem::Dependency
84
104
  name: rspec
85
105
  requirement: !ruby/object:Gem::Requirement
86
106
  requirements:
87
107
  - - "~>"
88
108
  - !ruby/object:Gem::Version
89
- version: '3.7'
109
+ version: '3.12'
90
110
  type: :development
91
111
  prerelease: false
92
112
  version_requirements: !ruby/object:Gem::Requirement
93
113
  requirements:
94
114
  - - "~>"
95
115
  - !ruby/object:Gem::Version
96
- version: '3.7'
116
+ version: '3.12'
97
117
  - !ruby/object:Gem::Dependency
98
118
  name: rubocop
99
119
  requirement: !ruby/object:Gem::Requirement
100
120
  requirements:
101
121
  - - "~>"
102
122
  - !ruby/object:Gem::Version
103
- version: '0.52'
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: 0.52.1
123
+ version: '1.57'
107
124
  type: :development
108
125
  prerelease: false
109
126
  version_requirements: !ruby/object:Gem::Requirement
110
127
  requirements:
111
128
  - - "~>"
112
129
  - !ruby/object:Gem::Version
113
- version: '0.52'
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: 0.52.1
130
+ version: '1.57'
117
131
  - !ruby/object:Gem::Dependency
118
132
  name: googleauth
119
133
  requirement: !ruby/object:Gem::Requirement
@@ -141,6 +155,7 @@ files:
141
155
  - ".rubocop.yml"
142
156
  - ".ruby-gemset"
143
157
  - ".ruby-version"
158
+ - Appraisals
144
159
  - CHANGELOG.md
145
160
  - Gemfile
146
161
  - LICENSE.txt
@@ -150,9 +165,13 @@ files:
150
165
  - bin/cron_kubernetes
151
166
  - bin/setup
152
167
  - cron-kubernetes.gemspec
168
+ - gemfiles/kubeclient_3.gemfile
169
+ - gemfiles/kubeclient_4.gemfile
153
170
  - lib/cron-kubernetes.rb
154
171
  - lib/cron_kubernetes.rb
155
172
  - lib/cron_kubernetes/configurable.rb
173
+ - lib/cron_kubernetes/context/kubectl.rb
174
+ - lib/cron_kubernetes/context/well_known.rb
156
175
  - lib/cron_kubernetes/cron_job.rb
157
176
  - lib/cron_kubernetes/cron_tab.rb
158
177
  - lib/cron_kubernetes/kubeclient_context.rb
@@ -163,7 +182,7 @@ homepage: https://github.com/keylimetoolbox/cron-kubernetes
163
182
  licenses:
164
183
  - MIT
165
184
  metadata: {}
166
- post_install_message:
185
+ post_install_message:
167
186
  rdoc_options: []
168
187
  require_paths:
169
188
  - lib
@@ -171,16 +190,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
190
  requirements:
172
191
  - - ">="
173
192
  - !ruby/object:Gem::Version
174
- version: '0'
193
+ version: '2.7'
175
194
  required_rubygems_version: !ruby/object:Gem::Requirement
176
195
  requirements:
177
196
  - - ">="
178
197
  - !ruby/object:Gem::Version
179
198
  version: '0'
180
199
  requirements: []
181
- rubyforge_project:
182
- rubygems_version: 2.7.4
183
- signing_key:
200
+ rubygems_version: 3.4.10
201
+ signing_key:
184
202
  specification_version: 4
185
203
  summary: Configure and deploy Kubernetes CronJobs from ruby.
186
204
  test_files: []