Skip to content

cleanup: Bump microsoft/wmi to 0.34.0 containing WMI method call fix #394

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

Merged
merged 1 commit into from
Jul 14, 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
6 changes: 3 additions & 3 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
integration_tests:
strategy:
matrix:
go: ['1.22']
go: ['1.24']
platform: [windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
unit_tests:
strategy:
matrix:
go: ['1.22']
go: ['1.24']
platform: [windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -69,7 +69,7 @@ jobs:
bump_version_test:
strategy:
matrix:
go: ['1.22']
go: ['1.24']
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
29 changes: 4 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,6 @@ BUILD_TOOLS_DIR = $(BUILD_DIR)/tools
GO_ENV_VARS = GO111MODULE=on GOOS=windows
CSI_PROXY_API_GEN = $(BUILD_DIR)/csi-proxy-api-gen

# overrides the $(CMDS:%=build-%) rule in release-tools/build.make because this project is not compatible with go >1.23
# TODO: remove this override as part of https://github.com/kubernetes-csi/csi-proxy/issues/361
build-csi-proxy: check-go-version-go
# Checks that the go version is 1.22 or lower
if (( "$$(go version | awk '{print $3}' | sed 's/go//' | cut -d'.' -f2)" > 22 )); then echo "This project requires go 1.22 or lower"; exit 1; fi;
mkdir -p bin
# os_arch_seen captures all of the $$os-$$arch-$$buildx_platform seen for the current binary
# that we want to build, if we've seen an $$os-$$arch-$$buildx_platform before it means that
# we don't need to build it again, this is done to avoid building
# the windows binary multiple times (see the default value of $$BUILD_PLATFORMS)
export os_arch_seen="" && echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch buildx_platform suffix base_image addon_image; do \
os_arch_seen_pre=$${os_arch_seen%%$$os-$$arch-$$buildx_platform*}; \
if ! [ $${#os_arch_seen_pre} = $${#os_arch_seen} ]; then \
continue; \
fi; \
if ! (set -x; cd ./$(CMDS_DIR)/$* && CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags '$(FULL_LDFLAGS)' -o "$(abspath ./bin)/$*$$suffix" .); then \
echo "Building $* for GOOS=$$os GOARCH=$$arch failed, see error(s) above."; \
exit 1; \
fi; \
os_arch_seen+=";$$os-$$arch-$$buildx_platform"; \
done

.PHONY: compile-csi-proxy-api-gen
compile-csi-proxy-api-gen:
GO111MODULE=on go build -o $(CSI_PROXY_API_GEN) ./cmd/csi-proxy-api-gen
Expand Down Expand Up @@ -83,16 +61,17 @@ test: test-go
test-go:
@ echo; echo "### $@:"
# TODO: After issue https://github.com/microsoft/go-winio/pull/169 is resolved, remove the filter on the test path.
GO111MODULE=on go test `find ./internal/server/ -type d -not -name server`;\
cd client && GO111MODULE=on go test `go list ./... | grep -v group` && cd ../
# GO111MODULE=on go test `find ./pkg/server/ -type d -not -name server`;\
cd client && GO111MODULE=on go test `go list ./... | grep -v group` && cd ../

.PHONY: test-vet
test: test-vet
test-vet:
@ echo; echo "### $@:"
# TODO: After issue https://github.com/microsoft/go-winio/pull/169 is resolved, remove the filter on the test path.
# GO111MODULE=on go vet `find ./internal/server/ -type d -not -name server`;\
cd client && GO111MODULE=on go vet `go list ./... | grep -v group` && cd ../
cd client && GO111MODULE=on go vet `go list ./... | grep -v group` && cd ../

# see https://github.com/golangci/golangci-lint#binary-release
$(GOLANGCI_LINT):
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$$(dirname '$(GOLANGCI_LINT)')" '$(GOLANGCI_LINT_VERSION)'
2 changes: 1 addition & 1 deletion docs/IMPLEMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ For example, the property `PartitionStyle` on [MSFT_Disk](https://learn.microsof
| Qualifiers | Required |
| Description | The partition style used by the disk. |

You may use `GetProperty` to get the value of `PartitionStyle` to get the value from the `VARAINT` and
You may use `GetProperty` to get the value of `PartitionStyle` to get the value from the `VARIANT` and
converts it back to Go types.

```go
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ module github.com/kubernetes-csi/csi-proxy
// NOTE: This project must be built with go < 1.23
// `make build` will error if go1.23 or higher is used.

go 1.22.0
go 1.24.3

toolchain go1.22.3
godebug winsymlink=0

toolchain go1.24.4

require (
github.com/Microsoft/go-winio v0.6.2
Expand All @@ -14,13 +16,13 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
github.com/iancoleman/strcase v0.3.0
github.com/kubernetes-csi/csi-proxy/client v1.1.3
github.com/microsoft/wmi v0.25.1
github.com/microsoft/wmi v0.34.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.5
github.com/sergi/go-diff v1.3.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.10.0
golang.org/x/sys v0.28.0
golang.org/x/sys v0.32.0
google.golang.org/grpc v1.69.2
google.golang.org/protobuf v1.36.0
k8s.io/component-base v0.28.4
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mauriciopoppe/gengo v0.0.0-20210525224835-9c78f58f3486 h1:+l047vEi0SyAzdVToIaAcfoY5DwwGW+OyqTdH/P3TTg=
github.com/mauriciopoppe/gengo v0.0.0-20210525224835-9c78f58f3486/go.mod h1:xXv3T4UXTLta31wMhVezwVkc26OLei4hMbLeBJbPmxc=
github.com/microsoft/wmi v0.25.1 h1:sQv9hCEHtW5K6yEVL78T6XGRMGxk4aTpcJwCiB5rLN0=
github.com/microsoft/wmi v0.25.1/go.mod h1:1zbdSF0A+5OwTUII5p3hN7/K6KF2m3o27pSG6Y51VU8=
github.com/microsoft/wmi v0.34.0 h1:1OqBM8Ha8CWMbKYDH6EqUmozgxZ0IuoYwtLkgsJj2zc=
github.com/microsoft/wmi v0.34.0/go.mod h1:uImvBuQss3NEnzU5bcwq0DsUh54seU3Sl//oBn62LDw=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -139,8 +139,8 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
Expand Down
102 changes: 1 addition & 101 deletions pkg/cim/wmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"runtime"

"github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
"github.com/microsoft/wmi/pkg/base/query"
wmierrors "github.com/microsoft/wmi/pkg/errors"
cim "github.com/microsoft/wmi/pkg/wmiinstance"
Expand Down Expand Up @@ -91,105 +90,6 @@ func QueryInstances(namespace string, query *query.WmiQuery) ([]*cim.WmiInstance
return instances, err
}

// TODO: fix the panic in microsoft/wmi library and remove this workaround
// Refer to https://github.com/microsoft/wmi/issues/167
func executeClassMethodParam(classInst *cim.WmiInstance, method *cim.WmiMethod, inParam, outParam cim.WmiMethodParamCollection) (result *cim.WmiMethodResult, err error) {
klog.V(6).Infof("[WMI] - Executing Method [%s]\n", method.Name)

iDispatchInstance := classInst.GetIDispatch()
if iDispatchInstance == nil {
return nil, wmierrors.Wrapf(wmierrors.InvalidInput, "InvalidInstance")
}
rawResult, err := iDispatchInstance.GetProperty("Methods_")
if err != nil {
return nil, err
}
defer rawResult.Clear()
// Retrieve the method
rawMethod, err := rawResult.ToIDispatch().CallMethod("Item", method.Name)
if err != nil {
return nil, err
}
defer rawMethod.Clear()

addInParam := func(inparamVariant *ole.VARIANT, paramName string, paramValue interface{}) error {
rawProperties, err := inparamVariant.ToIDispatch().GetProperty("Properties_")
if err != nil {
return err
}
defer rawProperties.Clear()
rawProperty, err := rawProperties.ToIDispatch().CallMethod("Item", paramName)
if err != nil {
return err
}
defer rawProperty.Clear()

p, err := rawProperty.ToIDispatch().PutProperty("Value", paramValue)
if err != nil {
return err
}
defer p.Clear()
return nil
}

params := []interface{}{method.Name}
if len(inParam) > 0 {
inparamsRaw, err := rawMethod.ToIDispatch().GetProperty("InParameters")
if err != nil {
return nil, err
}
defer inparamsRaw.Clear()

inparams, err := oleutil.CallMethod(inparamsRaw.ToIDispatch(), "SpawnInstance_")
if err != nil {
return nil, err
}
defer inparams.Clear()

for _, inp := range inParam {
addInParam(inparams, inp.Name, inp.Value)
}

params = append(params, inparams)
}

result = &cim.WmiMethodResult{
OutMethodParams: map[string]*cim.WmiMethodParam{},
}
outparams, err := classInst.GetIDispatch().CallMethod("ExecMethod_", params...)
if err != nil {
return
}
defer outparams.Clear()
returnRaw, err := outparams.ToIDispatch().GetProperty("ReturnValue")
if err != nil {
return
}
defer returnRaw.Clear()
if returnRaw.Value() != nil {
result.ReturnValue = returnRaw.Value().(int32)
klog.V(6).Infof("[WMI] - Return [%d] ", result.ReturnValue)
}

for _, outp := range outParam {
returnRawIn, err1 := outparams.ToIDispatch().GetProperty(outp.Name)
if err1 != nil {
err = err1
return
}
defer returnRawIn.Clear()

value, err1 := cim.GetVariantValue(returnRawIn)
if err1 != nil {
err = err1
return
}

result.OutMethodParams[outp.Name] = cim.NewWmiMethodParam(outp.Name, value)
}
return
}

// InvokeCimMethod calls a static method on a specific WMI class with given input parameters,
// returning the method's return value, output parameters, and any error encountered.
func InvokeCimMethod(namespace, class, methodName string, inputParameters map[string]interface{}) (int, map[string]interface{}, error) {
Expand Down Expand Up @@ -225,7 +125,7 @@ func InvokeCimMethod(namespace, class, methodName string, inputParameters map[st

var outParam cim.WmiMethodParamCollection
var result *cim.WmiMethodResult
result, err = executeClassMethodParam(classInst, method, inParam, outParam)
result, err = method.Execute(inParam, outParam)
if err != nil {
return -1, nil, err
}
Expand Down
4 changes: 0 additions & 4 deletions scripts/run-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ pkgdir=${GOPATH}/src/github.com/kubernetes-csi/csi-proxy
source $pkgdir/scripts/utils.sh

main() {
# TODO: remove go version pin as part of https://github.com/kubernetes-csi/csi-proxy/issues/361
wget -q https://go.dev/dl/go1.22.12.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.12.linux-amd64.tar.gz

compile_csi_proxy
compile_csi_proxy_integration_tests
sync_csi_proxy
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions vendor/github.com/microsoft/wmi/pkg/errors/errors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 24 additions & 15 deletions vendor/github.com/microsoft/wmi/pkg/wmiinstance/WmiMethod.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading