Skip to content

Commit

Permalink
Merge pull request #6156 from nanikjava/f-fix-5144
Browse files Browse the repository at this point in the history
Customizing host path for dynamically provisioned PersistentVolumes
  • Loading branch information
tstromberg authored Feb 5, 2020
2 parents 6d4ee3a + 0d29a2a commit 88693f2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
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"

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
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

0 comments on commit 88693f2

Please sign in to comment.