Skip to content

Commit 2f298f7

Browse files
authored
Resources without generation will not skip events (#2830)
* Resources without generation will not skip events Fixes #2108 If the `metadata.generation` is `0`, the event will now still trigger a reconciliation.
1 parent 7445d40 commit 2f298f7

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

pkg/predicate/predicate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (GenerationChangedPredicate) Update(e event.UpdateEvent) bool {
4646
log.Error(nil, "Update event has no new metadata", "event", e)
4747
return false
4848
}
49-
if e.MetaNew.GetGeneration() == e.MetaOld.GetGeneration() {
49+
if e.MetaNew.GetGeneration() == e.MetaOld.GetGeneration() && e.MetaNew.GetGeneration() != 0 {
5050
return false
5151
}
5252
return true
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
- name: Create the v1.Secret
3+
k8s:
4+
state: present
5+
definition:
6+
apiVersion: v1
7+
kind: Secret
8+
metadata:
9+
name: test-secret
10+
namespace: '{{ namespace }}'
11+
labels:
12+
reconcile: "yes"
13+
data:
14+
test: '{{ "test" | b64encode }}'
15+
16+
- name: Wait for the corresponding configmap to be created
17+
k8s_info:
18+
api_version: v1
19+
kind: ConfigMap
20+
name: test-secret
21+
namespace: '{{ namespace }}'
22+
register: result
23+
until: result.resources
24+
retries: 10
25+
26+
- name: Assert that the configmap has the proper content
27+
assert:
28+
that: result.resources.0.data.test == "test"
29+
30+
- name: Update the v1.Secret
31+
k8s:
32+
state: present
33+
definition:
34+
apiVersion: v1
35+
kind: Secret
36+
metadata:
37+
name: test-secret
38+
namespace: '{{ namespace }}'
39+
labels:
40+
reconcile: "yes"
41+
data:
42+
new: '{{ "content" | b64encode }}'
43+
44+
- name: Wait for the corresponding key to be created
45+
k8s_facts:
46+
api_version: v1
47+
kind: ConfigMap
48+
name: test-secret
49+
namespace: '{{ namespace }}'
50+
register: result
51+
until: result.resources.0.data.new is defined
52+
retries: 10
53+
54+
- name: Assert that the configmap has the proper content
55+
assert:
56+
that: result.resources.0.data.new == 'content'

test/ansible/playbooks/secret.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- hosts: localhost
3+
gather_facts: no
4+
collections:
5+
- community.kubernetes
6+
7+
tasks:
8+
- meta: end_play
9+
when: not (__secret.metadata.get('labels', {}).reconcile|default(false)|bool)
10+
11+
# This is for testing, but never do this with real secrets
12+
- name: Populate configmap with contents of secret
13+
k8s:
14+
definition: |
15+
apiVersion: v1
16+
kind: ConfigMap
17+
metadata:
18+
name: '{{ meta.name }}'
19+
namespace: '{{ meta.namespace }}'
20+
data:
21+
'{{ item.key }}': '{{ item.value | b64decode }}'
22+
with_dict: '{{ __secret.data }}'
23+

test/ansible/watches.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313
group: test.example.com
1414
kind: ExecTest
1515
playbook: playbooks/exec.yml
16+
17+
- version: v1
18+
group: ""
19+
kind: Secret
20+
playbook: playbooks/secret.yml
21+
manageStatus: false

0 commit comments

Comments
 (0)