diff --git a/probe/kubernetes/persistentvolume.go b/probe/kubernetes/persistentvolume.go index 1afd5c1665..fba53db0ff 100644 --- a/probe/kubernetes/persistentvolume.go +++ b/probe/kubernetes/persistentvolume.go @@ -7,6 +7,11 @@ 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 @@ -14,6 +19,8 @@ type PersistentVolume interface { GetAccessMode() string GetVolume() string GetStorageDriver() string + GetCASType() string + GetBDCName() string } // persistentVolume represents kubernetes persistent volume @@ -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{ @@ -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) diff --git a/probe/kubernetes/reporter.go b/probe/kubernetes/reporter.go index 1923f95c52..74bba7e398 100644 --- a/probe/kubernetes/reporter.go +++ b/probe/kubernetes/reporter.go @@ -70,6 +70,8 @@ const ( BlockDeviceList = report.KubernetesBlockDeviceList Path = report.KubernetesPath BlockDeviceName = report.KubernetesBlockDeviceName + BlockDeviceClaimName = report.KubernetesBlockDeviceClaimName + CASType = report.KubernetesCASType ) var ( diff --git a/render/persistentvolume.go b/render/persistentvolume.go index 4942373727..8d725a75a6 100644 --- a/render/persistentvolume.go +++ b/render/persistentvolume.go @@ -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 } diff --git a/report/map_keys.go b/report/map_keys.go index ab74a92ae4..7fb3c792a1 100644 --- a/report/map_keys.go +++ b/report/map_keys.go @@ -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" diff --git a/report/report.go b/report/report.go index 0015a1f26c..1e66b22931 100644 --- a/report/report.go +++ b/report/report.go @@ -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" @@ -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{},