metatron 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a89ce9a5fa862d8312310581e5a57b0094bf49bc2934043f9b5578de66e519c
4
- data.tar.gz: ebf94d54cce8d9dc11f439731bec655ed5d943f1f77e47a79a788616cffc02f9
3
+ metadata.gz: e2595e703b422eadf0c748386541eae93f9b447d74e2bd70160a85dc14c7f59a
4
+ data.tar.gz: 599adf4652b4e2bbf35f86f95c083f6e6e03780d44fa563c83ca714c90aa3004
5
5
  SHA512:
6
- metadata.gz: 0ec004038d5ffa21bf0eed37f67079bbfd613dc844b7916713b1855ae5e09f2b10e7e54e1d3bdc4fa03ec3520628719d086d0fdb5eee25a79191817d47f50480
7
- data.tar.gz: 91db8671698f68bd9e1e42e2a9baa536daafa12e545d7bc1744b420580f7247929d8a025aed9f7d22800264dd21ec173745e3b0ebfd5c174c448b5fa92ab43d2
6
+ metadata.gz: fd16efd8685097c4fdb321de668cecb60ac24c0dab98e1e97ab40590007d524dfa9b0ba644174786d659a0fc6bc1225b48b62cb0ae2a1224e1503ee8a6aa40c7
7
+ data.tar.gz: d0255911256d4e233f300b5a82dbeba91feeba7819d920bdd2e2e3c505a02b1b7343fdfc8ec938912bc4f650491ddfdc51efc007f7e57e58527ecf0665b07adf
data/.rubocop.yml CHANGED
@@ -38,6 +38,9 @@ Metrics/ClassLength:
38
38
  Gemspec/RequireMFA:
39
39
  Enabled: false
40
40
 
41
+ Gemspec/DevelopmentDependencies:
42
+ Enabled: false
43
+
41
44
  Style/MixinUsage:
42
45
  Exclude:
43
46
  - "bin/console"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- metatron (0.1.8)
4
+ metatron (0.2.0)
5
5
  json (~> 2.6)
6
6
  puma (~> 6.3)
7
7
  sinatra (~> 2.2)
@@ -50,7 +50,7 @@ GEM
50
50
  regexp_parser (2.8.1)
51
51
  reverse_markdown (2.1.1)
52
52
  nokogiri
53
- rexml (3.2.5)
53
+ rexml (3.2.6)
54
54
  rspec (3.12.0)
55
55
  rspec-core (~> 3.12.0)
56
56
  rspec-expectations (~> 3.12.0)
data/README.md CHANGED
@@ -203,7 +203,7 @@ module BlogController
203
203
  # status = compare_children(request_body["children"], desired_children)
204
204
  status = {}
205
205
 
206
- { status:, children: desired_children.map(&:render) }
206
+ { status:, children: desired_children }
207
207
  end
208
208
 
209
209
  def construct_app_resources(parent, db_secret)
@@ -235,18 +235,23 @@ module BlogController
235
235
 
236
236
  def construct_db_stateful_set(secret)
237
237
  stateful_set = Metatron::Templates::StatefulSet.new("db")
238
- stateful_set.image = "mysql:8.0"
238
+ container = Metatron::Templates::Container.new("db")
239
+ container.image = "mysql:8.0"
240
+ container.envfrom << secret.name
241
+ stateful_set.containers << container
239
242
  stateful_set.additional_pod_labels = { "app.kubernetes.io/component": "db" }
240
- stateful_set.envfrom << secret.name
241
243
  stateful_set
242
244
  end
243
245
 
244
246
  def construct_app_deployment(meta, spec, auth_secret)
245
247
  deployment = Metatron::Templates::Deployment.new(meta["name"], replicas: spec["replicas"])
246
- deployment.image = spec["image"]
248
+ container = Metatron::Templates::Container.new("app")
249
+ container.image = spec["image"]
250
+ container.envfrom << auth_secret.name
251
+ container.ports << { name: "web", containerPort: 3000 }
252
+
253
+ deployment.containers << container
247
254
  deployment.additional_pod_labels = { "app.kubernetes.io/component": "app" }
248
- deployment.envfrom << auth_secret.name
249
- deployment.ports << { name: "web", containerPort: 3000 }
250
255
  deployment
251
256
  end
252
257
 
@@ -9,7 +9,9 @@ module Metatron
9
9
  end
10
10
 
11
11
  post "/" do
12
- halt(sync.to_json)
12
+ data = sync
13
+ data[:children] = data[:children]&.map { |c| c.respond_to?(:render) ? c.render : c }
14
+ halt(data.to_json)
13
15
  end
14
16
  end
15
17
  end
@@ -3,12 +3,20 @@
3
3
  module Metatron
4
4
  # Base class for templating Kubernetes resources
5
5
  class Template
6
- attr_accessor :api_version, :label_namespace, :name
7
- attr_reader :kind
6
+ attr_accessor :api_version, :name
7
+ attr_reader :kind, :label_namespace
8
+
9
+ class << self
10
+ attr_writer :label_namespace
11
+
12
+ def label_namespace
13
+ @label_namespace ||= "metatron.therubyist.org"
14
+ end
15
+ end
8
16
 
9
17
  def initialize(name)
10
18
  @name = name
11
- @label_namespace = "metatron.therubyist.org"
19
+ @label_namespace = self.class.label_namespace
12
20
  @api_version = "v1"
13
21
  @kind = self.class.name.split("::").last
14
22
  run_initializers
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metatron
4
+ module Templates
5
+ module Concerns
6
+ # Makes supporting namespaced resources easier
7
+ module Namespaced
8
+ def self.included(base)
9
+ # base.extend ClassMethods
10
+ base.class_eval do
11
+ attr_accessor :namespace
12
+
13
+ initializer :namespaced_initialize
14
+ end
15
+ end
16
+
17
+ def namespaced_initialize
18
+ @namespace = nil
19
+ end
20
+
21
+ def formatted_namespace
22
+ if namespace
23
+ { namespace: namespace.is_a?(Namespace) ? namespace.name : namespace }
24
+ else
25
+ {}
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -8,78 +8,42 @@ module Metatron
8
8
  def self.included(base)
9
9
  # base.extend ClassMethods
10
10
  base.class_eval do
11
- attr_accessor :image, :image_pull_policy, :additional_labels, :additional_pod_labels,
12
- :resource_limits, :resource_requests, :probes, :ports, :security_context,
13
- :volume_mounts, :volumes, :additional_containers, :env, :envfrom,
14
- :container_security_context, :affinity, :termination_grace_period_seconds,
11
+ attr_accessor :additional_labels, :additional_pod_labels,
12
+ :security_context, :volumes, :containers, :init_containers,
13
+ :affinity, :termination_grace_period_seconds,
15
14
  :tolerations, :pod_annotations
16
15
 
17
16
  initializer :pod_producer_initialize
18
17
 
19
- alias_method :imagePullPolicy, :image_pull_policy
20
- alias_method :volumeMounts, :volume_mounts
21
18
  alias_method :securityContext, :security_context
22
- alias_method :environment, :env
23
19
  alias_method :terminationGracePeriodSeconds, :termination_grace_period_seconds
24
20
  end
25
21
  end
26
22
 
27
23
  def pod_producer_initialize
28
- @image = "gcr.io/google_containers/pause"
29
- @image_pull_policy = "IfNotPresent"
30
- @resource_limits = { memory: "512Mi", cpu: "500m" }
31
- @resource_requests = { memory: "64Mi", cpu: "10m" }
32
24
  @affinity = {}
33
- @env = {}
34
- @envfrom = []
35
- @probes = {}
36
- @ports = []
37
- @volume_mounts = []
38
25
  @volumes = []
39
26
  @security_context = {}
40
- @container_security_context = {}
41
- @additional_containers = []
27
+ @containers = []
28
+ @init_containers = []
42
29
  @additional_labels = {}
43
30
  @additional_pod_labels = {}
44
31
  @pod_annotations = {}
45
- @termination_grace_period_seconds = 60
32
+ @termination_grace_period_seconds = nil
46
33
  @tolerations = []
47
34
  end
48
35
 
49
36
  def formatted_affinity = affinity && !affinity.empty? ? { affinity: } : {}
50
37
 
51
- def formatted_environment
52
- env && !env.empty? ? { env: env.map { |k, v| { name: k, value: v } } } : {}
53
- end
54
-
55
- def formatted_envfrom
56
- if envfrom && !envfrom.empty?
57
- { envFrom: envfrom.map { |secret| { secretRef: { name: secret } } } }
58
- else
59
- {}
60
- end
61
- end
62
-
63
38
  def formatted_pod_annotations
64
39
  pod_annotations && !pod_annotations.empty? ? { annotations: pod_annotations } : {}
65
40
  end
66
41
 
67
- def formatted_ports = ports&.any? ? { ports: } : {}
68
-
69
42
  def formatted_security_context
70
43
  security_context && !security_context.empty? ? { securityContext: } : {}
71
44
  end
72
45
 
73
- def formatted_container_security_context
74
- if container_security_context && !container_security_context.empty?
75
- { securityContext: container_security_context }
76
- else
77
- {}
78
- end
79
- end
80
-
81
46
  def formatted_tolerations = tolerations&.any? ? { tolerations: } : {}
82
- def formatted_volume_mounts = volume_mounts&.any? ? { volumeMounts: } : {}
83
47
  def formatted_volumes = volumes&.any? ? { volumes: } : {}
84
48
  end
85
49
  end
@@ -5,6 +5,7 @@ module Metatron
5
5
  # The ConfigMap Kubernetes resource
6
6
  class ConfigMap < Template
7
7
  include Concerns::Annotated
8
+ include Concerns::Namespaced
8
9
 
9
10
  attr_accessor :additional_labels, :type, :data
10
11
 
@@ -21,7 +22,7 @@ module Metatron
21
22
  metadata: {
22
23
  name:,
23
24
  labels: { "#{label_namespace}/name": name }.merge(additional_labels)
24
- }.merge(formatted_annotations),
25
+ }.merge(formatted_annotations).merge(formatted_namespace),
25
26
  data:
26
27
  }
27
28
  end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metatron
4
+ module Templates
5
+ # Template for containers used by k8s resources (not an actual resource)
6
+ class Container
7
+ attr_accessor :name, :image, :command, :args, :env, :envfrom, :resources, :volume_mounts,
8
+ :image_pull_policy, :life_cycle, :probes, :security_context, :ports,
9
+ :stdin, :tty
10
+
11
+ alias imagePullPolicy image_pull_policy
12
+ alias volumeMounts volume_mounts
13
+ alias securityContext security_context
14
+ alias environment env
15
+ alias envFrom envfrom
16
+
17
+ def initialize(name, image = "gcr.io/google_containers/pause")
18
+ @name = name
19
+ @image = image
20
+ @command = nil
21
+ @args = []
22
+ @env = []
23
+ @resources = {}
24
+ @volume_mounts = []
25
+ @image_pull_policy = "IfNotPresent"
26
+ @life_cycle = {}
27
+ @probes = {}
28
+ @stdin = true
29
+ @tty = true
30
+ end
31
+
32
+ def render
33
+ {
34
+ name:,
35
+ image:,
36
+ imagePullPolicy:,
37
+ stdin:,
38
+ tty:
39
+ }.merge(probes)
40
+ .merge(formatted_resources)
41
+ .merge(formatted_environment)
42
+ .merge(formatted_envfrom)
43
+ .merge(formatted_ports)
44
+ .merge(formatted_volume_mounts)
45
+ .merge(formatted_security_context)
46
+ .compact
47
+ end
48
+
49
+ def formatted_environment # rubocop:disable Metrics/PerceivedComplexity
50
+ return {} unless env && !env.empty?
51
+
52
+ if env.is_a?(Hash)
53
+ mapped_values = env.map do |key, value|
54
+ v = { name: key }
55
+ if value.is_a?(Hash)
56
+ v.merge!(value)
57
+ else
58
+ v[:value] = value
59
+ end
60
+ v
61
+ end
62
+
63
+ { env: mapped_values }
64
+ elsif env.is_a?(Array)
65
+ { env: }
66
+ else
67
+ raise "Environment must be a Hash or Array"
68
+ end
69
+ end
70
+
71
+ def formatted_envfrom
72
+ if envfrom && !envfrom.empty?
73
+ { envFrom: envfrom.map { |secret| { secretRef: { name: secret } } } }
74
+ else
75
+ {}
76
+ end
77
+ end
78
+
79
+ def formatted_resources = resources&.any? ? { resources: } : {}
80
+
81
+ def formatted_ports = ports&.any? ? { ports: } : {}
82
+
83
+ def formatted_security_context
84
+ security_context && !security_context.empty? ? { securityContext: } : {}
85
+ end
86
+
87
+ def formatted_volume_mounts = volume_mounts&.any? ? { volumeMounts: } : {}
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metatron
4
+ module Templates
5
+ # Template for basic CronJob k8s resource
6
+ class CronJob < Template
7
+ include Concerns::Annotated
8
+ include Concerns::PodProducer
9
+ include Concerns::Namespaced
10
+
11
+ attr_accessor :schedule, :suspend, :concurrency_policy, :starting_deadline_seconds,
12
+ :successful_jobs_history_limit, :failed_jobs_history_limit,
13
+ :automount_service_account_token, :backoff_limit, :active_deadline_seconds,
14
+ :dns_policy, :restart_policy,
15
+ :scheduler_name, :service_account, :service_account_name
16
+
17
+ alias automountServiceAccountToken automount_service_account_token
18
+ alias backoffLimit backoff_limit
19
+ alias activeDeadlineSeconds active_deadline_seconds
20
+ alias concurrencyPolicy concurrency_policy
21
+ alias dnsPolicy dns_policy
22
+ alias restartPolicy restart_policy
23
+ alias schedulerName scheduler_name
24
+ alias serviceAccount service_account
25
+ alias serviceAccountName service_account_name
26
+ alias startingDeadlineSeconds starting_deadline_seconds
27
+ alias successfulJobsHistoryLimit successful_jobs_history_limit
28
+ alias failedJobsHistoryLimit failed_jobs_history_limit
29
+
30
+ def initialize(name, schedule = "* * * * *")
31
+ super(name)
32
+ @schedule = schedule
33
+ @api_version = "batch/v1"
34
+ @restart_policy = "OnFailure"
35
+ end
36
+
37
+ # rubocop:disable Metrics/AbcSize
38
+ # rubocop:disable Metrics/MethodLength
39
+ def render
40
+ {
41
+ apiVersion:,
42
+ kind:,
43
+ metadata: {
44
+ labels: { "#{label_namespace}/name": name }.merge(additional_labels),
45
+ name:
46
+ }.merge(formatted_annotations).merge(formatted_namespace),
47
+ spec: {
48
+ schedule:,
49
+ suspend:,
50
+ concurrencyPolicy:,
51
+ startingDeadlineSeconds:,
52
+ successfulJobsHistoryLimit:,
53
+ failedJobsHistoryLimit:,
54
+ jobTemplate: {
55
+ spec: {
56
+ activeDeadlineSeconds:,
57
+ backoffLimit:,
58
+ template: {
59
+ spec: {
60
+ automountServiceAccountToken:,
61
+ terminationGracePeriodSeconds:,
62
+ dnsPolicy:,
63
+ restartPolicy:,
64
+ schedulerName:,
65
+ serviceAccount:,
66
+ serviceAccountName:,
67
+ containers: containers.map(&:render),
68
+ init_containers: init_containers.any? ? init_containers.map(&:render) : nil
69
+ }.merge(formatted_volumes)
70
+ .merge(formatted_security_context)
71
+ .compact
72
+ }.compact
73
+ }.compact
74
+ }.merge(formatted_tolerations)
75
+ .compact
76
+ }.compact
77
+ }
78
+ end
79
+ # rubocop:enable Metrics/AbcSize
80
+ # rubocop:enable Metrics/MethodLength
81
+ end
82
+ end
83
+ end
@@ -5,6 +5,7 @@ module Metatron
5
5
  # The DaemonSet Kubernetes resource
6
6
  class DaemonSet < Template
7
7
  include Concerns::Annotated
8
+ include Concerns::Namespaced
8
9
  include Concerns::PodProducer
9
10
 
10
11
  attr_accessor :replicas, :additional_labels
@@ -14,8 +15,8 @@ module Metatron
14
15
  @api_version = "apps/v1"
15
16
  end
16
17
 
17
- # rubocop:disable Metrics/MethodLength
18
18
  # rubocop:disable Metrics/AbcSize
19
+ # rubocop:disable Metrics/MethodLength
19
20
  def render
20
21
  {
21
22
  apiVersion:,
@@ -23,7 +24,7 @@ module Metatron
23
24
  metadata: {
24
25
  name:,
25
26
  labels: { "#{label_namespace}/name": name }.merge(additional_labels)
26
- }.merge(formatted_annotations),
27
+ }.merge(formatted_annotations).merge(formatted_namespace),
27
28
  spec: {
28
29
  selector: {
29
30
  matchLabels: { "#{label_namespace}/name": name }.merge(additional_pod_labels)
@@ -34,24 +35,12 @@ module Metatron
34
35
  }.merge(formatted_pod_annotations),
35
36
  spec: {
36
37
  terminationGracePeriodSeconds:,
37
- containers: [
38
- {
39
- name: "app",
40
- image:,
41
- imagePullPolicy:,
42
- stdin: true,
43
- tty: true,
44
- resources: { limits: resource_limits, requests: resource_requests }
45
- }.merge(probes)
46
- .merge(formatted_environment)
47
- .merge(formatted_envfrom)
48
- .merge(formatted_ports)
49
- .merge(formatted_volume_mounts)
50
- .merge(formatted_container_security_context)
51
- ] + additional_containers
38
+ containers: containers.map(&:render),
39
+ init_containers: init_containers.any? ? init_containers.map(&:render) : nil
52
40
  }.merge(formatted_volumes)
53
41
  .merge(formatted_security_context)
54
42
  .merge(formatted_tolerations)
43
+ .compact
55
44
  }
56
45
  }
57
46
  }
@@ -5,6 +5,7 @@ module Metatron
5
5
  # The Deployment Kubernetes resource
6
6
  class Deployment < Template
7
7
  include Concerns::Annotated
8
+ include Concerns::Namespaced
8
9
  include Concerns::PodProducer
9
10
 
10
11
  attr_accessor :replicas, :additional_labels
@@ -34,27 +35,15 @@ module Metatron
34
35
  template: {
35
36
  metadata: {
36
37
  labels: { "#{label_namespace}/name": name }.merge(additional_pod_labels)
37
- }.merge(formatted_pod_annotations),
38
+ }.merge(formatted_pod_annotations).merge(formatted_namespace),
38
39
  spec: {
39
40
  terminationGracePeriodSeconds:,
40
- containers: [
41
- {
42
- name: "app",
43
- image:,
44
- imagePullPolicy:,
45
- stdin: true,
46
- tty: true,
47
- resources: { limits: resource_limits, requests: resource_requests }
48
- }.merge(probes)
49
- .merge(formatted_environment)
50
- .merge(formatted_envfrom)
51
- .merge(formatted_ports)
52
- .merge(formatted_volume_mounts)
53
- .merge(formatted_container_security_context)
54
- ] + additional_containers
41
+ containers: containers.map(&:render),
42
+ init_containers: init_containers.any? ? init_containers.map(&:render) : nil
55
43
  }.merge(formatted_volumes)
56
44
  .merge(formatted_security_context)
57
45
  .merge(formatted_tolerations)
46
+ .compact
58
47
  }
59
48
  }
60
49
  }
@@ -4,6 +4,8 @@ module Metatron
4
4
  module Templates
5
5
  # Template for basic Ingress k8s resource
6
6
  class Ingress < Template
7
+ include Concerns::Namespaced
8
+
7
9
  attr_accessor :ingress_class, :additional_labels, :additional_annotations, :rules, :tls,
8
10
  :cert_manager_cluster_issuer, :cert_manager_issuer, :cert_manager_challenge_type
9
11
 
@@ -76,7 +78,7 @@ module Metatron
76
78
  metadata: {
77
79
  name:,
78
80
  labels: { "#{label_namespace}/name": name }.merge(additional_labels)
79
- }.merge(formatted_annotations),
81
+ }.merge(formatted_annotations).merge(formatted_namespace),
80
82
  spec: formatted_rules.merge(formatted_tls)
