mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
Add adjacencies for kubernetes storage components
- Kubernetes storage components such as PV and PVC are connected based on two parameters Persistent volume claim name and Persistent Volume name. - PVC contains the volume name which is, PV name itself. Hence, we can show edge for PVC and PV. - This will bring higher level visibility for kubernetes storage components. Signed-off-by: Satyam Zode <satyam.zode@openebs.io>
This commit is contained in:
@@ -10,10 +10,11 @@ import (
|
||||
|
||||
// These constants are keys used in node metadata
|
||||
const (
|
||||
Name = report.KubernetesName
|
||||
Namespace = report.KubernetesNamespace
|
||||
Created = report.KubernetesCreated
|
||||
LabelPrefix = "kubernetes_labels_"
|
||||
Name = report.KubernetesName
|
||||
Namespace = report.KubernetesNamespace
|
||||
Created = report.KubernetesCreated
|
||||
LabelPrefix = "kubernetes_labels_"
|
||||
VolumeClaimName = report.KubernetesVolumeClaim
|
||||
)
|
||||
|
||||
// Meta represents a metadata information about a Kubernetes object
|
||||
|
||||
@@ -8,11 +8,17 @@ import (
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
)
|
||||
|
||||
const (
|
||||
// BetaStorageClassAnnotation is the annotation for default storage class
|
||||
BetaStorageClassAnnotation = "volume.beta.kubernetes.io/storage-class"
|
||||
)
|
||||
|
||||
// PersistentVolumeClaim represents kubernetes PVC interface
|
||||
type PersistentVolumeClaim interface {
|
||||
Meta
|
||||
Selector() (labels.Selector, error)
|
||||
GetNode(probeID string) report.Node
|
||||
GetStorageClass() string
|
||||
}
|
||||
|
||||
// persistentVolumeClaim represents kubernetes Persistent Volume Claims
|
||||
@@ -26,15 +32,30 @@ func NewPersistentVolumeClaim(p *apiv1.PersistentVolumeClaim) PersistentVolumeCl
|
||||
return &persistentVolumeClaim{PersistentVolumeClaim: p, Meta: meta{p.ObjectMeta}}
|
||||
}
|
||||
|
||||
// GetStorageClass will fetch storage class name from given PVC
|
||||
func (p *persistentVolumeClaim) GetStorageClass() string {
|
||||
|
||||
// Use Beta storage class annotation first
|
||||
storageClassName := p.Annotations[BetaStorageClassAnnotation]
|
||||
if storageClassName != "" {
|
||||
return storageClassName
|
||||
}
|
||||
if p.Spec.StorageClassName != nil {
|
||||
storageClassName = *p.Spec.StorageClassName
|
||||
}
|
||||
|
||||
return storageClassName
|
||||
}
|
||||
|
||||
// GetNode returns Persistent Volume Claim as Node
|
||||
func (p *persistentVolumeClaim) GetNode(probeID string) report.Node {
|
||||
return p.MetaNode(report.MakePersistentVolumeClaimNodeID(p.UID())).WithLatests(map[string]string{
|
||||
report.ControlProbeID: probeID,
|
||||
NodeType: "Persistent Volume Claim",
|
||||
Namespace: p.GetNamespace(),
|
||||
Status: string(p.Status.Phase),
|
||||
VolumeName: p.Spec.VolumeName,
|
||||
AccessModes: string(p.Spec.AccessModes[0]),
|
||||
StorageClassName: p.GetStorageClass(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -75,12 +75,24 @@ func (p *pod) RestartCount() uint {
|
||||
return count
|
||||
}
|
||||
|
||||
func (p *pod) VolumeClaimName() string {
|
||||
claimName := ""
|
||||
for _, volume := range p.Spec.Volumes {
|
||||
if volume.VolumeSource.PersistentVolumeClaim != nil {
|
||||
claimName = volume.VolumeSource.PersistentVolumeClaim.ClaimName
|
||||
break
|
||||
}
|
||||
}
|
||||
return claimName
|
||||
}
|
||||
|
||||
func (p *pod) GetNode(probeID string) report.Node {
|
||||
latests := map[string]string{
|
||||
State: p.State(),
|
||||
IP: p.Status.PodIP,
|
||||
report.ControlProbeID: probeID,
|
||||
RestartCount: strconv.FormatUint(uint64(p.RestartCount()), 10),
|
||||
VolumeClaim: p.VolumeClaimName(),
|
||||
}
|
||||
|
||||
if p.Pod.Spec.HostNetwork {
|
||||
|
||||
Reference in New Issue
Block a user