From b6ce262e7ff608c97aecb1efbc000195f0b42f10 Mon Sep 17 00:00:00 2001 From: Yuichiro Ueno Date: Sat, 11 Dec 2021 11:42:31 +0900 Subject: [PATCH] core: add context to k8sutil replicaset and secret This commit adds context parameter to k8sutil replicaset and secret functions. By this, we can handle cancellation during API call of replicaset and secret resource. Signed-off-by: Yuichiro Ueno --- pkg/operator/ceph/controller/mirror_peer.go | 2 +- pkg/operator/k8sutil/replicaset.go | 3 +-- pkg/operator/k8sutil/secret.go | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/operator/ceph/controller/mirror_peer.go b/pkg/operator/ceph/controller/mirror_peer.go index d033488e9bd6..25f0fc4baa44 100644 --- a/pkg/operator/ceph/controller/mirror_peer.go +++ b/pkg/operator/ceph/controller/mirror_peer.go @@ -107,7 +107,7 @@ func CreateBootstrapPeerSecret(ctx *clusterd.Context, clusterInfo *cephclient.Cl // Create Secret logger.Debugf("store %s-mirror bootstrap token in a Kubernetes Secret %q in namespace %q", daemonType, s.Name, ns) - _, err = k8sutil.CreateOrUpdateSecret(ctx.Clientset, s) + _, err = k8sutil.CreateOrUpdateSecret(clusterInfo.Context, ctx.Clientset, s) if err != nil && !kerrors.IsAlreadyExists(err) { return ImmediateRetryResult, errors.Wrapf(err, "failed to create %s-mirror bootstrap peer %q secret", daemonType, s.Name) } diff --git a/pkg/operator/k8sutil/replicaset.go b/pkg/operator/k8sutil/replicaset.go index 9b719e9d1013..d502752d80cc 100644 --- a/pkg/operator/k8sutil/replicaset.go +++ b/pkg/operator/k8sutil/replicaset.go @@ -24,8 +24,7 @@ import ( ) // DeleteReplicaSet makes a best effort at deleting a deployment and its pods, then waits for them to be deleted -func DeleteReplicaSet(clientset kubernetes.Interface, namespace, name string) error { - ctx := context.TODO() +func DeleteReplicaSet(ctx context.Context, clientset kubernetes.Interface, namespace, name string) error { deleteAction := func(options *metav1.DeleteOptions) error { return clientset.AppsV1().ReplicaSets(namespace).Delete(ctx, name, *options) } diff --git a/pkg/operator/k8sutil/secret.go b/pkg/operator/k8sutil/secret.go index e63f98332910..3a68ac4afdd3 100644 --- a/pkg/operator/k8sutil/secret.go +++ b/pkg/operator/k8sutil/secret.go @@ -27,8 +27,7 @@ import ( ) // CreateOrUpdateSecret creates a secret or updates the secret declaratively if it already exists. -func CreateOrUpdateSecret(clientset kubernetes.Interface, secretDefinition *v1.Secret) (*v1.Secret, error) { - ctx := context.TODO() +func CreateOrUpdateSecret(ctx context.Context, clientset kubernetes.Interface, secretDefinition *v1.Secret) (*v1.Secret, error) { name := secretDefinition.Name logger.Debugf("creating secret %s", name)