81
83
  }
82
84
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metatron
4
+ module Templates
5
+ # Template for basic Job k8s resource
6
+ class Job < Template
7
+ include Concerns::Annotated
8
+ include Concerns::PodProducer
9
+ include Concerns::Namespaced
10
+
11
+ attr_accessor :backoff_limit, :completions, :parallelism, :restart_policy,
12
+ :pod_failure_policy, :active_deadline_seconds, :ttl_seconds_after_finished,
13
+ :suspend
14
+
15
+ alias activeDeadlineSeconds active_deadline_seconds
16
+ alias backoffLimit backoff_limit
17
+ alias podFailurePolicy pod_failure_policy
18
+ alias restartPolicy restart_policy
19
+ alias ttlSecondsAfterFinished ttl_seconds_after_finished
20
+
21
+ def initialize(name)
22
+ super(name)
23
+ @api_version = "batch/v1"
24
+ end
25
+
26
+ # rubocop:disable Metrics/AbcSize
27
+ # rubocop:disable Metrics/MethodLength
28
+ def render
29
+ {
30
+ apiVersion:,
31
+ kind:,
32
+ metadata: {
33
+ labels: { "#{label_namespace}/name": name }.merge(additional_labels),
34
+ name:
35
+ }.merge(formatted_annotations).merge(formatted_namespace),
36
+ spec: {
37
+ suspend:,
38
+ backoffLimit:,
39
+ activeDeadlineSeconds:,
40
+ completions:,
41
+ parallelism:,
42
+ podFailurePolicy:,
43
+ ttlSecondsAfterFinished:,
44
+ template: {
45
+ spec: {
46
+ terminationGracePeriodSeconds:,
47
+ restartPolicy:,
48
+ containers: containers.map(&:render),
49
+ init_containers: init_containers.any? ? init_containers.map(&:render) : nil
50
+ }.merge(formatted_volumes)
51
+ .merge(formatted_security_context)
52
+ .merge(formatted_tolerations)
53
+ .compact
54
+ }.compact
55
+ }.compact
56
+ }
57
+ end
58
+ # rubocop:enable Metrics/AbcSize
59
+ # rubocop:enable Metrics/MethodLength
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metatron
4
+ module Templates
5
+ # Template for basic Namespace k8s resource
6
+ class Namespace < Template
7
+ include Concerns::Annotated
8
+
9
+ attr_accessor :additional_labels
10
+
11
+ def initialize(name)
12
+ super(name)
13
+ @additional_labels = {}
14
+ end
15
+
16
+ def render
17
+ {
18
+ apiVersion:,
19
+ kind:,
20
+ metadata: {
21
+ name:,
22
+ labels: { "#{label_namespace}/name": name }.merge(additional_labels)
23
+ }.merge(formatted_annotations)
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -5,6 +5,7 @@ module Metatron
5
5
  # The PersistentVolumeClaim Kubernetes resource
6
6
  class PersistentVolumeClaim < Template
7
7
  include Concerns::Annotated
8
+ include Concerns::Namespaced
8
9
 
9
10
  attr_accessor :additional_labels, :storage_class, :access_modes, :storage
10
11
 
@@ -28,7 +29,7 @@ module Metatron
28
29
  metadata: {
29
30
  name:,
30
31
  labels: { "#{label_namespace}/name": name }.merge(additional_labels)
31
- }.merge(formatted_annotations),
32
+ }.merge(formatted_annotations).merge(formatted_namespace),
32
33
  spec: {
33
34
  accessModes: access_modes,
34
35
  storageClassName: storage_class,
@@ -6,8 +6,8 @@ module Metatron
6
6
  class Pod < Template
7
7
  include Concerns::Annotated
8
8
  include Concerns::PodProducer
9
+ include Concerns::Namespaced
9
10
 
10
- # rubocop:disable Metrics/MethodLength
11
11
  # rubocop:disable Metrics/AbcSize
12
12
  def render
13
13
  {
@@ -16,31 +16,18 @@ module Metatron
16
16
  metadata: {
17
17
  labels: { "#{label_namespace}/name": name }.merge(additional_labels),
18
18
  name:
19
- }.merge(formatted_annotations),
19
+ }.merge(formatted_annotations).merge(formatted_namespace),
20
20
  spec: {
21
21
  terminationGracePeriodSeconds:,
22
- containers: [
23
- {
24
- name: "app",
25
- image:,
26
- imagePullPolicy:,
27
- stdin: true,
28
- tty: true,
29
- resources: { limits: resource_limits, requests: resource_requests }
30
- }.merge(probes)
31
- .merge(formatted_environment)
32
- .merge(formatted_envfrom)
33
- .merge(formatted_ports)
34
- .merge(formatted_volume_mounts)
35
- .merge(formatted_container_security_context)
36
- ] + additional_containers
22
+ containers: containers.map(&:render),
23
+ init_containers: init_containers.any? ? init_containers.map(&:render) : nil
37
24
  }.merge(formatted_volumes)
38
25
  .merge(formatted_security_context)
39
26
  .merge(formatted_tolerations)
27
+ .compact
40
28
  }
