Customizing host path for dynamically provisioned PersistentVolumes
This fix contains few things: * Used k8s.gcr.io/debian-base-amd64:v2.0.0 as base image to build storage-provisioner * Modify RBAC permission used to cluster-admin * Build storage-provisioner as static binarypull/6156/head
parent
6c45d66d84
commit
9b455aafc4
2
Makefile
2
Makefile
|
@ -84,7 +84,7 @@ STORAGE_PROVISIONER_TAG := v1.8.1
|
|||
|
||||
# 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 := "$(MINIKUBE_LDFLAGS) -s -w"
|
||||
PROVISIONER_LDFLAGS := "$(MINIKUBE_LDFLAGS) -s -w -extldflags '-static'"
|
||||
|
||||
MINIKUBEFILES := ./cmd/minikube/
|
||||
HYPERKIT_FILES := ./cmd/drivers/hyperkit
|
||||
|
|
|
@ -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 {
|
||||
|
@ -33,7 +35,7 @@ func main() {
|
|||
}
|
||||
flag.Parse()
|
||||
|
||||
if err := storage.StartStorageProvisioner(); err != nil {
|
||||
if err := storage.StartStorageProvisioner(pvDir); err != nil {
|
||||
glog.Exit(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -13,5 +13,5 @@
|
|||
# limitations under the License.
|
||||
|
||||
FROM scratch
|
||||
COPY out/storage-provisioner storage-provisioner
|
||||
CMD ["/storage-provisioner"]
|
||||
COPY out/storage-provisioner /storage-provisioner
|
||||
CMD ["/storage-provisioner"]
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -103,8 +103,7 @@ 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")
|
||||
}
|
||||
|
||||
|
@ -112,7 +111,7 @@ func (p *hostPathProvisioner) Delete(volume *core.PersistentVolume) error {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue