Skip to content

Commit

Permalink
Merge pull request #2820 from andyzhangx/add-ut
Browse files Browse the repository at this point in the history
test: improve ut coverage
  • Loading branch information
andyzhangx authored Jan 16, 2025
2 parents 209bbcd + ba51f1a commit ae3e562
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
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()
}

0 comments on commit ae3e562

Please sign in to comment.