forked from mayadata-io/scope
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List application pods under Persistent Volumes tab
* List application pods under Persistent Volumes tab This commit will add functionality to list all the application pods (having volume claim name) under persistent volumes tab (sub-topology of Pods) Signed-off-by: Akash4927 <[email protected]> * Add test case for application pods Signed-off-by: Akash4927 <[email protected]>
- Loading branch information
Showing
12 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/weaveworks/scope/report" | ||
|
||
apiv1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// ApplicationPod represents a Kubernetes pod | ||
type ApplicationPod interface { | ||
Meta | ||
GetApp(probeID string) report.Node | ||
RestartCount() uint | ||
} | ||
|
||
type applicationPod struct { | ||
*apiv1.Pod | ||
Meta | ||
parents report.Sets | ||
Node *apiv1.Node | ||
} | ||
|
||
func (p *applicationPod) State() string { | ||
return string(p.Status.Phase) | ||
} | ||
|
||
func (p *applicationPod) RestartCount() uint { | ||
count := uint(0) | ||
for _, cs := range p.Status.ContainerStatuses { | ||
count += uint(cs.RestartCount) | ||
} | ||
return count | ||
} | ||
|
||
func (p *applicationPod) EmptyMetaNode() report.Node { | ||
return report.MakeNode("") | ||
} | ||
|
||
func (p *applicationPod) AddParent(topology, id string) { | ||
p.parents = p.parents.Add(topology, report.MakeStringSet(id)) | ||
} | ||
|
||
// NewApp creates a new Pod | ||
func NewApp(p *apiv1.Pod) ApplicationPod { | ||
return &applicationPod{ | ||
Pod: p, | ||
Meta: meta{p.ObjectMeta}, | ||
parents: report.MakeSets(), | ||
} | ||
} | ||
|
||
func (p *applicationPod) GetApp(probeID string) report.Node { | ||
for _, v := range p.Spec.Volumes { | ||
if v.VolumeSource.PersistentVolumeClaim != nil { | ||
latests := map[string]string{ | ||
State: p.State(), | ||
IP: p.Status.PodIP, | ||
report.ControlProbeID: probeID, | ||
RestartCount: strconv.FormatUint(uint64(p.RestartCount()), 10), | ||
VolumeClaimName: v.VolumeSource.PersistentVolumeClaim.ClaimName, | ||
} | ||
|
||
if p.Pod.Spec.HostNetwork { | ||
latests[IsInHostNetwork] = "true" | ||
} | ||
|
||
return p.MetaNode(report.MakePodNodeID(p.UID())).WithLatests(latests). | ||
WithParents(p.parents) | ||
} | ||
} | ||
return p.EmptyMetaNode() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters