Skip to content

Commit 8395ae9

Browse files
committed
feat(498): Add ownerReferences to managed entities
1 parent 30b6124 commit 8395ae9

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

pkg/cluster/k8sres.go

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,10 +1473,11 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
14731473

14741474
statefulSet := &appsv1.StatefulSet{
14751475
ObjectMeta: metav1.ObjectMeta{
1476-
Name: c.statefulSetName(),
1477-
Namespace: c.Namespace,
1478-
Labels: c.labelsSet(true),
1479-
Annotations: c.AnnotationsToPropagate(c.annotationsSet(nil)),
1476+
Name: c.statefulSetName(),
1477+
Namespace: c.Namespace,
1478+
Labels: c.labelsSet(true),
1479+
Annotations: c.AnnotationsToPropagate(c.annotationsSet(nil)),
1480+
OwnerReferences: c.ownerReferences(),
14801481
},
14811482
Spec: appsv1.StatefulSetSpec{
14821483
Replicas: &numberOfInstances,
@@ -1813,10 +1814,11 @@ func (c *Cluster) generateSingleUserSecret(namespace string, pgUser spec.PgUser)
18131814

18141815
secret := v1.Secret{
18151816
ObjectMeta: metav1.ObjectMeta{
1816-
Name: c.credentialSecretName(username),
1817-
Namespace: pgUser.Namespace,
1818-
Labels: lbls,
1819-
Annotations: c.annotationsSet(nil),
1817+
Name: c.credentialSecretName(username),
1818+
Namespace: pgUser.Namespace,
1819+
Labels: lbls,
1820+
Annotations: c.annotationsSet(nil),
1821+
OwnerReferences: c.ownerReferences(),
18201822
},
18211823
Type: v1.SecretTypeOpaque,
18221824
Data: map[string][]byte{
@@ -1874,10 +1876,11 @@ func (c *Cluster) generateService(role PostgresRole, spec *acidv1.PostgresSpec)
18741876

18751877
service := &v1.Service{
18761878
ObjectMeta: metav1.ObjectMeta{
1877-
Name: c.serviceName(role),
1878-
Namespace: c.Namespace,
1879-
Labels: c.roleLabelsSet(true, role),
1880-
Annotations: c.annotationsSet(c.generateServiceAnnotations(role, spec)),
1879+
Name: c.serviceName(role),
1880+
Namespace: c.Namespace,
1881+
Labels: c.roleLabelsSet(true, role),
1882+
Annotations: c.annotationsSet(c.generateServiceAnnotations(role, spec)),
1883+
OwnerReferences: c.ownerReferences(),
18811884
},
18821885
Spec: serviceSpec,
18831886
}
@@ -1943,9 +1946,10 @@ func (c *Cluster) getCustomServiceAnnotations(role PostgresRole, spec *acidv1.Po
19431946
func (c *Cluster) generateEndpoint(role PostgresRole, subsets []v1.EndpointSubset) *v1.Endpoints {
19441947
endpoints := &v1.Endpoints{
19451948
ObjectMeta: metav1.ObjectMeta{
1946-
Name: c.endpointName(role),
1947-
Namespace: c.Namespace,
1948-
Labels: c.roleLabelsSet(true, role),
1949+
Name: c.endpointName(role),
1950+
Namespace: c.Namespace,
1951+
Labels: c.roleLabelsSet(true, role),
1952+
OwnerReferences: c.ownerReferences(),
19491953
},
19501954
}
19511955
if len(subsets) > 0 {
@@ -2099,10 +2103,11 @@ func (c *Cluster) generatePodDisruptionBudget() *policyv1.PodDisruptionBudget {
20992103

21002104
return &policyv1.PodDisruptionBudget{
21012105
ObjectMeta: metav1.ObjectMeta{
2102-
Name: c.podDisruptionBudgetName(),
2103-
Namespace: c.Namespace,
2104-
Labels: c.labelsSet(true),
2105-
Annotations: c.annotationsSet(nil),
2106+
Name: c.podDisruptionBudgetName(),
2107+
Namespace: c.Namespace,
2108+
Labels: c.labelsSet(true),
2109+
Annotations: c.annotationsSet(nil),
2110+
OwnerReferences: c.ownerReferences(),
21062111
},
21072112
Spec: policyv1.PodDisruptionBudgetSpec{
21082113
MinAvailable: &minAvailable,
@@ -2224,10 +2229,11 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1.CronJob, error) {
22242229

22252230
cronJob := &batchv1.CronJob{
22262231
ObjectMeta: metav1.ObjectMeta{
2227-
Name: c.getLogicalBackupJobName(),
2228-
Namespace: c.Namespace,
2229-
Labels: c.labelsSet(true),
2230-
Annotations: c.annotationsSet(nil),
2232+
Name: c.getLogicalBackupJobName(),
2233+
Namespace: c.Namespace,
2234+
Labels: c.labelsSet(true),
2235+
Annotations: c.annotationsSet(nil),
2236+
OwnerReferences: c.ownerReferences(),
22312237
},
22322238
Spec: batchv1.CronJobSpec{
22332239
Schedule: schedule,
@@ -2372,10 +2378,10 @@ func (c *Cluster) ownerReferences() []metav1.OwnerReference {
23722378

23732379
return []metav1.OwnerReference{
23742380
{
2375-
UID: c.Statefulset.ObjectMeta.UID,
2376-
APIVersion: "apps/v1",
2377-
Kind: "StatefulSet",
2378-
Name: c.Statefulset.ObjectMeta.Name,
2381+
UID: c.Postgresql.ObjectMeta.UID,
2382+
APIVersion: acidv1.SchemeGroupVersion.Identifier(),
2383+
Kind: acidv1.PostgresCRDResourceKind,
2384+
Name: c.Postgresql.ObjectMeta.Name,
23792385
Controller: &controller,
23802386
},
23812387
}

0 commit comments

Comments
 (0)