From ac80dff899decbb195463f8f71587ef1a9b3c69e Mon Sep 17 00:00:00 2001 From: nhanus <4275780+nhanus@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:17:14 +0100 Subject: [PATCH 1/2] fix windows file access handling --- cmd/kubernetes.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/kubernetes.go b/cmd/kubernetes.go index ca8980f7..65aa12f7 100644 --- a/cmd/kubernetes.go +++ b/cmd/kubernetes.go @@ -347,7 +347,9 @@ func loadCachedKubeConfig(id string) (*clientauth.ExecCredential, error) { return nil, err } - defer f.Close() + defer func() { + _ = f.Close() + }() var execCredential *clientauth.ExecCredential if err := json.NewDecoder(f).Decode(&execCredential); err != nil { @@ -357,7 +359,10 @@ func loadCachedKubeConfig(id string) (*clientauth.ExecCredential, error) { timeStamp := execCredential.Status.ExpirationTimestamp if execCredential.Status == nil || timeStamp.IsZero() || timeStamp.Time.Before(time.Now()) { - err = os.Remove(kubeConfigPath) + err = f.Close() + if err == nil { + err = os.Remove(kubeConfigPath) + } return nil, err } From 8ad263180df47b9f5cb284c274d9cfbecc283641 Mon Sep 17 00:00:00 2001 From: nhanus <4275780+nhanus@users.noreply.github.com> Date: Thu, 28 Mar 2024 08:18:38 +0100 Subject: [PATCH 2/2] revert defer changes --- cmd/kubernetes.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/kubernetes.go b/cmd/kubernetes.go index 65aa12f7..1eb442b3 100644 --- a/cmd/kubernetes.go +++ b/cmd/kubernetes.go @@ -347,9 +347,7 @@ func loadCachedKubeConfig(id string) (*clientauth.ExecCredential, error) { return nil, err } - defer func() { - _ = f.Close() - }() + defer f.Close() var execCredential *clientauth.ExecCredential if err := json.NewDecoder(f).Decode(&execCredential); err != nil {