41
29
  end
42
30
  # rubocop:enable Metrics/AbcSize
43
- # rubocop:enable Metrics/MethodLength
44
31
  end
45
32
  end
46
33
  end
@@ -6,6 +6,7 @@ module Metatron
6
6
  class ReplicaSet < Template
7
7
  include Concerns::Annotated
8
8
  include Concerns::PodProducer
9
+ include Concerns::Namespaced
9
10
 
10
11
  attr_accessor :replicas, :additional_labels
11
12
 
@@ -24,7 +25,7 @@ module Metatron
24
25
  metadata: {
25
26
  name:,
26
27
  labels: { "#{label_namespace}/name": name }.merge(additional_labels)
27
- }.merge(formatted_annotations),
28
+ }.merge(formatted_annotations).merge(formatted_namespace),
28
29
  spec: {
29
30
  replicas:,
30
31
  selector: {
@@ -36,24 +37,12 @@ module Metatron
36
37
  }.merge(formatted_pod_annotations),
37
38
  spec: {
38
39
  terminationGracePeriodSeconds:,
39
- containers: [
40
- {
41
- name: "app",
42
- image:,
43
- imagePullPolicy:,
44
- stdin: true,
45
- tty: true,
46
- resources: { limits: resource_limits, requests: resource_requests }
47
- }.merge(probes)
48
- .merge(formatted_environment)
49
- .merge(formatted_envfrom)
50
- .merge(formatted_ports)
51
- .merge(formatted_volume_mounts)
52
- .merge(formatted_container_security_context)
53
- ] + additional_containers
40
+ containers: containers.map(&:render),
41
+ init_containers: init_containers.any? ? init_containers.map(&:render) : nil
54
42
  }.merge(formatted_volumes)
55
43
  .merge(formatted_security_context)
56
44
  .merge(formatted_tolerations)
45
+ .compact
57
46
  }
58
47
  }
59
48
  }
@@ -5,6 +5,7 @@ module Metatron
5
5
  # The Secret Kubernetes resource
6
6
  class Secret < Template
7
7
  include Concerns::Annotated
8
+ include Concerns::Namespaced
8
9
 
9
10
  attr_accessor :additional_labels, :type, :data
10
11
 
@@ -22,7 +23,7 @@ module Metatron
22
23
  metadata: {
23
24
  name:,
24
25
  labels: { "#{label_namespace}/name": name }.merge(additional_labels)
25
- }.merge(formatted_annotations),
26
+ }.merge(formatted_annotations).merge(formatted_namespace),
26
27
  type:,
27
28
  stringData: data
28
29
  }
@@ -5,6 +5,7 @@ module Metatron
5
5
  # The Service Kubernetes resource
6
6
  class Service < Template
7
7
  include Concerns::Annotated
8
+ include Concerns::Namespaced
8
9
 
9
10
  attr_accessor :type, :selector, :additional_labels, :ports,
10
11
  :additional_selector_labels, :publish_not_ready_addresses
@@ -41,7 +42,7 @@ module Metatron
41
42
  metadata: {
42
43
  name:,
43
44
  labels: { "#{label_namespace}/name": name }.merge(additional_labels)
44
- }.merge(formatted_annotations),
45
+ }.merge(formatted_annotations).merge(formatted_namespace),
45
46
  spec: {
46
47
  type:,
47
48
  selector: selector.merge(additional_selector_labels),
@@ -6,6 +6,7 @@ module Metatron
6
6
  class StatefulSet < Template
7
7
  include Concerns::Annotated
8
8
  include Concerns::PodProducer
9
+ include Concerns::Namespaced
9
10
 
10
11
  attr_accessor :replicas, :service_name, :pod_management_policy, :enable_service_links
11
12
 
@@ -31,7 +32,7 @@ module Metatron
31
32
  metadata: {
32
33
  name:,
33
34
  labels: { "#{label_namespace}/name": name }.merge(additional_labels)
34
- }.merge(formatted_annotations),
35
+ }.merge(formatted_annotations).merge(formatted_namespace),
35
36
  spec: {
36
37
  replicas:,
37
38
  serviceName:,
@@ -46,24 +47,12 @@ module Metatron
46
47
  }.merge(formatted_pod_annotations),
47
48
  spec: {
48
49
  terminationGracePeriodSeconds:,
49
- containers: [
50
- {
51
- name: "app",
52
- image:,
53
- imagePullPolicy:,
54
- stdin: true,
55
- tty: true,
56
- resources: { limits: resource_limits, requests: resource_requests }
57
- }.merge(probes)
58
- .merge(formatted_environment)
59
- .merge(formatted_envfrom)
60
- .merge(formatted_ports)
61
- .merge(formatted_volume_mounts)
62
- .merge(formatted_security_context)
63
- ] + additional_containers
50
+ containers: containers.map(&:render),
51
+ init_containers: init_containers.any? ? init_containers.map(&:render) : nil
64
52
  }.merge(formatted_volumes)
65
53
  .merge(formatted_affinity)
66
54
  .merge(formatted_tolerations)
55
+ .compact
67
56
  }
68
57
  }
69
58
  }
@@ -3,7 +3,7 @@
3
3
  module Metatron
4
4
  VERSION = [
5
5
  0, # major
6
- 1, # minor
7
- 8 # patch
6
+ 2, # minor
7
+ 0 # patch
8
8
  ].join(".")
9
9
  end
data/lib/metatron.rb CHANGED
@@ -26,11 +26,16 @@ end
26
26
  require "metatron/version"
27
27
  require "metatron/template"
28
28
  require "metatron/templates/concerns/annotated"
29
+ require "metatron/templates/concerns/namespaced"
29
30
  require "metatron/templates/concerns/pod_producer"
31
+ require "metatron/templates/container"
32
+ require "metatron/templates/job"
33
+ require "metatron/templates/cron_job"
30
34
  require "metatron/templates/pod"
31
35
  require "metatron/templates/persistent_volume_claim"
32
36
  require "metatron/templates/deployment"
33
37
  require "metatron/templates/ingress"
38
+ require "metatron/templates/namespace"
34
39
  require "metatron/templates/replica_set"
35
40
  require "metatron/templates/config_map"
36
41
  require "metatron/templates/secret"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-26 00:00:00.000000000 Z
11
+ date: 2023-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -257,11 +257,16 @@ files:
257
257
  - lib/metatron/sync_controller.rb
258
258
  - lib/metatron/template.rb
259
259
  - lib/metatron/templates/concerns/annotated.rb
260
+ - lib/metatron/templates/concerns/namespaced.rb
260
261
  - lib/metatron/templates/concerns/pod_producer.rb
261
262
  - lib/metatron/templates/config_map.rb
263
+ - lib/metatron/templates/container.rb
264
+ - lib/metatron/templates/cron_job.rb
262
265
  - lib/metatron/templates/daemon_set.rb
263
266
  - lib/metatron/templates/deployment.rb
264
267
  - lib/metatron/templates/ingress.rb
268
+ - lib/metatron/templates/job.rb
269
+ - lib/metatron/templates/namespace.rb
265
270
  - lib/metatron/templates/persistent_volume_claim.rb
266
271
  - lib/metatron/templates/pod.rb
267
272
  - lib/metatron/templates/replica_set.rb