-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: add support for deployments in oc status
- Loading branch information
Showing
14 changed files
with
670 additions
and
79 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package graphview | ||
|
||
import ( | ||
appsedges "github.com/openshift/origin/pkg/oc/graph/appsgraph" | ||
osgraph "github.com/openshift/origin/pkg/oc/graph/genericgraph" | ||
kubeedges "github.com/openshift/origin/pkg/oc/graph/kubegraph" | ||
kubegraph "github.com/openshift/origin/pkg/oc/graph/kubegraph/nodes" | ||
) | ||
|
||
type Deployment struct { | ||
Deployment *kubegraph.DeploymentNode | ||
|
||
ActiveDeployment *kubegraph.ReplicaSetNode | ||
InactiveDeployments []*kubegraph.ReplicaSetNode | ||
|
||
Images []ImagePipeline | ||
|
||
// TODO: handle conflicting once controller refs are present, not worth it yet | ||
} | ||
|
||
// AllDeployments returns all the Deployments that aren't in the excludes set and the set of covered NodeIDs | ||
func AllDeployments(g osgraph.Graph, excludeNodeIDs IntSet) ([]Deployment, IntSet) { | ||
covered := IntSet{} | ||
views := []Deployment{} | ||
|
||
for _, uncastNode := range g.NodesByKind(kubegraph.DeploymentNodeKind) { | ||
if excludeNodeIDs.Has(uncastNode.ID()) { | ||
continue | ||
} | ||
|
||
view, covers := NewDeployment(g, uncastNode.(*kubegraph.DeploymentNode)) | ||
covered.Insert(covers.List()...) | ||
views = append(views, view) | ||
} | ||
|
||
return views, covered | ||
} | ||
|
||
// NewDeployment returns the Deployment and a set of all the NodeIDs covered by the Deployment | ||
func NewDeployment(g osgraph.Graph, node *kubegraph.DeploymentNode) (Deployment, IntSet) { | ||
covered := IntSet{} | ||
covered.Insert(node.ID()) | ||
|
||
view := Deployment{} | ||
view.Deployment = node | ||
|
||
for _, istNode := range g.PredecessorNodesByEdgeKind(node, kubeedges.TriggersDeploymentEdgeKind) { | ||
imagePipeline, covers := NewImagePipelineFromImageTagLocation(g, istNode, istNode.(ImageTagLocation)) | ||
covered.Insert(covers.List()...) | ||
view.Images = append(view.Images, imagePipeline) | ||
} | ||
|
||
// for image that we use, create an image pipeline and add it to the list | ||
for _, tagNode := range g.PredecessorNodesByEdgeKind(node, appsedges.UsedInDeploymentEdgeKind) { | ||
imagePipeline, covers := NewImagePipelineFromImageTagLocation(g, tagNode, tagNode.(ImageTagLocation)) | ||
|
||
covered.Insert(covers.List()...) | ||
view.Images = append(view.Images, imagePipeline) | ||
} | ||
|
||
view.ActiveDeployment, view.InactiveDeployments = kubeedges.RelevantDeployments(g, view.Deployment) | ||
for _, rs := range view.InactiveDeployments { | ||
_, covers := NewReplicaSet(g, rs) | ||
covered.Insert(covers.List()...) | ||
} | ||
|
||
if view.ActiveDeployment != nil { | ||
_, covers := NewReplicaSet(g, view.ActiveDeployment) | ||
covered.Insert(covers.List()...) | ||
} | ||
|
||
return view, covered | ||
} |
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,71 @@ | ||
package graphview | ||
|
||
import ( | ||
osgraph "github.com/openshift/origin/pkg/oc/graph/genericgraph" | ||
kubeedges "github.com/openshift/origin/pkg/oc/graph/kubegraph" | ||
"github.com/openshift/origin/pkg/oc/graph/kubegraph/analysis" | ||
kubegraph "github.com/openshift/origin/pkg/oc/graph/kubegraph/nodes" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type ReplicaSet struct { | ||
RS *kubegraph.ReplicaSetNode | ||
|
||
OwnedPods []*kubegraph.PodNode | ||
CreatedPods []*kubegraph.PodNode | ||
} | ||
|
||
func AllReplicaSets(g osgraph.Graph, excludeNodeIDs IntSet) ([]ReplicaSet, IntSet) { | ||
covered := IntSet{} | ||
rsViews := []ReplicaSet{} | ||
|
||
for _, uncastNode := range g.NodesByKind(kubegraph.ReplicaSetNodeKind) { | ||
if excludeNodeIDs.Has(uncastNode.ID()) { | ||
continue | ||
} | ||
|
||
rsView, covers := NewReplicaSet(g, uncastNode.(*kubegraph.ReplicaSetNode)) | ||
covered.Insert(covers.List()...) | ||
rsViews = append(rsViews, rsView) | ||
} | ||
|
||
return rsViews, covered | ||
} | ||
|
||
// MaxRecentContainerRestarts returns the maximum container restarts for all pods | ||
func (rs *ReplicaSet) MaxRecentContainerRestarts() int32 { | ||
var maxRestarts int32 | ||
for _, pod := range rs.OwnedPods { | ||
for _, status := range pod.Status.ContainerStatuses { | ||
if status.RestartCount > maxRestarts && analysis.ContainerRestartedRecently(status, metav1.Now()) { | ||
maxRestarts = status.RestartCount | ||
} | ||
} | ||
} | ||
return maxRestarts | ||
} | ||
|
||
// NewReplicationController returns the ReplicationController and a set of all the NodeIDs covered by the ReplicationController | ||
func NewReplicaSet(g osgraph.Graph, rsNode *kubegraph.ReplicaSetNode) (ReplicaSet, IntSet) { | ||
covered := IntSet{} | ||
covered.Insert(rsNode.ID()) | ||
|
||
rsView := ReplicaSet{} | ||
rsView.RS = rsNode | ||
|
||
for _, uncastPodNode := range g.PredecessorNodesByEdgeKind(rsNode, kubeedges.ManagedByControllerEdgeKind) { | ||
podNode := uncastPodNode.(*kubegraph.PodNode) | ||
covered.Insert(podNode.ID()) | ||
rsView.OwnedPods = append(rsView.OwnedPods, podNode) | ||
} | ||
|
||
return rsView, covered | ||
} | ||
|
||
func MaxRecentContainerRestartsForRS(g osgraph.Graph, rsNode *kubegraph.ReplicaSetNode) int32 { | ||
if rsNode == nil { | ||
return 0 | ||
} | ||
rs, _ := NewReplicaSet(g, rsNode) | ||
return rs.MaxRecentContainerRestarts() | ||
} |
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
Oops, something went wrong.