Skip to content
This repository was archived by the owner on Jun 23, 2020. It is now read-only.

Use type parameter to dispatch custom logic #135

Closed

Conversation

harveylowndes
Copy link
Contributor

@harveylowndes harveylowndes commented Jun 12, 2018

Resolves #131

Changelog


- Use the 'type' parameter in a storage class to dispatch custom logic. By default the type is 'blockStorage'. If the type is 'blockStorage' then the 'fsType' parameter can also be set. By default this is ext4 but there is also support for ext3. The follow will create a block storage with file system type ext3:

kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
  name: oci
provisioner: oracle.com/oci
parameters:
  type: blockStorage
  fsType: ext3


@harveylowndes harveylowndes requested review from prydie and garthy June 12, 2018 14:43
@harveylowndes harveylowndes changed the title Storage class fsType parameter used to dispatch custom logic Use storage class fsType parameter to dispatch custom logic Jun 12, 2018

fsType := getFsTypeWithDefault(storageClass.Parameters["fsType"])

provisioner, ok := p.storageClassProvisioners[fsType]
Copy link
Contributor

Choose a reason for hiding this comment

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

As @garthy highlighted offline this breaks down when the following happens:

  • You Provision a volume with a given fsType
  • The volume provisioner is restarted
  • Delete is called before a Provision with the same fsType

return getFsTypeWithDefault(options.Parameters["fsType"])
}

func getFsTypeWithDefault(fsType string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would fold this into resolveFSType() and add a const along the lines of defaultFSType rather than hardcoding the constant here.

@@ -48,7 +48,9 @@ func TestResolveFSTypeWhenNotConfigured(t *testing.T) {

func TestResolveFSTypeWhenConfigured(t *testing.T) {
// test default fsType of 'ext3' is always returned when configured.
options := controller.VolumeOptions{Parameters: map[string]string{fsType: "ext3"}}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is preferable IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it was breaking for some reason on vsCode but worked out why and I will change back.

@@ -109,16 +109,29 @@ func mapAvailabilityDomainToFailureDomain(AD string) string {
return parts[len(parts)-1]
}

func resolveFSType(options controller.VolumeOptions) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to deduplicate this (pkg/provisioner/block/block.go)?

provisioner, ok := p.storageClassProvisioners[volume.Spec.StorageClassName]
storageClass, err := p.kubeClient.Storage().StorageClasses().Get(volume.Spec.StorageClassName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("Could not find storage class with the associated name '%s'", volume.Spec.StorageClassName)
Copy link
Contributor

Choose a reason for hiding this comment

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

 		return fmt.Errorf("could not find storage class %q", volume.Spec.StorageClassName) 

// Provision creates a storage asset and returns a PV object representing it.
func (p *OCIProvisioner) Provision(options controller.VolumeOptions) (*v1.PersistentVolume, error) {
availabilityDomainName, availabilityDomain, err := p.chooseAvailabilityDomain(options.PVC)
if err != nil {
return nil, err
}

provisioner, ok := p.storageClassProvisioners[*options.PVC.Spec.StorageClassName]
fsType := resolveFSType(options)
provisioner, ok := p.storageClassProvisioners[fsType]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still not overly happy with the overloading of fsType here. For one thing, it means creating multiple copies of the block storage provisioner in p.storageClassProvisioners unnecessarily. More importantly, it's not really what I'd expect as a user as throughout Kubernetes FSType is used to denote the filesystem type rather than the storage backend:

	// Filesystem type to mount.
	// Must be a filesystem type supported by the host operating system.
	// Ex. "ext4", "xfs", "ntfs". The default filesystem depends on FlexVolume script.
	// +optional
	FSType string

Source

I suggest we do something akin to what hyperkube does with symlinks in the flexvolume driver DaemonSet and then dispatch on provisioner in the StorageClass (i.e. oracle/oci-block-storage / oracle/oci-filesystem-storage).

@@ -87,8 +87,8 @@ func NewOCIProvisioner(kubeClient kubernetes.Interface, nodeInformer informersv1
nodeLister: nodeInformer.Lister(),
nodeListerSynced: nodeInformer.Informer().HasSynced,
storageClassProvisioners: map[string]plugin.ProvisionerPlugin{
"oci": blockProvisioner,
"oci-ext3": blockProvisioner,
Copy link
Member

Choose a reason for hiding this comment

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

Dispatching here should be done on some additional parameter e.g. type: block, type: nfs. This allows us to support FSS and Block. The block provisioner gets the volume options passed in so it can lookup the fsType directly without it being passed in.

Copy link
Contributor

Choose a reason for hiding this comment

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

We discussed this as an option yesterday. Personally I prefer the symlink approach but this to overloading fsType also.

@harveylowndes harveylowndes force-pushed the use-storageclass-fstype-to-dispatch-custom-logic branch from cf364ff to c392a06 Compare June 13, 2018 09:25
@harveylowndes harveylowndes changed the title Use storage class fsType parameter to dispatch custom logic Use type parameter to dispatch custom logic Jun 13, 2018
@harveylowndes harveylowndes force-pushed the use-storageclass-fstype-to-dispatch-custom-logic branch from c392a06 to 1fa59fa Compare June 13, 2018 09:35
@harveylowndes harveylowndes force-pushed the use-storageclass-fstype-to-dispatch-custom-logic branch from 1fa59fa to 18ecaa5 Compare June 13, 2018 12:44
@prydie prydie closed this Jun 13, 2018
@prydie prydie deleted the use-storageclass-fstype-to-dispatch-custom-logic branch September 17, 2018 13:48
rjtsdl pushed a commit to rjtsdl/oci-volume-provisioner that referenced this pull request Dec 20, 2018
* Add OCI proxy support
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants