kuby-kind 0.2.0 → 0.2.2

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: 162dbe72c825ab0226317402bd69d196edf2e744c6a1705958544f2f3e8084f0
4
- data.tar.gz: 926121f8be70a445ce4b37cf20f427b32b02d86edd53516eb833a7fa4c43f894
3
+ metadata.gz: 32168f7821c5fdc2b593f00e355d4033b2eb9f957b3f306e26f743484d9ee74c
4
+ data.tar.gz: 4b75e6a5f900bd24760d90350e594557bfcb4830b6d963766c82e94a822ad640
5
5
  SHA512:
6
- metadata.gz: 5a0b6078ca87b52898869696bea5b4e42b74d8271bf123053dd4e965d055a759755708acbd8ff41f220ca7d693fe29b7040c52d37d271a50b76d61aaaab246e8
7
- data.tar.gz: 3b9996a749e5835bce22a7463244b4cee762532e6af290bc09c254939011a5cda6a2a7144f6c9a5710793786b642647470b827f9b63cb07a7847b983d5d8dade
6
+ metadata.gz: 162a12291e5c63fbcc66e63d344c566be36f0d1894b4bf7e84e07bb49166354296f338fc4f23a4d7c3227380e63c7a7f9bd72ac86ffdbfd624fb439d0a4147c2
7
+ data.tar.gz: e892e6f0732ef8bbd0205fdcd45d74a02031166c42bbd3e2e584583125eaa7a3075ca0fd77edab376d578bfb186f68813e59acd7e8deebfc8f48b5c6ea8dbc0f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.2.2
2
+ * Add missing 'require'.
3
+
4
+ ## 0.2.1
5
+ * Only create cluster and load images on deploy.
6
+ - Uses the `deploy` hook instead of `before_deploy`, which is called during `kuby resources` used to simulate a deploy so tag info is populated correctly.
7
+
1
8
  ## 0.2.0
2
9
  * Allow configuring Kubernetes version.
3
10
  * Fix storage class name
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development, :test do
6
+ gem 'sorbet-runtime'
6
7
  gem 'pry-byebug'
7
8
  gem 'rake'
8
9
  end
data/Rakefile CHANGED
@@ -2,6 +2,7 @@ require 'bundler'
2
2
  require 'rspec/core/rake_task'
3
3
  require 'rubygems/package_task'
4
4
 
5
+ require 'sorbet-runtime'
5
6
  require 'kuby/kind'
6
7
  require 'pry-byebug'
7
8
 
@@ -1,6 +1,7 @@
1
1
  require 'kuby'
2
2
  require 'kind-rb'
3
3
  require 'open3'
4
+ require 'tmpdir'
4
5
 
5
6
  module Kuby
6
7
  module Kind
@@ -29,9 +30,11 @@ module Kuby
29
30
  ensure_cluster!
30
31
  end
31
32
 
32
- def before_deploy(*)
33
+ def deploy
33
34
  ensure_cluster!
34
35
  load_images
36
+
37
+ super
35
38
  end
36
39
 
37
40
  def after_configuration
@@ -60,14 +63,44 @@ module Kuby
60
63
  end
61
64
 
62
65
  def load_images
66
+ require 'pry-byebug'
63
67
  Kuby.logger.info("Loading Docker images into Kind cluster...")
64
68
 
69
+ node_name = "#{cluster_name}-control-plane"
70
+ loaded_images = YAML.load(
71
+ docker_cli.exec_capture(
72
+ container: node_name,
73
+ command: '/usr/local/bin/crictl images --digests -o yaml'
74
+ )
75
+ )
76
+
77
+ loaded_digests = loaded_images['images'].map do |image|
78
+ algo, digest = image['id'].split(':')
79
+ { algo: algo, digest: digest }
80
+ end
81
+
65
82
  environment.kubernetes.docker_images.each do |image|
66
83
  image = image.current_version
67
84
 
68
- # Only load the main tag because it's so darn expensive to load large
69
- # images into Kind clusters. Kind doesn't seem to realize images with
70
- # the same SHA but different tags are the same, :eyeroll:
85
+ # Avoid loading images into the cluster if they're already there. Kind tries to detect this
86
+ # on its own and will even emit log messages to that effect, but appears to load them
87
+ # anyway. Since loading images can be quite time-consuming, we do our own check below.
88
+ images = docker_cli.images(image.image_url, digests: true)
89
+ image_info = images.find { |img| img[:tag] == image.main_tag }
90
+
91
+ if image_info
92
+ algo, _ = image_info[:digest].split(':')
93
+
94
+ loaded_digest = loaded_digests.find do |loaded_digest|
95
+ algo == loaded_digest[:algo] && loaded_digest[:digest].start_with?(image_info[:id])
96
+ end
97
+
98
+ if loaded_digest
99
+ Kuby.logger.info("Skipping #{image.image_url}@#{loaded_digest[:algo]}:#{loaded_digest[:digest]} because it's already loaded.")
100
+ next
101
+ end
102
+ end
103
+
71
104
  cmd = [
72
105
  KindRb.executable,
73
106
  'load', 'docker-image', "#{image.image_url}:#{image.main_tag}",
@@ -211,6 +244,10 @@ module Kuby
211
244
  Dir.tmpdir, 'kuby-kind'
212
245
  )
213
246
  end
247
+
248
+ def docker_cli
249
+ @docker_cli ||= Docker::CLI.new
250
+ end
214
251
  end
215
252
  end
216
253
  end
@@ -1,5 +1,5 @@
1
1
  module Kuby
2
2
  module Kind
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.2.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuby-kind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-23 00:00:00.000000000 Z
11
+ date: 2023-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kuby-core
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.2.22
82
+ rubygems_version: 3.4.5
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Kind provider for Kuby.