Class: Kuby::Sidekiq::Plugin
- Inherits:
-
Plugin
- Object
- Plugin
- Kuby::Sidekiq::Plugin
- Extended by:
- KubeDSL::ValueFields
- Defined in:
- lib/kuby/sidekiq/plugin.rb
Constant Summary collapse
- ROLE =
'worker'.freeze
Instance Method Summary collapse
- #after_configuration ⇒ Object
- #after_initialize ⇒ Object
- #before_deploy(manifest) ⇒ Object
- #deployment(&block) ⇒ Object
- #docker ⇒ Object
- #kubernetes ⇒ Object
- #namespace ⇒ Object
- #rails_app ⇒ Object
- #redis(&block) ⇒ Object
- #resources ⇒ Object
- #selector_app ⇒ Object
- #service_account(&block) ⇒ Object
- #storage_class_name ⇒ Object
- #url ⇒ Object
Instance Method Details
#after_configuration ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/kuby/sidekiq/plugin.rb', line 20 def after_configuration return unless rails_app deployment.spec.template.spec.container(:worker).merge!( rails_app.deployment.spec.template.spec.container(:web), fields: [:env_from] ) end |
#after_initialize ⇒ Object
16 17 18 |
# File 'lib/kuby/sidekiq/plugin.rb', line 16 def after_initialize @replicas = 1 end |
#before_deploy(manifest) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kuby/sidekiq/plugin.rb', line 28 def before_deploy(manifest) image_with_tag = "#{docker..image_url}:#{kubernetes.tag}" deployment do spec do template do spec do container(:worker) do image image_with_tag end end end end end end |
#deployment(&block) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/kuby/sidekiq/plugin.rb', line 71 def deployment(&block) context = self @deployment ||= KubeDSL.deployment do do name "#{context.selector_app}-sidekiq-#{ROLE}" namespace context.namespace..name labels do add :app, context.selector_app add :role, ROLE end end spec do replicas context.replicas selector do match_labels do add :app, context.selector_app add :role, ROLE end end strategy do type 'RollingUpdate' rolling_update do max_surge '25%' max_unavailable 0 end end template do do labels do add :app, context.selector_app add :role, ROLE end end spec do container(:worker) do name "#{context.selector_app}-sidekiq-#{ROLE}" image_pull_policy 'IfNotPresent' command %w(bundle exec sidekiq) end image_pull_secret do name context.kubernetes.registry_secret..name end restart_policy 'Always' service_account_name context.service_account..name end end end end @deployment.instance_eval(&block) if block @deployment end |
#docker ⇒ Object
174 175 176 |
# File 'lib/kuby/sidekiq/plugin.rb', line 174 def docker environment.docker end |
#kubernetes ⇒ Object
170 171 172 |
# File 'lib/kuby/sidekiq/plugin.rb', line 170 def kubernetes environment.kubernetes end |
#namespace ⇒ Object
182 183 184 |
# File 'lib/kuby/sidekiq/plugin.rb', line 182 def namespace kubernetes.namespace end |
#rails_app ⇒ Object
186 187 188 |
# File 'lib/kuby/sidekiq/plugin.rb', line 186 def rails_app kubernetes.plugin(:rails_app) end |
#redis(&block) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kuby/sidekiq/plugin.rb', line 134 def redis(&block) context = self @redis ||= Kuby::KubeDB.redis do api_version 'kubedb.com/v1alpha1' do name "#{context.selector_app}-sidekiq-redis" namespace context.kubernetes.namespace..name end spec do version '5.0.3-v1' storage_type 'Durable' storage do storage_class_name context.storage_class_name access_modes ['ReadWriteOnce'] resources do requests do add :storage, '1Gi' end end end end end @redis.instance_eval(&block) if block @redis end |
#resources ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/kuby/sidekiq/plugin.rb', line 44 def resources @resources ||= [ service_account, deployment, redis ] end |
#selector_app ⇒ Object
178 179 180 |
# File 'lib/kuby/sidekiq/plugin.rb', line 178 def selector_app kubernetes.selector_app end |
#service_account(&block) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/kuby/sidekiq/plugin.rb', line 52 def service_account(&block) context = self @service_account ||= KubeDSL.service_account do do name "#{context.selector_app}-sidekiq-sa" namespace context.namespace..name labels do add :app, context.selector_app add :role, ROLE end end end @service_account.instance_eval(&block) if block @service_account end |
#storage_class_name ⇒ Object
166 167 168 |
# File 'lib/kuby/sidekiq/plugin.rb', line 166 def storage_class_name kubernetes.provider.storage_class_name end |
#url ⇒ Object
12 13 14 |
# File 'lib/kuby/sidekiq/plugin.rb', line 12 def url @url ||= "redis://#{redis..name}:6379/0" end |