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

Build Node Driver Registrar for Windows nodes #47

Merged
merged 1 commit into from
Sep 5, 2019
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: 9 additions & 0 deletions Dockerfile.Windows
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to double check this is a must setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for the node driver registrar to be able to connect to the unix domain socket surfaced by the node CSI plugin (which also needs to be started as ContainerAdministrator).

ENTRYPOINT ["/csi-node-driver-registrar.exe"]
14 changes: 10 additions & 4 deletions cmd/csi-node-driver-registrar/node_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -48,16 +48,22 @@ 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)
if err != nil {
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.
Expand Down
27 changes: 27 additions & 0 deletions cmd/csi-node-driver-registrar/util_linux.go
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

@jingxu97 jingxu97 Aug 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why put it in a wrapper function? what is purpose of error here?

Copy link
Contributor Author

@ddebroy ddebroy Aug 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the wrapper function to able to allow platform dependent building (and essentially skip umask for Windows). The error is necessary in the Windows wrapper to clearly indicate that umask is not implemented on Windows. So we need the error returned for the _linux case as well to keep go happy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this wrapper function, do you still need to check OS in the code when using umask?

if runtime.GOOS == "linux" {
	// Default to only user accessible socket, caller can open up later if desired
	oldmask, _ = umask(0077)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed - not necessary. I added the above to make it doubly clear that umask is only intended for the Linux case. Someone looking at the code won't have to navigate to the umask wrapper to find out it is not implemented for Windows. I can skip the check above if that is recommended.

}
27 changes: 27 additions & 0 deletions cmd/csi-node-driver-registrar/util_windows.go
Original file line number Diff line number Diff line change
@@ -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")
}