Skip to content

Commit

Permalink
Add adjacency between pv and bdc
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Srivastava <akashsrivastava4927@gmail.com>
  • Loading branch information
qiell committed Aug 6, 2019
1 parent f0fa228 commit 3f3a85d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
27 changes: 27 additions & 0 deletions probe/kubernetes/persistentvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import (
apiv1 "k8s.io/api/core/v1"
)

const (
casTypeLabel = "openebs.io/cas-type"
bdcAnnotation = "local.openebs.io/blockdeviceclaim"
)

// PersistentVolume represent kubernetes PersistentVolume interface
type PersistentVolume interface {
Meta
GetNode(probeID string) report.Node
GetAccessMode() string
GetVolume() string
GetStorageDriver() string
GetCASType() string
GetBDCName() string
}

// persistentVolume represents kubernetes persistent volume
Expand Down Expand Up @@ -63,6 +70,18 @@ func (p *persistentVolume) GetStorageDriver() string {
return ""
}

func (p *persistentVolume) GetCASType() string {
casType := p.GetLabels()[casTypeLabel]
if casType == "local-device" {
return "local-device"
}
return ""
}

func (p *persistentVolume) GetBDCName() string {
return p.GetAnnotations()[bdcAnnotation]
}

// GetNode returns Persistent Volume as Node
func (p *persistentVolume) GetNode(probeID string) report.Node {
latests := map[string]string{
Expand All @@ -78,6 +97,14 @@ func (p *persistentVolume) GetNode(probeID string) report.Node {
latests[StorageDriver] = p.GetStorageDriver()
}

if p.GetCASType() != "" {
latests[CASType] = p.GetCASType()
}

if p.GetBDCName() != "" {
latests[BlockDeviceClaimName] = p.GetBDCName()
}

return p.MetaNode(report.MakePersistentVolumeNodeID(p.UID())).
WithLatests(latests).
WithLatestActiveControls(Describe)
Expand Down
2 changes: 2 additions & 0 deletions probe/kubernetes/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const (
BlockDeviceList = report.KubernetesBlockDeviceList
Path = report.KubernetesPath
BlockDeviceName = report.KubernetesBlockDeviceName
BlockDeviceClaimName = report.KubernetesBlockDeviceClaimName
CASType = report.KubernetesCASType
)

var (
Expand Down
13 changes: 13 additions & 0 deletions render/persistentvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ func (v pvToControllerRenderer) Render(ctx context.Context, rpt report.Report) N
}
}

_, casOk := p.Latest.Lookup(kubernetes.CASType)
bdcNameFromPV, bdcOk := p.Latest.Lookup(kubernetes.BlockDeviceClaimName)
if casOk && bdcOk {
for bdcID, bdcNode := range rpt.BlockDeviceClaim.Nodes {
bdcName, _ := bdcNode.Latest.Lookup(kubernetes.Name)
if bdcName == bdcNameFromPV {
p.Adjacency = p.Adjacency.Add(bdcID)
p.Children = p.Children.Add(bdcNode)
break
}
}
}

if p.ID != "" {
nodes[pvNodeID] = p
}
Expand Down
2 changes: 2 additions & 0 deletions report/map_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ const (
KubernetesBlockDeviceList = "kubernetes_block_device_list"
KubernetesPath = "kubernetes_path"
KubernetesBlockDeviceName = "kubernetes_block_device_name"
KubernetesBlockDeviceClaimName = "kubernetes_block_device_claim_name"
KubernetesCASType = "kubernetes_cas_type"
// probe/awsecs
ECSCluster = "ecs_cluster"
ECSCreatedAt = "ecs_created_at"
Expand Down
37 changes: 19 additions & 18 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,24 @@ const (
BlockDeviceClaim = "block_device_claim"

// Shapes used for different nodes
Circle = "circle"
Triangle = "triangle"
Square = "square"
Pentagon = "pentagon"
Hexagon = "hexagon"
Heptagon = "heptagon"
Octagon = "octagon"
Cloud = "cloud"
Cylinder = "cylinder"
DottedCylinder = "dottedcylinder"
StorageSheet = "sheet"
Camera = "camera"
DottedTriangle = "dottedtriangle"
DottedSquare = "dottedsquare"
Controller = "controller"
Replica = "replica"
Rectangle = "rectangle"
Circle = "circle"
Triangle = "triangle"
Square = "square"
Pentagon = "pentagon"
Hexagon = "hexagon"
Heptagon = "heptagon"
Octagon = "octagon"
Cloud = "cloud"
Cylinder = "cylinder"
DottedCylinder = "dottedcylinder"
StorageSheet = "sheet"
Camera = "camera"
DottedTriangle = "dottedtriangle"
DottedSquare = "dottedsquare"
Controller = "controller"
Replica = "replica"
Rectangle = "rectangle"
DottedRectangle = "dottedrectangle"

// Used when counting the number of containers
ContainersKey = "containers"
Expand Down Expand Up @@ -374,7 +375,7 @@ func MakeReport() Report {
WithLabel("cStor Pool", "cStor Pool"),

BlockDeviceClaim: MakeTopology().
WithShape(Rectangle).
WithShape(DottedRectangle).
WithLabel("block device claim", "block device claims"),

DNS: DNSRecords{},
Expand Down

0 comments on commit 3f3a85d

Please sign in to comment.