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

chore: enable host process deployment test #1287

Merged
merged 4 commits into from
May 27, 2023
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
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ ARCH ?= amd64
OSVERSION ?= 1809
# Output type of docker buildx build
OUTPUT_TYPE ?= registry
# enable host process containers for Windows
USE_HOST_PROCESS_CONTAINERS ?= false

.EXPORT_ALL_VARIABLES:

Expand Down Expand Up @@ -100,21 +98,20 @@ e2e-test:
.PHONY: e2e-bootstrap
e2e-bootstrap: install-helm
ifdef WINDOWS_USE_HOST_PROCESS_CONTAINERS
(docker pull $(CSI_IMAGE_TAG) && docker pull $(CSI_IMAGE_TAG)-windows-hp) || make container-all push-manifest
USE_HOST_PROCESS_CONTAINERS=${WINDOWS_USE_HOST_PROCESS_CONTAINERS}
(docker pull $(CSI_IMAGE_TAG) && docker pull $(CSI_IMAGE_TAG)-windows-hp) || make container-all push-manifest
else
docker pull $(CSI_IMAGE_TAG) || make container-all push-manifest
endif
ifdef TEST_WINDOWS
helm install azurefile-csi-driver charts/latest/azurefile-csi-driver --namespace kube-system --wait --timeout=15m -v=5 --debug \
${E2E_HELM_OPTIONS} \
--set windows.enabled=true \
--set windows.useHostProcessContainers=${USE_HOST_PROCESS_CONTAINERS} \
--set windows.useHostProcessContainers=${WINDOWS_USE_HOST_PROCESS_CONTAINERS} \
--set linux.enabled=false \
--set driver.azureGoSDKLogLevel=INFO \
--set controller.replicas=1 \
--set controller.logLevel=6 \
--set node.logLevel=6
--set node.logLevel=10
else
helm install azurefile-csi-driver charts/latest/azurefile-csi-driver --namespace kube-system --wait --timeout=15m -v=5 --debug \
${E2E_HELM_OPTIONS} \
Expand Down
6 changes: 5 additions & 1 deletion pkg/os/smb/smb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"fmt"
"strings"

"k8s.io/klog/v2"
"sigs.k8s.io/azurefile-csi-driver/pkg/util"
)

func IsSmbMapped(remotePath string) (bool, error) {
cmdLine := `$(Get-SmbGlobalMapping -RemotePath $Env:smbremotepath -ErrorAction Stop).Status `
cmdLine := `$(Get-SmbGlobalMapping -RemotePath $Env:smbremotepath -ErrorAction Stop).Status`
cmdEnv := fmt.Sprintf("smbremotepath=%s", remotePath)
out, err := util.RunPowershellCmd(cmdLine, cmdEnv)
if err != nil {
Expand Down Expand Up @@ -52,6 +53,7 @@ func NewSmbLink(remotePath, localPath string) error {
}

cmdLine := `New-Item -ItemType SymbolicLink $Env:smblocalPath -Target $Env:smbremotepath`
klog.V(2).Infof("begin to run NewSmbLink with %s, %s", remotePath, localPath)
output, err := util.RunPowershellCmd(cmdLine, fmt.Sprintf("smbremotepath=%s", remotePath), fmt.Sprintf("smblocalpath=%s", localPath))
if err != nil {
return fmt.Errorf("error linking %s to %s. output: %s, err: %v", remotePath, localPath, string(output), err)
Expand All @@ -67,6 +69,7 @@ func NewSmbGlobalMapping(remotePath, username, password string) error {
`;$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Env:smbuser, $PWord` +
`;New-SmbGlobalMapping -RemotePath $Env:smbremotepath -Credential $Credential -RequirePrivacy $true`)

klog.V(2).Infof("begin to run NewSmbGlobalMapping with %s, %s", remotePath, username)
if output, err := util.RunPowershellCmd(cmdLine, fmt.Sprintf("smbuser=%s", username),
fmt.Sprintf("smbpassword=%s", password),
fmt.Sprintf("smbremotepath=%s", remotePath)); err != nil {
Expand All @@ -77,6 +80,7 @@ func NewSmbGlobalMapping(remotePath, username, password string) error {

func RemoveSmbGlobalMapping(remotePath string) error {
cmd := `Remove-SmbGlobalMapping -RemotePath $Env:smbremotepath -Force`
klog.V(2).Infof("begin to run RemoveSmbGlobalMapping with %s", remotePath)
if output, err := util.RunPowershellCmd(cmd, fmt.Sprintf("smbremotepath=%s", remotePath)); err != nil {
return fmt.Errorf("UnmountSmbShare failed. output: %q, err: %v", string(output), err)
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package util
import (
"os"
"os/exec"
"sync"

"k8s.io/klog/v2"
)
Expand All @@ -28,6 +29,8 @@ const (
MaxPathLengthWindows = 260
)

var mutex = &sync.Mutex{}

// RoundUpBytes rounds up the volume size in bytes up to multiplications of GiB
// in the unit of Bytes
func RoundUpBytes(volumeSizeBytes int64) int64 {
Expand Down Expand Up @@ -64,9 +67,12 @@ func roundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 {
}

func RunPowershellCmd(command string, envs ...string) ([]byte, error) {
// only one powershell command can be executed at a time to avoid OOM
mutex.Lock()
defer mutex.Unlock()

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