Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: add context parameter to k8sutil configMap #9394

Merged
merged 1 commit into from Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/operator/k8sutil/cmdreporter/cmdreporter.go
Expand Up @@ -155,7 +155,7 @@ func (cr *CmdReporter) Run(ctx context.Context, timeout time.Duration) (stdout,
delOpts.Wait = true
delOpts.ErrorOnTimeout = true
// configmap's name will be the same as the app
err := k8sutil.DeleteConfigMap(cr.clientset, jobName, namespace, delOpts)
err := k8sutil.DeleteConfigMap(ctx, cr.clientset, jobName, namespace, delOpts)
if err != nil {
return "", "", -1, fmt.Errorf("%s. failed to delete existing results ConfigMap %s. %+v", errMsg, jobName, err)
}
Expand All @@ -180,7 +180,7 @@ func (cr *CmdReporter) Run(ctx context.Context, timeout time.Duration) (stdout,

// just to be explicit: delete idempotently, and don't wait for delete to complete
delOpts = &k8sutil.DeleteOptions{MustDelete: false, WaitOptions: k8sutil.WaitOptions{Wait: false}}
if err := k8sutil.DeleteConfigMap(cr.clientset, jobName, namespace, delOpts); err != nil {
if err := k8sutil.DeleteConfigMap(ctx, cr.clientset, jobName, namespace, delOpts); err != nil {
logger.Errorf("continuing after failing to delete ConfigMap %s for job %s; user may need to delete it manually. %+v",
jobName, jobName, err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/operator/k8sutil/configmap.go
Expand Up @@ -28,8 +28,7 @@ import (
)

// DeleteConfigMap deletes a ConfigMap.
func DeleteConfigMap(clientset kubernetes.Interface, cmName, namespace string, opts *DeleteOptions) error {
ctx := context.TODO()
func DeleteConfigMap(ctx context.Context, clientset kubernetes.Interface, cmName, namespace string, opts *DeleteOptions) error {
k8sOpts := BaseKubernetesDeleteOptions()
delete := func() error { return clientset.CoreV1().ConfigMaps(namespace).Delete(ctx, cmName, *k8sOpts) }
verify := func() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/k8sutil/configmap_test.go
Expand Up @@ -51,7 +51,7 @@ func TestDeleteConfigMap(t *testing.T) {
opts := &DeleteOptions{}
opts.Wait = true
opts.ErrorOnTimeout = true
err = DeleteConfigMap(k8s, "test-configmap", "test-namespace", opts)
err = DeleteConfigMap(ctx, k8s, "test-configmap", "test-namespace", opts)
assert.NoError(t, err)

_, err = k8s.CoreV1().ConfigMaps("test-namespace").Get(ctx, "test-configmap", metav1.GetOptions{})
Expand Down