Skip to content

Commit

Permalink
Use context.Context as first parameter for external.Get
Browse files Browse the repository at this point in the history
  • Loading branch information
tahsinrahman committed Oct 16, 2019
1 parent 6ae7aac commit 214c917
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion controllers/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (r *ClusterReconciler) reconcileDelete(ctx context.Context, cluster *cluste
}

if cluster.Spec.InfrastructureRef != nil {
obj, err := external.Get(r.Client, cluster.Spec.InfrastructureRef, cluster.Namespace)
obj, err := external.Get(ctx, r.Client, cluster.Spec.InfrastructureRef, cluster.Namespace)
switch {
case apierrors.IsNotFound(err):
// All good - the infra resource has been deleted
Expand Down
2 changes: 1 addition & 1 deletion controllers/cluster_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (r *ClusterReconciler) reconcilePhase(ctx context.Context, cluster *cluster

// reconcileExternal handles generic unstructured objects referenced by a Cluster.
func (r *ClusterReconciler) reconcileExternal(ctx context.Context, cluster *clusterv1.Cluster, ref *corev1.ObjectReference) (*unstructured.Unstructured, error) {
obj, err := external.Get(r.Client, ref, cluster.Namespace)
obj, err := external.Get(ctx, r.Client, ref, cluster.Namespace)
if err != nil {
if apierrors.IsNotFound(err) {
return nil, errors.Wrapf(&capierrors.RequeueAfterError{RequeueAfter: 30 * time.Second},
Expand Down
6 changes: 3 additions & 3 deletions controllers/external/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ import (
)

// Get uses the client and reference to get an external, unstructured object.
func Get(c client.Client, ref *corev1.ObjectReference, namespace string) (*unstructured.Unstructured, error) {
func Get(ctx context.Context, c client.Client, ref *corev1.ObjectReference, namespace string) (*unstructured.Unstructured, error) {
obj := new(unstructured.Unstructured)
obj.SetAPIVersion(ref.APIVersion)
obj.SetKind(ref.Kind)
obj.SetName(ref.Name)
key := client.ObjectKey{Name: obj.GetName(), Namespace: namespace}
if err := c.Get(context.Background(), key, obj); err != nil {
if err := c.Get(ctx, key, obj); err != nil {
return nil, err
}
return obj, nil
}

// CloneTemplate uses the client and the reference to create a new object from the template.
func CloneTemplate(c client.Client, ref *corev1.ObjectReference, namespace string) (*unstructured.Unstructured, error) {
from, err := Get(c, ref, namespace)
from, err := Get(context.TODO(), c, ref, namespace)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (r *MachineReconciler) reconcileDeleteExternal(ctx context.Context, m *clus
continue
}

obj, err := external.Get(r.Client, ref, m.Namespace)
obj, err := external.Get(ctx, r.Client, ref, m.Namespace)
if err != nil && !apierrors.IsNotFound(err) {
return false, errors.Wrapf(err, "failed to get %s %q for Machine %q in namespace %q",
ref.GroupVersionKind(), ref.Name, m.Name, m.Namespace)
Expand Down
2 changes: 1 addition & 1 deletion controllers/machine_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *MachineReconciler) reconcilePhase(ctx context.Context, m *clusterv1.Mac

// reconcileExternal handles generic unstructured objects referenced by a Machine.
func (r *MachineReconciler) reconcileExternal(ctx context.Context, m *clusterv1.Machine, ref *corev1.ObjectReference) (*unstructured.Unstructured, error) {
obj, err := external.Get(r.Client, ref, m.Namespace)
obj, err := external.Get(ctx, r.Client, ref, m.Namespace)
if err != nil {
if apierrors.IsNotFound(err) {
return nil, errors.Wrapf(&capierrors.RequeueAfterError{RequeueAfter: externalReadyWait},
Expand Down

0 comments on commit 214c917

Please sign in to comment.