feat(zfspv) Add golint check to travis (#175)

Signed-off-by: vaniisgh <vanisingh@live.co.uk>
This commit is contained in:
vaniisgh 2020-07-07 18:21:02 +05:30 committed by GitHub
parent 8b7ad5cb45
commit 8bbf3d7d2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 321 additions and 266 deletions

View file

@ -36,10 +36,9 @@ type ZFSSnapshot struct {
Status SnapStatus `json:"status"`
}
// ZFSSnapshotList is a list of ZFSSnapshot resources
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=zfssnapshots
// ZFSSnapshotList is a list of ZFSSnapshot resources
type ZFSSnapshotList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
@ -47,6 +46,7 @@ type ZFSSnapshotList struct {
Items []ZFSSnapshot `json:"items"`
}
// SnapStatus string that reflects if the snapshot was cretaed successfully
type SnapStatus struct {
State string `json:"state,omitempty"`
}

View file

@ -63,10 +63,9 @@ type MountInfo struct {
MountOptions []string `json:"mountOptions"`
}
// ZFSVolumeList is a list of ZFSVolume resources
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=zfsvolumes
// ZFSVolumeList is a list of ZFSVolume resources
type ZFSVolumeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
@ -202,6 +201,7 @@ type VolumeInfo struct {
Shared string `json:"shared,omitempty"`
}
// VolStatus string that specifies the current state of the volume provisioning request.
type VolStatus struct {
// State specifies the current state of the volume provisioning request.
// The state "Pending" means that the volume creation request has not

View file

@ -35,10 +35,9 @@ type ZFSSnapshot struct {
Status SnapStatus `json:"status"`
}
// ZFSSnapshotList is a list of ZFSSnapshot resources
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=zfssnapshots
// ZFSSnapshotList is a list of ZFSSnapshot resources
type ZFSSnapshotList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
@ -46,6 +45,7 @@ type ZFSSnapshotList struct {
Items []ZFSSnapshot `json:"items"`
}
// SnapStatus string that reflects if the snapshot was cretaed successfully
type SnapStatus struct {
State string `json:"state,omitempty"`
}

View file

@ -62,10 +62,9 @@ type MountInfo struct {
MountOptions []string `json:"mountOptions"`
}
// ZFSVolumeList is a list of ZFSVolume resources
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=zfsvolumes
// ZFSVolumeList is a list of ZFSVolume resources
type ZFSVolumeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
@ -194,6 +193,7 @@ type VolumeInfo struct {
FsType string `json:"fsType,omitempty"`
}
// VolStatus string that specifies the current state of the volume provisioning request.
type VolStatus struct {
// State specifies the current state of the volume provisioning request.
// The state "Pending" means that the volume creation request has not

View file

@ -26,15 +26,16 @@ type ClientsetGetter interface {
Get() (*kubernetes.Clientset, error)
}
type clientset struct{}
// ClientsetStruct is used to export a kuberneter Clientset
type ClientsetStruct struct{}
// Clientset returns a pointer to clientset struct
func Clientset() *clientset {
return &clientset{}
func Clientset() *ClientsetStruct {
return &ClientsetStruct{}
}
// Get returns a new instance of kubernetes clientset
func (c *clientset) Get() (*kubernetes.Clientset, error) {
func (c *ClientsetStruct) Get() (*kubernetes.Clientset, error) {
config, err := Config().Get()
if err != nil {
return nil, errors.Wrap(err, "failed to get kubernetes clientset")

View file

@ -17,10 +17,11 @@ limitations under the License.
package v1alpha1
import (
"strings"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
)
// ConfigMapGetter abstracts fetching of ConfigMap instance from kubernetes
@ -29,18 +30,19 @@ type ConfigMapGetter interface {
Get(options metav1.GetOptions) (*corev1.ConfigMap, error)
}
type configmap struct {
// Configmap is used to initialise a kubernetes Configmap struct
type Configmap struct {
namespace string // namespace where this configmap exists
name string // name of this configmap
}
// ConfigMap returns a new instance of configmap
func ConfigMap(namespace, name string) *configmap {
return &configmap{namespace: namespace, name: name}
func ConfigMap(namespace, name string) *Configmap {
return &Configmap{namespace: namespace, name: name}
}
// Get returns configmap instance from kubernetes cluster
func (c *configmap) Get(options metav1.GetOptions) (cm *corev1.ConfigMap, err error) {
func (c *Configmap) Get(options metav1.GetOptions) (cm *corev1.ConfigMap, err error) {
if len(strings.TrimSpace(c.name)) == 0 {
return nil, errors.Errorf("missing config map name: failed to get config map from namespace %s", c.namespace)
}

View file

@ -17,12 +17,13 @@ limitations under the License.
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// test if configmap implements ConfigMapGetter interface
var _ ConfigMapGetter = &configmap{}
var _ ConfigMapGetter = &Configmap{}
func TestConfigMapGet(t *testing.T) {
tests := map[string]struct {

View file

@ -26,16 +26,17 @@ type DynamicProvider interface {
Provide() (k8sdynamic.Interface, error)
}
type dynamic struct{}
//DynamicStruct is used to initialise a kuberenets dynamic interface
type DynamicStruct struct{}
// Dynamic returns a new instance of dynamic
func Dynamic() *dynamic {
return &dynamic{}
func Dynamic() *DynamicStruct {
return &DynamicStruct{}
}
// Provide provides a kubernetes dynamic client capable of invoking operations
// against kubernetes resources
func (d *dynamic) Provide() (k8sdynamic.Interface, error) {
func (d *DynamicStruct) Provide() (k8sdynamic.Interface, error) {
config, err := Config().Get()
if err != nil {
return nil, errors.Wrap(err, "failed to provide dynamic client")

View file

@ -21,7 +21,7 @@ import (
)
// test if dynamic implements DynamicProvider interface
var _ DynamicProvider = &dynamic{}
var _ DynamicProvider = &DynamicStruct{}
func TestDynamicProvider(t *testing.T) {
tests := map[string]struct {

View file

@ -31,15 +31,17 @@ type NamespaceGetter interface {
type NamespaceLister interface {
List(options metav1.ListOptions) (*corev1.NamespaceList, error)
}
type namespace struct{}
// NamespaceStruct is used to initialise kubernetes namespace instnaces
type NamespaceStruct struct{}
// Namespace returns a pointer to the namespace struct
func Namespace() *namespace {
return &namespace{}
func Namespace() *NamespaceStruct {
return &NamespaceStruct{}
}
// Get returns a namespace instance from kubernetes cluster
func (ns *namespace) Get(name string, options metav1.GetOptions) (*corev1.Namespace, error) {
func (ns *NamespaceStruct) Get(name string, options metav1.GetOptions) (*corev1.Namespace, error) {
cs, err := Clientset().Get()
if err != nil {
return nil, errors.Wrapf(err, "failed to get namespace: %s", name)
@ -48,7 +50,7 @@ func (ns *namespace) Get(name string, options metav1.GetOptions) (*corev1.Namesp
}
// List returns a slice of namespaces defined in a Kubernetes cluster
func (ns *namespace) List(options metav1.ListOptions) (*corev1.NamespaceList, error) {
func (ns *NamespaceStruct) List(options metav1.ListOptions) (*corev1.NamespaceList, error) {
cs, err := Clientset().Get()
if err != nil {
return nil, errors.Wrapf(err, "failed to get namespaces")

View file

@ -31,30 +31,31 @@ type NodeGetter interface {
type NodeLister interface {
List(options metav1.ListOptions) (*corev1.NodeList, error)
}
type node struct{}
func Node() *node {
return &node{}
//NodeStruct returns a struct used to instantiate a kubernetes Node
type NodeStruct struct{}
// Node returnd a pointer to the node struct
func Node() *NodeStruct {
return &NodeStruct{}
}
// Get returns a node instance from kubernetes cluster
func (n *node) Get(name string, options metav1.GetOptions) (*corev1.Node, error) {
func (n *NodeStruct) Get(name string, options metav1.GetOptions) (*corev1.Node, error) {
cs, err := Clientset().Get()
if err != nil {
return nil, errors.Wrapf(err, "failed to get node: %s", name)
} else {
return cs.CoreV1().Nodes().Get(name, options)
}
return cs.CoreV1().Nodes().Get(name, options)
}
// List returns a slice of Nodes registered in a Kubernetes cluster
func (n *node) List(options metav1.ListOptions) (*corev1.NodeList, error) {
func (n *NodeStruct) List(options metav1.ListOptions) (*corev1.NodeList, error) {
cs, err := Clientset().Get()
if err != nil {
return nil, errors.Wrapf(err, "failed to get nodes")
} else {
return cs.CoreV1().Nodes().List(options)
}
return cs.CoreV1().Nodes().List(options)
}
// NumberOfNodes returns the number of nodes registered in a Kubernetes cluster
@ -63,9 +64,8 @@ func NumberOfNodes() (int, error) {
nodes, err := n.List(metav1.ListOptions{})
if err != nil {
return 0, errors.Wrapf(err, "failed to get the number of nodes")
} else {
return len(nodes.Items), nil
}
return len(nodes.Items), nil
}
// GetNode returns a node instance from kubernetes cluster
@ -74,9 +74,8 @@ func GetNode(name string) (*corev1.Node, error) {
node, err := n.Get(name, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrapf(err, "failed to get node")
} else {
return node, nil
}
return node, nil
}
// ListNodes returns list of node instance from kubernetes cluster
@ -85,9 +84,8 @@ func ListNodes(options metav1.ListOptions) (*corev1.NodeList, error) {
nodelist, err := n.List(options)
if err != nil {
return nil, errors.Wrapf(err, "failed to list node")
} else {
return nodelist, nil
}
return nodelist, nil
}
// GetOSAndKernelVersion gets us the OS,Kernel version

View file

@ -66,23 +66,24 @@ type ResourceDeleter interface {
Delete(obj *unstructured.Unstructured, subresources ...string) error
}
type resource struct {
// ResourceStruct is used to abstract a kubernetes struct
type ResourceStruct struct {
gvr schema.GroupVersionResource // identify a resource
namespace string // namespace where this resource is to be operated at
}
// String implements Stringer interface
func (r *resource) String() string {
func (r *ResourceStruct) String() string {
return r.gvr.String()
}
// Resource returns a new resource instance
func Resource(gvr schema.GroupVersionResource, namespace string) *resource {
return &resource{gvr: gvr, namespace: namespace}
func Resource(gvr schema.GroupVersionResource, namespace string) *ResourceStruct {
return &ResourceStruct{gvr: gvr, namespace: namespace}
}
// Create creates a new resource in kubernetes cluster
func (r *resource) Create(obj *unstructured.Unstructured, subresources ...string) (u *unstructured.Unstructured, err error) {
func (r *ResourceStruct) Create(obj *unstructured.Unstructured, subresources ...string) (u *unstructured.Unstructured, err error) {
if obj == nil {
err = errors.Errorf("nil resource instance: failed to create resource '%s' at '%s'", r.gvr, r.namespace)
return
@ -101,7 +102,7 @@ func (r *resource) Create(obj *unstructured.Unstructured, subresources ...string
}
// Delete deletes a existing resource in kubernetes cluster
func (r *resource) Delete(obj *unstructured.Unstructured, subresources ...string) error {
func (r *ResourceStruct) Delete(obj *unstructured.Unstructured, subresources ...string) error {
if obj == nil {
return errors.Errorf("nil resource instance: failed to delete resource '%s' at '%s'", r.gvr, r.namespace)
}
@ -117,7 +118,7 @@ func (r *resource) Delete(obj *unstructured.Unstructured, subresources ...string
}
// Get returns a specific resource from kubernetes cluster
func (r *resource) Get(name string, opts metav1.GetOptions, subresources ...string) (u *unstructured.Unstructured, err error) {
func (r *ResourceStruct) Get(name string, opts metav1.GetOptions, subresources ...string) (u *unstructured.Unstructured, err error) {
if len(strings.TrimSpace(name)) == 0 {
err = errors.Errorf("missing resource name: failed to get resource '%s' at '%s'", r.gvr, r.namespace)
return
@ -136,7 +137,7 @@ func (r *resource) Get(name string, opts metav1.GetOptions, subresources ...stri
}
// Update updates the resource at kubernetes cluster
func (r *resource) Update(oldobj, newobj *unstructured.Unstructured, subresources ...string) (u *unstructured.Unstructured, err error) {
func (r *ResourceStruct) Update(oldobj, newobj *unstructured.Unstructured, subresources ...string) (u *unstructured.Unstructured, err error) {
if oldobj == nil {
err = errors.Errorf("nil old resource instance: failed to update resource '%s' at '%s'", r.gvr, r.namespace)
return
@ -163,7 +164,7 @@ func (r *resource) Update(oldobj, newobj *unstructured.Unstructured, subresource
}
// List returns a list of specific resource at kubernetes cluster
func (r *resource) List(opts metav1.ListOptions) (u *unstructured.UnstructuredList, err error) {
func (r *ResourceStruct) List(opts metav1.ListOptions) (u *unstructured.UnstructuredList, err error) {
dynamic, err := Dynamic().Provide()
if err != nil {
err = errors.Wrapf(err, "failed to list resource '%s' at '%s'", r.gvr, r.namespace)
@ -181,7 +182,7 @@ func (r *resource) List(opts metav1.ListOptions) (u *unstructured.UnstructuredLi
// create or update a given resource. It does so by implementing
// ResourceApplier interface
type ResourceCreateOrUpdater struct {
*resource
*ResourceStruct
// Various executors required to perform Apply
// This is how this instance decouples its dependencies
@ -222,10 +223,10 @@ func NewResourceCreateOrUpdater(
) *ResourceCreateOrUpdater {
resource := Resource(gvr, namespace)
t := &ResourceCreateOrUpdater{
resource: resource,
Getter: resource,
Creator: resource,
Updater: resource,
ResourceStruct: resource,
Getter: resource,
Creator: resource,
Updater: resource,
}
for _, o := range options {
o(t)
@ -235,10 +236,10 @@ func NewResourceCreateOrUpdater(
// String implements Stringer interface
func (r *ResourceCreateOrUpdater) String() string {
if r.resource == nil {
if r.ResourceStruct == nil {
return fmt.Sprint("ResourceCreateOrUpdater")
}
return fmt.Sprintf("ResourceCreateOrUpdater %s", r.resource)
return fmt.Sprintf("ResourceCreateOrUpdater %s", r.ResourceStruct)
}
// Apply applies a resource to the kubernetes cluster. In other words, it
@ -285,7 +286,7 @@ type ResourceDeleteOptions struct {
// Delete is a resource that is suitable to be executed as a Delete operation
type Delete struct {
*resource
*ResourceStruct
options ResourceDeleteOptions
}
@ -293,7 +294,7 @@ type Delete struct {
func DeleteResource(gvr schema.GroupVersionResource, namespace string) *Delete {
resource := Resource(gvr, namespace)
options := ResourceDeleteOptions{Deleter: resource}
return &Delete{resource: resource, options: options}
return &Delete{ResourceStruct: resource, options: options}
}
// Delete deletes a resource from a kubernetes cluster
@ -313,7 +314,7 @@ type ResourceListOptions struct {
// List is a resource resource that is suitable to be executed as a List operation
type List struct {
*resource
*ResourceStruct
options ResourceListOptions
}
@ -321,7 +322,7 @@ type List struct {
func ListResource(gvr schema.GroupVersionResource, namespace string) *List {
resource := Resource(gvr, namespace)
options := ResourceListOptions{Lister: resource}
return &List{resource: resource, options: options}
return &List{ResourceStruct: resource, options: options}
}
// List lists a resource from a kubernetes cluster
@ -340,7 +341,7 @@ type ResourceGetOptions struct {
// Get is resource that is suitable to be executed as Get operation
type Get struct {
*resource
*ResourceStruct
options ResourceGetOptions
}
@ -348,7 +349,7 @@ type Get struct {
func GetResource(gvr schema.GroupVersionResource, namespace string) *Get {
resource := Resource(gvr, namespace)
options := ResourceGetOptions{Getter: resource}
return &Get{resource: resource, options: options}
return &Get{ResourceStruct: resource, options: options}
}
// Get gets a resource from a kubernetes cluster

View file

@ -19,13 +19,13 @@ limitations under the License.
package v1alpha1
// verify if resource struct is an implementation of ResourceGetter
var _ ResourceGetter = &resource{}
var _ ResourceGetter = &ResourceStruct{}
// verify if resource struct is an implementation of ResourceCreator
var _ ResourceCreator = &resource{}
var _ ResourceCreator = &ResourceStruct{}
// verify if resource struct is an implementation of ResourceUpdater
var _ ResourceUpdater = &resource{}
var _ ResourceUpdater = &ResourceStruct{}
// verify if createOrUpdate struct is an implementation of ResourceApplier
var _ ResourceApplier = &ResourceCreateOrUpdater{}

View file

@ -20,10 +20,11 @@ import (
"strings"
)
// Coerce the map's keys to lower case, which only works when unicode char is in
// ASCII subset. May overwrite key-value pairs on different permutations of key
// case as in Key and key. DON'T force values to the lower case unconditionally,
// because values for keys such as mountpoint or keylocation are case-sensitive.
// GetCaseInsensitiveMap coercs the map's keys to lower case, which only works
// when unicode char is in ASCII subset. May overwrite key-value pairs on
// different permutations of key case as in Key and key. DON'T force values to the
// lower case unconditionally, because values for keys such as mountpoint or
// keylocation are case-sensitive.
// Note that although keys such as 'comPREssion' are accepted and processed,
// even if they are technically invalid, updates to rectify such typing will be
// prohibited as a forbidden update.
@ -36,7 +37,8 @@ func GetCaseInsensitiveMap(dict *map[string]string) map[string]string {
return insensitiveDict
}
// special case of GetCaseInsensitiveMap looking up one key-value pair only
// GetInsensitiveParameter handles special case ofGetCaseInsensitiveMap looking up one
// key-value pair only
func GetInsensitiveParameter(dict *map[string]string, key string) string {
insensitiveDict := GetCaseInsensitiveMap(dict)
return insensitiveDict[strings.ToLower(key)]

View file

@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package usage
const (
@ -34,12 +35,14 @@ const (
// RunningStatus status is running
RunningStatus string = "running"
// Event labels
EventLabelNode string = "nodes"
// EventLabelNode holds the string label "nodes"
EventLabelNode string = "nodes"
// EventLabelCapacity holds the string label "capacity"
EventLabelCapacity string = "capacity"
// Replica Event replication
Replica string = "replica:"
Replica string = "replica:"
// DefaultReplicaCount holds the replica count string
DefaultReplicaCount string = "replica:1"
// DefaultCASType Event application name constant for volume event

View file

@ -33,9 +33,9 @@ var (
installerType = "OPENEBS_IO_INSTALLER_TYPE"
)
// versionSet is a struct which stores (sort of) fixed information about a
// VersionSet is a struct which stores (sort of) fixed information about a
// k8s environment
type versionSet struct {
type VersionSet struct {
id string // OPENEBS_IO_USAGE_UUID
k8sVersion string // OPENEBS_IO_K8S_VERSION
k8sArch string // OPENEBS_IO_K8S_ARCH
@ -45,13 +45,13 @@ type versionSet struct {
}
// NewVersion returns a new versionSet struct
func NewVersion() *versionSet {
return &versionSet{}
func NewVersion() *VersionSet {
return &VersionSet{}
}
// fetchAndSetVersion consumes the Kubernetes API to get environment constants
// and returns a versionSet struct
func (v *versionSet) fetchAndSetVersion() error {
func (v *VersionSet) fetchAndSetVersion() error {
var err error
v.id, err = getUUIDbyNS("default")
if err != nil {
@ -79,7 +79,7 @@ func (v *versionSet) fetchAndSetVersion() error {
}
// getVersion is a wrapper over fetchAndSetVersion
func (v *versionSet) getVersion(override bool) error {
func (v *VersionSet) getVersion(override bool) error {
// If ENVs aren't set or the override is true, fetch the required
// values from the K8s APIserver
if _, present := env.Lookup(openEBSversion); !present || override {

View file

@ -17,8 +17,9 @@ limitations under the License.
package zfs
import (
"k8s.io/klog"
"os/exec"
"k8s.io/klog"
)
/*
@ -27,8 +28,8 @@ import (
* volume refers to the same block because of the way ZFS clone works, it will
* also have the same UUID.
*/
func btrfsGenerateUuid(volume string) error {
device := ZFS_DEVPATH + volume
func btrfsGenerateUUID(volume string) error {
device := ZFSDevPath + volume
// for mounting the cloned volume for btrfs, a new UUID has to be generated
cmd := exec.Command("btrfstune", "-f", "-u", device)

View file

@ -183,7 +183,7 @@ func MountZvol(vol *apis.ZFSVolume, mount *apis.MountInfo) error {
return err
}
devicePath := ZFS_DEVPATH + volume
devicePath := ZFSDevPath + volume
err = FormatAndMountZvol(devicePath, mount)
if err != nil {
@ -244,7 +244,7 @@ func MountDataset(vol *apis.ZFSVolume, mount *apis.MountInfo) error {
// MountFilesystem mounts the disk to the specified path
func MountFilesystem(vol *apis.ZFSVolume, mount *apis.MountInfo) error {
switch vol.Spec.VolumeType {
case VOLTYPE_DATASET:
case VolTypeDataset:
return MountDataset(vol, mount)
default:
return MountZvol(vol, mount)
@ -254,7 +254,7 @@ func MountFilesystem(vol *apis.ZFSVolume, mount *apis.MountInfo) error {
// MountBlock mounts the block disk to the specified path
func MountBlock(vol *apis.ZFSVolume, mountinfo *apis.MountInfo) error {
target := mountinfo.MountPath
devicePath := ZFS_DEVPATH + vol.Spec.PoolName + "/" + vol.Name
devicePath := ZFSDevPath + vol.Spec.PoolName + "/" + vol.Name
mountopt := []string{"bind"}
mounter := &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: mount.NewOsExec()}

View file

@ -26,7 +26,7 @@ import (
)
func xfsTempMount(volume string) error {
device := ZFS_DEVPATH + volume
device := ZFSDevPath + volume
pvol := strings.Split(volume, "/")
// create a temporary directory to mount the xfs file system
@ -70,8 +70,8 @@ func xfsTempMount(volume string) error {
* There might be something there in the xfs log, we have to clear them
* so that filesystem is clean and we can generate the UUID for it.
*/
func xfsGenerateUuid(volume string) error {
device := ZFS_DEVPATH + volume
func xfsGenerateUUID(volume string) error {
device := ZFSDevPath + volume
// temporary mount the volume with nouuid to replay the logs
err := xfsTempMount(volume)

View file

@ -28,8 +28,8 @@ import (
// zfs related constants
const (
ZFS_DEVPATH = "/dev/zvol/"
FSTYPE_ZFS = "zfs"
ZFSDevPath = "/dev/zvol/"
FSTypeZFS = "zfs"
)
// zfs command related constants
@ -46,14 +46,14 @@ const (
// constants to define volume type
const (
VOLTYPE_DATASET = "DATASET"
VOLTYPE_ZVOL = "ZVOL"
VolTypeDataset = "DATASET"
VolTypeZVol = "ZVOL"
)
// PropertyChanged return whether volume property is changed
func PropertyChanged(oldVol *apis.ZFSVolume, newVol *apis.ZFSVolume) bool {
if oldVol.Spec.VolumeType == VOLTYPE_DATASET &&
newVol.Spec.VolumeType == VOLTYPE_DATASET &&
if oldVol.Spec.VolumeType == VolTypeDataset &&
newVol.Spec.VolumeType == VolTypeDataset &&
oldVol.Spec.RecordSize != newVol.Spec.RecordSize {
return true
}
@ -70,10 +70,10 @@ func GetVolumeType(fstype string) string {
* otherwise a zvol will be created
*/
switch fstype {
case FSTYPE_ZFS:
return VOLTYPE_DATASET
case FSTypeZFS:
return VolTypeDataset
default:
return VOLTYPE_ZVOL
return VolTypeZVol
}
}
@ -129,7 +129,7 @@ func buildCloneCreateArgs(vol *apis.ZFSVolume) []string {
ZFSVolArg = append(ZFSVolArg, ZFSCloneArg)
if vol.Spec.VolumeType == VOLTYPE_DATASET {
if vol.Spec.VolumeType == VolTypeDataset {
if len(vol.Spec.Capacity) != 0 {
quotaProperty := "quota=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, "-o", quotaProperty)
@ -251,7 +251,7 @@ func buildVolumeSetArgs(vol *apis.ZFSVolume) []string {
ZFSVolArg = append(ZFSVolArg, ZFSSetArg)
if vol.Spec.VolumeType == VOLTYPE_DATASET &&
if vol.Spec.VolumeType == VolTypeDataset &&
len(vol.Spec.RecordSize) != 0 {
recordsizeProperty := "recordsize=" + vol.Spec.RecordSize
ZFSVolArg = append(ZFSVolArg, recordsizeProperty)
@ -279,7 +279,7 @@ func buildVolumeResizeArgs(vol *apis.ZFSVolume) []string {
ZFSVolArg = append(ZFSVolArg, ZFSSetArg)
if vol.Spec.VolumeType == VOLTYPE_DATASET {
if vol.Spec.VolumeType == VolTypeDataset {
quotaProperty := "quota=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, quotaProperty)
} else {
@ -320,7 +320,7 @@ func CreateVolume(vol *apis.ZFSVolume) error {
if err := getVolume(volume); err != nil {
var args []string
if vol.Spec.VolumeType == VOLTYPE_DATASET {
if vol.Spec.VolumeType == VolTypeDataset {
args = buildDatasetCreateArgs(vol)
} else {
args = buildZvolCreateArgs(vol)
@ -365,10 +365,16 @@ func CreateClone(vol *apis.ZFSVolume) error {
}
if vol.Spec.FsType == "xfs" {
return xfsGenerateUuid(volume)
return xfsGenerateUUID(volume)
}
if vol.Spec.FsType == "btrfs" {
return btrfsGenerateUuid(volume)
return btrfsGenerateUUID(volume)
}
if vol.Spec.FsType == "btrfs" {
return btrfsGenerateUUID(volume)
}
if vol.Spec.FsType == "btrfs" {
return btrfsGenerateUUID(volume)
}
return nil
}
@ -428,7 +434,7 @@ func MountZFSDataset(vol *apis.ZFSVolume, mountpath string) error {
// SetDatasetLegacyMount sets the dataset mountpoint to legacy if not set
func SetDatasetLegacyMount(vol *apis.ZFSVolume) error {
if vol.Spec.VolumeType != VOLTYPE_DATASET {
if vol.Spec.VolumeType != VolTypeDataset {
return nil
}
@ -471,7 +477,7 @@ func SetVolumeProp(vol *apis.ZFSVolume) error {
if len(vol.Spec.Compression) == 0 &&
len(vol.Spec.Dedup) == 0 &&
(vol.Spec.VolumeType != VOLTYPE_DATASET ||
(vol.Spec.VolumeType != VolTypeDataset ||
len(vol.Spec.RecordSize) == 0) {
//nothing to set, just return
return nil
@ -587,11 +593,11 @@ func DestroySnapshot(snap *apis.ZFSSnapshot) error {
// GetVolumeDevPath returns devpath for the given volume
func GetVolumeDevPath(vol *apis.ZFSVolume) (string, error) {
volume := vol.Spec.PoolName + "/" + vol.Name
if vol.Spec.VolumeType == VOLTYPE_DATASET {
if vol.Spec.VolumeType == VolTypeDataset {
return volume, nil
}
devicePath := ZFS_DEVPATH + volume
devicePath := ZFSDevPath + volume
// evaluate the symlink to get the dev path for zvol
dev, err := filepath.EvalSymlinks(devicePath)