Skip to content

Commit 108b56d

Browse files
author
Harsh Vardhan
authored
Update cas-type name from local-hostpath to localpv-hostpath (#114)
* Update cas-type name from local-hostpath to localpv-hostpath Summary: dynamic-localpv-provisioner currently sets the label key for PVs as `openebs.io/cas-type=local-hostpath` * Set attachedNode correctly and fix-castype map Signed-off-by: Harsh Vardhan <[email protected]>
1 parent 2f6b060 commit 108b56d

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@ enable:
3030
- goimports
3131
- golint
3232
- misspell
33-

pkg/util/constant.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ const (
3737
LocalPvHostpathCasType = "localpv-hostpath"
3838
// LocalDeviceCasType cas type name
3939
LocalDeviceCasType = "localpv-device"
40-
// Local-hostpath cas type name
41-
LocalHostpathCasType = "local-hostpath"
40+
// LocalHostpathCasLabel cas-type label in dynamic-localpv-provisioner
41+
LocalHostpathCasLabel = "local-hostpath"
4242
// Healthy cstor volume status
4343
Healthy = "Healthy"
4444
// StorageKey key present in pvc status.capacity
@@ -102,11 +102,11 @@ var (
102102
// CasTypeAndComponentNameMap stores the component name of the corresponding cas type
103103
// NOTE: Not including ZFSLocalPV as it'd break existing code
104104
CasTypeAndComponentNameMap = map[string]string{
105-
CstorCasType: CStorCSIControllerLabelValue,
106-
JivaCasType: JivaCSIControllerLabelValue,
107-
LVMCasType: LVMLocalPVcsiControllerLabelValue,
108-
ZFSCasType: ZFSLocalPVcsiControllerLabelValue,
109-
LocalHostpathCasType: HostpathComponentNames,
105+
CstorCasType: CStorCSIControllerLabelValue,
106+
JivaCasType: JivaCSIControllerLabelValue,
107+
LVMCasType: LVMLocalPVcsiControllerLabelValue,
108+
ZFSCasType: ZFSLocalPVcsiControllerLabelValue,
109+
LocalPvHostpathCasType: HostpathComponentNames,
110110
}
111111
// ComponentNameToCasTypeMap is a reverse map of CasTypeAndComponentNameMap
112112
// NOTE: Not including ZFSLocalPV as it'd break existing code
@@ -115,7 +115,7 @@ var (
115115
JivaCSIControllerLabelValue: JivaCasType,
116116
LVMLocalPVcsiControllerLabelValue: LVMCasType,
117117
ZFSLocalPVcsiControllerLabelValue: ZFSCasType,
118-
HostpathComponentNames: LocalHostpathCasType,
118+
HostpathComponentNames: LocalPvHostpathCasType,
119119
}
120120
// ProvsionerAndCasTypeMap stores the cas type name of the corresponding provisioner
121121
ProvsionerAndCasTypeMap = map[string]string{

pkg/volume/local_hostpath.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,28 @@ RECLAIM POLICY : {{.ReclaimPolicy}}
4040
`
4141
)
4242

43-
// GetLocalHostpath returns a list of local-hostpath columes
43+
// GetLocalHostpath returns a list of localpv-hostpath columes
4444
func GetLocalHostpath(c *client.K8sClient, pvList *corev1.PersistentVolumeList, openebsNS string) ([]metav1.TableRow, error) {
4545
var rows []metav1.TableRow
4646
for _, pv := range pvList.Items {
4747
// Ignore all the other volumes that is not of cas-type local-hostpath
48-
if util.GetCasTypeFromPV(&pv) != util.LocalHostpathCasType {
48+
// dynamic-local-provisioner has this label for PVs openebs.io/cas-type=local-hostpath
49+
// this might be fixed later
50+
if util.GetCasTypeFromPV(&pv) != util.LocalHostpathCasLabel {
4951
continue
5052
}
51-
5253
name := pv.Name
5354
capacity := pv.Spec.Capacity.Storage()
5455
sc := pv.Spec.StorageClassName
5556
attached := pv.Status.Phase
56-
attachedNode, customStatus, ns, storageVersion := pv.Labels["nodeID"], "N/A", "N/A", "N/A"
57-
58-
deployment, err := c.GetDeploymentList("openebs.io/component-name=openebs-localpv-provisioner")
59-
if err == nil {
60-
storageVersion = deployment.Items[0].Labels["openebs.io/version"]
57+
attachedNode := pv.Spec.NodeAffinity.Required.NodeSelectorTerms[0].MatchExpressions[0].Values[0]
58+
var storageVersion, ns, customStatus string
59+
deploy, err := c.GetDeploymentList("openebs.io/component-name=openebs-localpv-provisioner")
60+
if err == nil && len(deploy.Items) == 1 {
61+
storageVersion = deploy.Items[0].Labels["openebs.io/version"]
62+
ns = deploy.Items[0].Namespace
63+
} else {
64+
storageVersion = "N/A"
6165
}
6266

6367
accessMode := pv.Spec.AccessModes[0]
@@ -70,8 +74,8 @@ func GetLocalHostpath(c *client.K8sClient, pvList *corev1.PersistentVolumeList,
7074
return rows, nil
7175
}
7276

73-
// DescribeLocalHostpathVolume describes a local-hostpath PersistentVolume
74-
func DescribeLocalHostpathVolume(c *client.K8sClient, vol *corev1.PersistentVolume) error {
77+
// DescribeLocalHostpathVolume describes a localpv-hostpath PersistentVolume
78+
func DescribeLocalHostpathVolume(_ *client.K8sClient, vol *corev1.PersistentVolume) error {
7579
// Get Local-volume Information
7680
localHostpathVolInfo := util.LocalHostPathVolInfo{
7781
VolumeInfo: util.VolumeInfo{
@@ -85,7 +89,7 @@ func DescribeLocalHostpathVolume(c *client.K8sClient, vol *corev1.PersistentVolu
8589
},
8690
Path: vol.Spec.PersistentVolumeSource.Local.Path,
8791
ReclaimPolicy: string(vol.Spec.PersistentVolumeReclaimPolicy),
88-
CasType: util.LocalHostpathCasType,
92+
CasType: util.LocalPvHostpathCasType,
8993
}
9094

9195
// Print the Volume information

pkg/volume/volume.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,22 @@ func CasList() []func(*client.K8sClient, *corev1.PersistentVolumeList, string) (
129129
func CasListMap() map[string]func(*client.K8sClient, *corev1.PersistentVolumeList, string) ([]metav1.TableRow, error) {
130130
// a good hack to implement immutable maps in Golang & also write tests for it
131131
return map[string]func(*client.K8sClient, *corev1.PersistentVolumeList, string) ([]metav1.TableRow, error){
132-
util.JivaCasType: GetJiva,
133-
util.CstorCasType: GetCStor,
134-
util.ZFSCasType: GetZFSLocalPVs,
135-
util.LVMCasType: GetLVMLocalPV,
136-
util.LocalHostpathCasType: GetLocalHostpath,
132+
util.JivaCasType: GetJiva,
133+
util.CstorCasType: GetCStor,
134+
util.ZFSCasType: GetZFSLocalPVs,
135+
util.LVMCasType: GetLVMLocalPV,
136+
util.LocalPvHostpathCasType: GetLocalHostpath,
137137
}
138138
}
139139

140140
// CasDescribeMap returns a map cas-types to functions for volume describing
141141
func CasDescribeMap() map[string]func(*client.K8sClient, *corev1.PersistentVolume) error {
142142
// a good hack to implement immutable maps in Golang & also write tests for it
143143
return map[string]func(*client.K8sClient, *corev1.PersistentVolume) error{
144-
util.JivaCasType: DescribeJivaVolume,
145-
util.CstorCasType: DescribeCstorVolume,
146-
util.ZFSCasType: DescribeZFSLocalPVs,
147-
util.LVMCasType: DescribeLVMLocalPVs,
148-
util.LocalHostpathCasType: DescribeLocalHostpathVolume,
144+
util.JivaCasType: DescribeJivaVolume,
145+
util.CstorCasType: DescribeCstorVolume,
146+
util.ZFSCasType: DescribeZFSLocalPVs,
147+
util.LVMCasType: DescribeLVMLocalPVs,
148+
util.LocalPvHostpathCasType: DescribeLocalHostpathVolume,
149149
}
150150
}

0 commit comments

Comments
 (0)