Skip to content

Commit 82b59d0

Browse files
committed
feat(templates)!: pod match labels are distinct
Resolves #72 This is a breaking change! Previously, `additional_pod_labels` would be merged into selector matchLables automatically and without a way to override them. This change introduces a new `additional_pod_match_labels` method that allows you specify additional labels to match on. `additional_pod_labels` will is no longer merged into the selector matchLabels.
1 parent ba3d4c2 commit 82b59d0

File tree

9 files changed

+22
-16
lines changed

9 files changed

+22
-16
lines changed

lib/metatron/templates/concerns/pod_producer.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ def self.included(base) # rubocop:disable Metrics/MethodLength
99
# base.extend ClassMethods
1010
base.class_eval do
1111
attr_accessor :active_deadline_seconds, :additional_pod_labels,
12-
:affinity, :automount_service_account_token, :containers,
13-
:dns_policy, :enable_service_links, :hostname, :host_ipc, :host_network,
14-
:host_pid, :image_pull_secrets, :init_containers, :node_selector,
15-
:node_name, :persistent_volume_claims, :pod_annotations,
12+
:additional_pod_match_labels, :affinity, :automount_service_account_token,
13+
:containers, :dns_policy, :enable_service_links, :hostname, :host_ipc,
14+
:host_network, :host_pid, :image_pull_secrets, :init_containers,
15+
:node_selector, :node_name, :persistent_volume_claims, :pod_annotations,
1616
:priority_class_name, :restart_policy, :scheduler_name, :security_context,
1717
:service_account, :service_account_name, :share_process_namespace,
1818
:subdomain, :termination_grace_period_seconds, :tolerations, :volumes
@@ -41,6 +41,7 @@ def self.included(base) # rubocop:disable Metrics/MethodLength
4141

4242
def pod_producer_initialize
4343
@additional_pod_labels = {}
44+
@additional_pod_match_labels = {}
4445
@affinity = {}
4546
@containers = []
4647
@enable_service_links = nil

lib/metatron/templates/daemon_set.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def render
2525
}.merge(formatted_annotations).merge(formatted_namespace),
2626
spec: {
2727
selector: {
28-
matchLabels: base_labels.merge(additional_pod_labels)
28+
matchLabels: base_labels.merge(additional_pod_match_labels)
2929
}
3030
}.merge(pod_template)
3131
}

lib/metatron/templates/deployment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def render
2828
replicas:,
2929
strategy:,
3030
selector: {
31-
matchLabels: base_labels.merge(additional_pod_labels)
31+
matchLabels: base_labels.merge(additional_pod_match_labels)
3232
}
3333
}.merge(pod_template).compact
3434
}

lib/metatron/templates/replica_set.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def render
2727
spec: {
2828
replicas:,
2929
selector: {
30-
matchLabels: base_labels.merge(additional_pod_labels)
30+
matchLabels: base_labels.merge(additional_pod_match_labels)
3131
}
3232
}.merge(pod_template)
3333
}

lib/metatron/templates/stateful_set.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def render
3838
serviceName:,
3939
updateStrategy:,
4040
selector: {
41-
matchLabels: base_labels.merge(additional_pod_labels)
41+
matchLabels: base_labels.merge(additional_pod_match_labels)
4242
}
4343
}.merge(pod_template).merge(volume_claim_templates).compact
4444
}

spec/metatron/templates/daemon_set_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
ds.annotations = { "a.test/foo": "bar" }
8484
ds.additional_labels = { "app.kubernetes.io/part-of": "test-app" }
8585
ds.namespace = "test-namespace"
86-
ds.additional_pod_labels = { thing: "swamp" }
86+
ds.additional_pod_labels = { them: "hills", thing: "swamp" }
87+
ds.additional_pod_match_labels = { thing: "swamp" }
8788
ds.security_context = { runAsUser: 1000, runAsGroup: 1000 }
8889
ds.volumes = [{ name: "tmpvol", emptyDir: {} }]
8990

@@ -109,7 +110,7 @@
109110
},
110111
template: {
111112
metadata: {
112-
labels: { "metatron.therubyist.org/name": "test", thing: "swamp" }
113+
labels: { "metatron.therubyist.org/name": "test", them: "hills", thing: "swamp" }
113114
},
114115
spec: {
115116
containers: [

spec/metatron/templates/deployment_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
dep.namespace = "test-namespace"
8787
dep.replicas = 10
8888
dep.strategy = { type: "RollingUpdate", rollingUpdate: { maxSurge: 1, maxUnavailable: 0 } }
89-
dep.additional_pod_labels = { thing: "swamp" }
89+
dep.additional_pod_labels = { them: "hills", thing: "swamp" }
90+
dep.additional_pod_match_labels = { thing: "swamp" }
9091
dep.security_context = { runAsUser: 1000, runAsGroup: 1000 }
9192
dep.volumes = [{ name: "tmpvol", emptyDir: {} }]
9293

@@ -114,7 +115,7 @@
114115
},
115116
template: {
116117
metadata: {
117-
labels: { "metatron.therubyist.org/name": "test", thing: "swamp" }
118+
labels: { "metatron.therubyist.org/name": "test", them: "hills", thing: "swamp" }
118119
},
119120
spec: {
120121
containers: [

spec/metatron/templates/replica_set_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
rs.annotations = { "a.test/foo": "bar" }
7575
rs.additional_labels = { "app.kubernetes.io/part-of": "test-app" }
7676
rs.replicas = 10
77-
rs.additional_pod_labels = { thing: "swamp" }
77+
rs.additional_pod_labels = { them: "hills", thing: "swamp" }
78+
rs.additional_pod_match_labels = { thing: "swamp" }
7879
rs.security_context = { runAsUser: 1000, runAsGroup: 1000 }
7980
rs.volumes = [{ name: "tmpvol", emptyDir: {} }]
8081

@@ -100,7 +101,7 @@
100101
},
101102
template: {
102103
metadata: {
103-
labels: { "metatron.therubyist.org/name": "test", thing: "swamp" }
104+
labels: { "metatron.therubyist.org/name": "test", them: "hills", thing: "swamp" }
104105
},
105106
spec: {
106107
containers: [

spec/metatron/templates/stateful_set_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
rollingUpdate: { maxSurge: 2, maxUnavailable: 0 }, type: "RollingUpdate"
7272
}
7373
stateful_set.termination_grace_period_seconds = 10
74-
stateful_set.additional_pod_labels = { foo: "bar" }
74+
stateful_set.additional_pod_labels = { foo: "bar", them: "hills" }
75+
stateful_set.additional_pod_match_labels = { foo: "bar" }
7576
stateful_set.service_name = "a-test"
7677
stateful_set.persistent_volume_claims = [
7778
Metatron::Templates::PersistentVolumeClaim.new("test", storage_class: "test",
@@ -96,7 +97,8 @@
9697
updateStrategy: { rollingUpdate: { maxSurge: 2, maxUnavailable: 0 },
9798
type: "RollingUpdate" },
9899
template: {
99-
metadata: { labels: { "metatron.therubyist.org/name": "test", foo: "bar" } },
100+
metadata: { labels: { "metatron.therubyist.org/name": "test", foo: "bar",
101+
them: "hills" } },
100102
spec: {
101103
containers: [
102104
{

0 commit comments

Comments
 (0)