Skip to content

Commit f675884

Browse files
committed
add OwnerReference for Statefulsets
1 parent c6f0172 commit f675884

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

pkg/cluster/cluster.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,19 @@ func (c *Cluster) clusterNamespace() string {
176176
return c.ObjectMeta.Namespace
177177
}
178178

179+
func (c *Cluster) createOwnerReference() []metav1.OwnerReference {
180+
return []metav1.OwnerReference{
181+
{
182+
APIVersion: c.APIVersion,
183+
Kind: c.Kind,
184+
Name: c.Name,
185+
UID: c.UID,
186+
Controller: util.True(),
187+
BlockOwnerDeletion: util.True(),
188+
},
189+
}
190+
}
191+
179192
func (c *Cluster) teamName() string {
180193
// TODO: check Teams API for the actual name (in case the user passes an integer Id).
181194
return c.Spec.TeamID

pkg/cluster/k8sres.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,10 +1660,11 @@ func (c *Cluster) generateStatefulSet(spec *cpov1.PostgresSpec) (*appsv1.Statefu
16601660

16611661
statefulSet := &appsv1.StatefulSet{
16621662
ObjectMeta: metav1.ObjectMeta{
1663-
Name: c.statefulSetName(),
1664-
Namespace: c.Namespace,
1665-
Labels: c.labelsSetWithType(true, TYPE_POSTGRESQL),
1666-
Annotations: c.AnnotationsToPropagate(c.annotationsSet(nil)),
1663+
Name: c.statefulSetName(),
1664+
Namespace: c.Namespace,
1665+
Labels: c.labelsSetWithType(true, TYPE_POSTGRESQL),
1666+
Annotations: c.AnnotationsToPropagate(c.annotationsSet(nil)),
1667+
OwnerReferences: c.createOwnerReference(),
16671668
},
16681669
Spec: appsv1.StatefulSetSpec{
16691670
Replicas: &numberOfInstances,
@@ -1921,10 +1922,11 @@ func (c *Cluster) generateRepoHostStatefulSet(spec *cpov1.PostgresSpec) (*appsv1
19211922

19221923
statefulSet := &appsv1.StatefulSet{
19231924
ObjectMeta: metav1.ObjectMeta{
1924-
Name: c.getPgbackrestRepoHostName(),
1925-
Namespace: c.Namespace,
1926-
Labels: repoHostLabels,
1927-
Annotations: c.AnnotationsToPropagate(c.annotationsSet(nil)),
1925+
Name: c.getPgbackrestRepoHostName(),
1926+
Namespace: c.Namespace,
1927+
Labels: repoHostLabels,
1928+
Annotations: c.AnnotationsToPropagate(c.annotationsSet(nil)),
1929+
OwnerReferences: c.createOwnerReference(),
19281930
},
19291931
Spec: appsv1.StatefulSetSpec{
19301932
Replicas: &numberOfInstances,

0 commit comments

Comments
 (0)