Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/predicate/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (GenerationChangedPredicate) Update(e event.UpdateEvent) bool {
log.Error(nil, "Update event has no new metadata", "event", e)
return false
}
if e.MetaNew.GetGeneration() == e.MetaOld.GetGeneration() {
if e.MetaNew.GetGeneration() == e.MetaOld.GetGeneration() && e.MetaNew.GetGeneration() != 0 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that this will only happen if the metadata.generation is not set and therefore goes to the default integer value of 0 when queried.

return false
}
return true
Expand Down
56 changes: 56 additions & 0 deletions test/ansible/molecule/cluster/tasks/secrets_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
- name: Create the v1.Secret
k8s:
state: present
definition:
apiVersion: v1
kind: Secret
metadata:
name: test-secret
namespace: '{{ namespace }}'
labels:
reconcile: "yes"
data:
test: '{{ "test" | b64encode }}'

- name: Wait for the corresponding configmap to be created
k8s_info:
api_version: v1
kind: ConfigMap
name: test-secret
namespace: '{{ namespace }}'
register: result
until: result.resources
retries: 10

- name: Assert that the configmap has the proper content
assert:
that: result.resources.0.data.test == "test"

- name: Update the v1.Secret
k8s:
state: present
definition:
apiVersion: v1
kind: Secret
metadata:
name: test-secret
namespace: '{{ namespace }}'
labels:
reconcile: "yes"
data:
new: '{{ "content" | b64encode }}'

- name: Wait for the corresponding key to be created
k8s_facts:
api_version: v1
kind: ConfigMap
name: test-secret
namespace: '{{ namespace }}'
register: result
until: result.resources.0.data.new is defined
retries: 10

- name: Assert that the configmap has the proper content
assert:
that: result.resources.0.data.new == 'content'
23 changes: 23 additions & 0 deletions test/ansible/playbooks/secret.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- hosts: localhost
gather_facts: no
collections:
- community.kubernetes

tasks:
- meta: end_play
when: not (__secret.metadata.get('labels', {}).reconcile|default(false)|bool)

# This is for testing, but never do this with real secrets
- name: Populate configmap with contents of secret
k8s:
definition: |
apiVersion: v1
kind: ConfigMap
metadata:
name: '{{ meta.name }}'
namespace: '{{ meta.namespace }}'
data:
'{{ item.key }}': '{{ item.value | b64decode }}'
with_dict: '{{ __secret.data }}'

6 changes: 6 additions & 0 deletions test/ansible/watches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
group: test.example.com
kind: ExecTest
playbook: playbooks/exec.yml

- version: v1
group: ""
kind: Secret
playbook: playbooks/secret.yml
manageStatus: false