1
- # Owner References for Existing Resources
1
+ # Adding Owner References for Existing Resources
2
2
3
- Owner references are automatically injected * only during creation of
4
- resources* . Enabling owner reference injection * will not update objects*
3
+ Owner references are automatically injected ` only during creation of
4
+ resources` . Enabling owner reference injection ` will not update objects`
5
5
created while [ owner reference injection is
6
6
disabled] ( ./advanced_options.md#turning-off-dependent-watches-and-owner-reference-injection )
7
- .
8
7
9
8
This guide will demonstrate how to retroactively set owner references
10
9
for existing resources.
11
10
12
- ### Owner References and Annotations
11
+ A GET request to the owning resource will provide the necessary data to
12
+ construct an ` ownerReference ` or an ` annotation ` .
13
+
14
+ ` $ kubectl get memcacheds.cache.example.com -o yaml `
15
+
16
+ ** Example Response (Abbreviated):**
17
+
18
+ ``` yaml
19
+ apiVersion : cache.example.com/v1alpha1
20
+ kind : Memcached
21
+ metadata :
22
+ name : example-memcached
23
+ namespace : default
24
+ uid : 2a94ff2b-84e0-40ce-8b5e-2b7e4d2bc0e2
25
+ ` ` `
13
26
14
- Dependent resources * within the same namespace as the owning CR* are
27
+ ` kubectl edit` can be used to update the resources by hand. See below
28
+ for example `ownerReference` and `annotations`.
29
+
30
+ # # For objects in the same namespace as the Owner (CRD)
31
+
32
+ Dependent resources `within the same namespace as the owning CR` are
15
33
tracked with the `ownerReference` field.
16
34
17
35
`ownerReference` structure :
@@ -20,10 +38,9 @@ tracked with the `ownerReference` field.
20
38
* name: {metadata.name}
21
39
* uid: {metadata.uid}
22
40
23
- ** Example:**
41
+ **Example ownerReference :**
24
42
25
43
` ` ` yaml
26
-
27
44
metadata:
28
45
...(snip)
29
46
ownerReferences:
@@ -33,38 +50,50 @@ metadata:
33
50
uid: ad834522-d9a5-4841-beac-991ff3798c00
34
51
` ` `
35
52
53
+ # # For objects which are NOT in the same namespace as the Owner (CRD)
54
+
36
55
An `annotation` is used instead of an `ownerReference` if the dependent
37
- resource is in a different namespace than the CR or the dependent
56
+ resource is in a different namespace than the CR, or the dependent
38
57
resource is a cluster level resource.
39
58
40
59
`annotation` structure :
41
- * operator-sdk/primary-resource: {metadata.namepace }/{metadata.name}
60
+ * operator-sdk/primary-resource: {metadata.namespace }/{metadata.name}
42
61
* operator-sdk/primary-resource-type: {kind}.{group}
43
62
44
- *Note: <group> must be determined by splitting the apiVersion field at the "/"*
63
+ **NOTE**: The {group} can be found by splitting the `apiVersion`
64
+ metadata of the CR, into `group` and `version`. As an example,
65
+ [this apiVersion field](https://github.com/operator-framework/operator-sdk-samples/blob/master/ansible/memcached-operator/deploy/crds/cache_v1alpha1_memcached_cr.yaml#L1)
66
+ gives us the group `cache.example.com`.
67
+
68
+ **Example Annotation:**
45
69
46
70
` ` ` yaml
47
71
metadata:
72
+ ...(snip)
48
73
annotations:
49
74
operator-sdk/primary-resource: default/example-memcached
50
75
operator-sdk/primary-resource-type: Memcached.cache.example.com
51
76
` ` `
52
77
53
- A GET request to the owning resource will provide the necessary data to
54
- construct an `ownerReference` or an `annotation`.
78
+ # # Migration using Ansible assets
55
79
56
- ` $ kubectl get memcacheds.cache.example.com -o yaml`
80
+ If you have many resources to update, it may be easier to use the
81
+ following Ansible assets, which **should be considered an example rather
82
+ than an officially supported workflow**.
57
83
58
- ` kubectl edit` can be used to update the resources by hand.
84
+ To use these assets, create a `vars.yml` as specified below and copy
85
+ ` playbook.yml` and `each_resource.yml` into the same directory. Execute
86
+ the playbook with :
59
87
60
- # ## Migration Playbook
88
+ ` ` ` bash
89
+ $ ansible-playbook -i localhost playbook.yml
90
+ ` ` `
61
91
62
- If you have many resources to update, it may be easier to use the
63
- following (unsupported) playbook.
92
+ # ## vars.yml
64
93
65
- # ### vars.yml
94
+ This file should be created by the user to configure the playbook, and
95
+ needs to contain :
66
96
67
- Users will configure the playbook by providing a `vars.yml` file which will specify :
68
97
* owning_resource
69
98
* apiVersion
70
99
* kind
@@ -76,8 +105,6 @@ Users will configure the playbook by providing a `vars.yml` file which will spec
76
105
* apiVersion
77
106
* kind
78
107
79
- **Example File:**
80
-
81
108
` ` ` yaml
82
109
owning_resource:
83
110
apiVersion: cache.example.com/v1alpha1
@@ -94,7 +121,10 @@ resources_to_own:
94
121
apiVersion: v1
95
122
kind: Namespace
96
123
` ` `
97
- # ### playbook.yml
124
+
125
+ # ## playbook.yml
126
+
127
+ This file can be used as-is without user adjustments.
98
128
99
129
` ` ` yaml
100
130
- hosts: localhost
@@ -127,7 +157,9 @@ resources_to_own:
127
157
uid: "{{ extra_owner_data.resources[0].metadata.uid }}"
128
158
` ` `
129
159
130
- # ### `each_resource.yml`
160
+ # ## `each_resource.yml`
161
+
162
+ This file can be used as-is without user adjustments.
131
163
132
164
` ` ` yaml
133
165
- name: Patch resource with owner reference
0 commit comments