diff --git a/Dockerfile.Windows b/Dockerfile.Windows new file mode 100644 index 00000000..5d2e4968 --- /dev/null +++ b/Dockerfile.Windows @@ -0,0 +1,9 @@ +FROM mcr.microsoft.com/windows/servercore:1809 as core + +FROM mcr.microsoft.com/windows/nanoserver:1809 +LABEL description="CSI Node driver registrar" + +COPY ./bin/csi-node-driver-registrar.exe /csi-node-driver-registrar.exe +COPY --from=core /Windows/System32/netapi32.dll /Windows/System32/netapi32.dll +USER ContainerAdministrator +ENTRYPOINT ["/csi-node-driver-registrar.exe"] diff --git a/cmd/csi-node-driver-registrar/node_register.go b/cmd/csi-node-driver-registrar/node_register.go index 0e96980b..47efd349 100644 --- a/cmd/csi-node-driver-registrar/node_register.go +++ b/cmd/csi-node-driver-registrar/node_register.go @@ -20,10 +20,10 @@ import ( "fmt" "net" "os" + "runtime" "google.golang.org/grpc" - "golang.org/x/sys/unix" "k8s.io/klog" registerapi "k8s.io/kubernetes/pkg/kubelet/apis/pluginregistration/v1alpha1" ) @@ -48,8 +48,12 @@ func nodeRegister( klog.Errorf("failed to stat the socket %s with error: %+v", socketPath, err) os.Exit(1) } - // Default to only user accessible socket, caller can open up later if desired - oldmask := unix.Umask(0077) + + var oldmask int + if runtime.GOOS == "linux" { + // Default to only user accessible socket, caller can open up later if desired + oldmask, _ = umask(0077) + } klog.Infof("Starting Registration Server at: %s\n", socketPath) lis, err := net.Listen("unix", socketPath) @@ -57,7 +61,9 @@ func nodeRegister( klog.Errorf("failed to listen on socket: %s with error: %+v", socketPath, err) os.Exit(1) } - unix.Umask(oldmask) + if runtime.GOOS == "linux" { + umask(oldmask) + } klog.Infof("Registration Server started at: %s\n", socketPath) grpcServer := grpc.NewServer() // Registers kubelet plugin watcher api. diff --git a/cmd/csi-node-driver-registrar/util_linux.go b/cmd/csi-node-driver-registrar/util_linux.go new file mode 100644 index 00000000..bab7d62f --- /dev/null +++ b/cmd/csi-node-driver-registrar/util_linux.go @@ -0,0 +1,27 @@ +// +build linux + +/* +Copyright 2019 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 main + +import ( + "golang.org/x/sys/unix" +) + +func umask(mask int) (int, error) { + return unix.Umask(mask), nil +} diff --git a/cmd/csi-node-driver-registrar/util_windows.go b/cmd/csi-node-driver-registrar/util_windows.go new file mode 100644 index 00000000..7a65a938 --- /dev/null +++ b/cmd/csi-node-driver-registrar/util_windows.go @@ -0,0 +1,27 @@ +// +build windows + +/* +Copyright 2019 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 main + +import ( + "errors" +) + +func umask(mask int) (int, error) { + return -1, errors.New("umask not supported in Windows") +}