Skip to content

Commit

Permalink
per-volume ephemeral mode + klog
Browse files Browse the repository at this point in the history
This removes the limitation that the driver can only be deployed for
one mode or the other. Instead the driver depends on the new
csi.storage.k8s.io/ephemeral
field (kubernetes/kubernetes#79624) in the
volume context to determine how it should behave in NodePublishVolume.

Supporting both modes in the same deployment makes it possible to test
ephemeral mode without having to change how the Prow jobs deploy the
driver, which is once as part of the cluster setup.

The --ephemeral parameter is deprecated and will trigger a warning
when still used. The shared code for handling deprecated flags uses
klog for logging, so as part of importing it, we also need to switch
over to more recent Kubernetes code which uses klog. For now, only
minimal changes to the source code are made by switching only to
Kubernetes 1.14.4. Going all the way up to Kubernetes 1.15.0 requires
further changes and should be done separately.
  • Loading branch information
pohly committed Jul 11, 2019
1 parent 7c724e3 commit 56e96ed
Show file tree
Hide file tree
Showing 454 changed files with 121,027 additions and 32,948 deletions.
104 changes: 62 additions & 42 deletions Gopkg.lock

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

12 changes: 4 additions & 8 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@

[[constraint]]
name = "github.com/container-storage-interface/spec"
version = "1.0.0"

[[constraint]]
branch = "master"
name = "github.com/golang/glog"
version = "=1.0.0"

[[override]]
revision = "5db89f0ca68677abc5eefce8f2a0a772c98ba52d"
Expand All @@ -50,14 +46,14 @@

[[constraint]]
name = "k8s.io/kubernetes"
version = "v1.12.0"
version = "=v1.14.4"

[[override]]
version = "kubernetes-1.12.0"
version = "kubernetes-1.14.4"
name = "k8s.io/api"

[[override]]
version = "kubernetes-1.12.0"
version = "kubernetes-1.14.4"
name = "k8s.io/apiserver"

[[override]]
Expand Down
7 changes: 5 additions & 2 deletions cmd/hostpathplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ import (
"path"

"github.com/kubernetes-csi/csi-driver-host-path/pkg/hostpath"
"github.com/kubernetes-csi/csi-lib-utils/deprecatedflags"
"k8s.io/klog"
)

func init() {
klog.InitFlags(nil)
flag.Set("logtostderr", "true")
}

var (
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
driverName = flag.String("drivername", "hostpath.csi.k8s.io", "name of the driver")
nodeID = flag.String("nodeid", "", "node id")
ephemeral = flag.Bool("ephemeral", false, "deploy in ephemeral mode")
_ = deprecatedflags.AddBool("ephemeral")
showVersion = flag.Bool("version", false, "Show version.")
// Set by the build process
version = ""
Expand All @@ -53,7 +56,7 @@ func main() {
}

func handle() {
driver, err := hostpath.NewHostPathDriver(*driverName, *nodeID, *endpoint, version, *ephemeral)
driver, err := hostpath.NewHostPathDriver(*driverName, *nodeID, *endpoint, version)
if err != nil {
fmt.Printf("Failed to initialize driver: %s", err.Error())
os.Exit(1)
Expand Down
7 changes: 7 additions & 0 deletions deploy/kubernetes-1.14/hostpath/csi-hostpath-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,10 @@ spec:
path: /var/lib/csi-hostpath-data/
type: DirectoryOrCreate
name: csi-data-dir
---
apiVersion: storage.k8s.io/v1beta1
kind: CSIDriver
metadata:
name: hostpath.csi.k8s.io
spec:
podInfoOnMount: true
9 changes: 3 additions & 6 deletions pkg/hostpath/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (

"github.com/golang/protobuf/ptypes"

"github.com/golang/glog"
"github.com/pborman/uuid"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/klog/glog"

"github.com/container-storage-interface/spec/lib/go/csi"
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler"
Expand All @@ -55,10 +55,7 @@ type controllerServer struct {
caps []*csi.ControllerServiceCapability
}

func NewControllerServer(ephemeral bool) *controllerServer {
if ephemeral {
return &controllerServer{caps: getControllerServiceCapabilities(nil)}
}
func NewControllerServer() *controllerServer {
return &controllerServer{
caps: getControllerServiceCapabilities(
[]csi.ControllerServiceCapability_RPC_Type{
Expand Down Expand Up @@ -167,7 +164,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}
}

vol, err := createHostpathVolume(volumeID, req.GetName(), capacity, requestedAccessType)
vol, err := createHostpathVolume(volumeID, req.GetName(), capacity, requestedAccessType, false /* ephemeral */)
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("failed to create volume: %s", err))
}
Expand Down
Loading

0 comments on commit 56e96ed

Please sign in to comment.