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

Customizing host path for dynamically provisioned PersistentVolumes #6156

Merged
merged 2 commits into from
Feb 5, 2020
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ endif

# Set the version information for the Kubernetes servers
MINIKUBE_LDFLAGS := -X k8s.io/minikube/pkg/version.version=$(VERSION) -X k8s.io/minikube/pkg/version.isoVersion=$(ISO_VERSION) -X k8s.io/minikube/pkg/version.isoPath=$(ISO_BUCKET) -X k8s.io/minikube/pkg/version.gitCommitID=$(COMMIT)
PROVISIONER_LDFLAGS := "-X k8s.io/minikube/pkg/storage.version=$(STORAGE_PROVISIONER_TAG) -s -w"
PROVISIONER_LDFLAGS := "-X k8s.io/minikube/pkg/storage.version=$(STORAGE_PROVISIONER_TAG) -s -w -extldflags '-static'"

MINIKUBEFILES := ./cmd/minikube/
HYPERKIT_FILES := ./cmd/drivers/hyperkit
Expand Down
4 changes: 3 additions & 1 deletion cmd/storage-provisioner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"k8s.io/minikube/pkg/storage"
)

var pvDir = "/tmp/hostpath-provisioner"
nanikjava marked this conversation as resolved.
Show resolved Hide resolved

func main() {
// Glog requires that /tmp exists.
if err := os.MkdirAll("/tmp", 0755); err != nil {
Expand All @@ -33,7 +35,7 @@ func main() {
}
flag.Parse()

if err := storage.StartStorageProvisioner(); err != nil {
if err := storage.StartStorageProvisioner(pvDir); err != nil {
glog.Exit(err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ metadata:
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:persistent-volume-provisioner
name: cluster-admin
Copy link
Contributor Author

@nanikjava nanikjava Dec 23, 2019

Choose a reason for hiding this comment

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

This permission works fine but uncertain whether this is the correct one to use. Tried using the following

system:controller:expand-controller
system:controller:persistent-volume-binder

but it always complain permission issue either with persistentvolume/persistentvolumeclaims.

Tried defining customised RBAC inside storage-provisioner.yaml.tmp also does not work as it keep on thrown permission issue with persistentvolume(claims) and endpoints (using ClusterRole similar to defined here https://github.com/pragkent/aliyun-disk-provisioner/blob/38680a9607b0d33567be1bf0a7c57b26f0960549/deploy/rbac.yaml)

subjects:
- kind: ServiceAccount
name: storage-provisioner
Expand Down
2 changes: 1 addition & 1 deletion deploy/storage-provisioner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

FROM scratch
ARG arch
COPY out/storage-provisioner-${arch} storage-provisioner
COPY out/storage-provisioner-${arch} /storage-provisioner
CMD ["/storage-provisioner"]
13 changes: 6 additions & 7 deletions pkg/storage/storage_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type hostPathProvisioner struct {
}

// NewHostPathProvisioner creates a new Provisioner using host paths
func NewHostPathProvisioner() controller.Provisioner {
func NewHostPathProvisioner(pvDir string) controller.Provisioner {
return &hostPathProvisioner{
pvDir: "/tmp/hostpath-provisioner",
pvDir: pvDir,
identity: uuid.NewUUID(),
}
}
Expand All @@ -57,7 +57,7 @@ var _ controller.Provisioner = &hostPathProvisioner{}
// Provision creates a storage asset and returns a PV object representing it.
func (p *hostPathProvisioner) Provision(options controller.ProvisionOptions) (*core.PersistentVolume, error) {
glog.Infof("Provisioning volume %v", options)
path := path.Join(p.pvDir, options.PVName)
path := path.Join(p.pvDir, options.PVC.Name)
if err := os.MkdirAll(path, 0777); err != nil {
return nil, err
}
Expand Down Expand Up @@ -103,16 +103,15 @@ func (p *hostPathProvisioner) Delete(volume *core.PersistentVolume) error {
return &controller.IgnoredError{Reason: "identity annotation on PV does not match ours"}
}

path := path.Join(p.pvDir, volume.Name)
if err := os.RemoveAll(path); err != nil {
if err := os.RemoveAll(volume.Spec.PersistentVolumeSource.HostPath.Path); err != nil {
return errors.Wrap(err, "removing hostpath PV")
}

return nil
}

// StartStorageProvisioner will start storage provisioner server
func StartStorageProvisioner() error {
func StartStorageProvisioner(pvDir string) error {
glog.Infof("Initializing the Minikube storage provisioner...")
config, err := rest.InClusterConfig()
if err != nil {
Expand All @@ -132,7 +131,7 @@ func StartStorageProvisioner() error {

// Create the provisioner: it implements the Provisioner interface expected by
// the controller
hostPathProvisioner := NewHostPathProvisioner()
hostPathProvisioner := NewHostPathProvisioner(pvDir)

// Start the provision controller which will dynamically provision hostPath
// PVs
Expand Down