Skip to content

Commit

Permalink
Use EnsureOwnerRef in MachineDeployment and MachineSet controllers (#…
Browse files Browse the repository at this point in the history
…1093)

Signed-off-by: Vince Prignano <[email protected]>
  • Loading branch information
vincepri authored and k8s-ci-robot committed Jul 1, 2019
1 parent 5653faa commit 554a3a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/klog"
"k8s.io/utils/pointer"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/common"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha2"
"sigs.k8s.io/cluster-api/pkg/util"
Expand Down Expand Up @@ -175,14 +176,13 @@ func (r *ReconcileMachineDeployment) reconcile(ctx context.Context, d *v1alpha2.
}

// Set the ownerRef with foreground deletion if there is a linked cluster.
if cluster != nil && len(d.OwnerReferences) == 0 {
blockOwnerDeletion := true
d.OwnerReferences = append(d.OwnerReferences, metav1.OwnerReference{
if cluster != nil {
d.OwnerReferences = util.EnsureOwnerRef(d.OwnerReferences, metav1.OwnerReference{
APIVersion: cluster.APIVersion,
Kind: cluster.Kind,
Name: cluster.Name,
UID: cluster.UID,
BlockOwnerDeletion: &blockOwnerDeletion,
BlockOwnerDeletion: pointer.BoolPtr(true),
})
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/machineset/machineset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
"k8s.io/klog"
"k8s.io/utils/pointer"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha2"
"sigs.k8s.io/cluster-api/pkg/util"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -172,14 +173,13 @@ func (r *ReconcileMachineSet) reconcile(ctx context.Context, machineSet *cluster
}

// Set the ownerRef with foreground deletion if there is a linked cluster.
if cluster != nil && len(machineSet.OwnerReferences) == 0 {
blockOwnerDeletion := true
machineSet.OwnerReferences = append(machineSet.OwnerReferences, metav1.OwnerReference{
if cluster != nil {
machineSet.OwnerReferences = util.EnsureOwnerRef(machineSet.OwnerReferences, metav1.OwnerReference{
APIVersion: cluster.APIVersion,
Kind: cluster.Kind,
Name: cluster.Name,
UID: cluster.UID,
BlockOwnerDeletion: &blockOwnerDeletion,
BlockOwnerDeletion: pointer.BoolPtr(true),
})
}

Expand Down

0 comments on commit 554a3a1

Please sign in to comment.