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

test: improve ut coverage #2820

Merged
merged 2 commits into from
Jan 16, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=profile.cov -service=github -ignore=./pkg/azuredisk/mockcorev1/interface.go,pkg/azuredisk/mockkubeclient/interface.go,pkg/azuredisk/mockpersistentvolume/interface.go,pkg/azureutils/fake_iohandler.go,pkg/mounter/fake_safe_mounter.go
run: goveralls -coverprofile=profile.cov -service=github -ignore=pkg/azuredisk/mockcorev1/interface.go,pkg/azuredisk/mockkubeclient/interface.go,pkg/azuredisk/mockpersistentvolume/interface.go,pkg/azureutils/fake_iohandler.go,pkg/mounter/fake_safe_mounter.go
15 changes: 0 additions & 15 deletions pkg/azureutils/azure_disk_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
Expand Down Expand Up @@ -86,9 +85,6 @@ var (
{Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_SINGLE_WRITER},
{Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER},
}

// control the number of concurrent powershell commands running on Windows node
powershellCmdSem = make(chan struct{}, 3)
)

type ManagedDiskParameters struct {
Expand Down Expand Up @@ -830,17 +826,6 @@ func SetKeyValueInMap(m map[string]string, key, value string) {
m[key] = value
}

func RunPowershellCmd(command string, envs ...string) ([]byte, error) {
// acquire a semaphore to limit the number of concurrent operations
powershellCmdSem <- struct{}{}
defer func() { <-powershellCmdSem }()

cmd := exec.Command("powershell", "-Mta", "-NoProfile", "-Command", command)
cmd.Env = append(os.Environ(), envs...)
klog.V(6).Infof("Executing command: %q", cmd.String())
return cmd.CombinedOutput()
}

// GenerateVolumeName returns a PV name with clusterName prefix. The function
// should be used to generate a name of GCE PD or Cinder volume. It basically
// adds "<clusterName>-dynamic-" before the PV name, making sure the resulting
Expand Down
41 changes: 41 additions & 0 deletions pkg/azureutils/azure_disk_utils_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//go:build windows
// +build windows

/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package azureutils

import (
"os"
"os/exec"

"k8s.io/klog/v2"
)

// control the number of concurrent powershell commands running on Windows node
var powershellCmdSem = make(chan struct{}, 3)

func RunPowershellCmd(command string, envs ...string) ([]byte, error) {
// acquire a semaphore to limit the number of concurrent operations
powershellCmdSem <- struct{}{}
defer func() { <-powershellCmdSem }()

cmd := exec.Command("powershell", "-Mta", "-NoProfile", "-Command", command)
cmd.Env = append(os.Environ(), envs...)
klog.V(6).Infof("Executing command: %q", cmd.String())
return cmd.CombinedOutput()
}
Loading