Skip to content

Commit

Permalink
feat: Display Helm release ready & status condition
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Toh <[email protected]>
  • Loading branch information
tohjustin committed Oct 3, 2021
1 parent 523cff4 commit 23aee89
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 23 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ kube-system └── Service/metrics-server
kube-system └── EndpointSlice/metrics-server-lbhb9 - 30m [ControllerReference OwnerReference]

$ kube-lineage helm traefik --show-labels
NAMESPACE NAME READY STATUS AGE LABELS
kube-system traefik - 21d <none>
├── ClusterRole/traefik - 21d app.kubernetes.io/managed-by=Helm
├── ClusterRoleBinding/traefik - 21d app.kubernetes.io/managed-by=Helm
kube-system ├── ConfigMap/traefik - 21d app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system ├── ConfigMap/traefik-test - 21d app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system ├── Deployment/traefik 1/1 21d app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system ├── Secret/traefik-default-cert - 21d app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system ├── Service/traefik - 21d app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system ├── Service/traefik-prometheus - 21d app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system └── ServiceAccount/traefik - 21d app.kubernetes.io/managed-by=Helm
NAMESPACE NAME READY STATUS AGE LABELS
kube-system traefik True Deployed 30m <none>
├── ClusterRole/traefik - 30m app.kubernetes.io/managed-by=Helm
├── ClusterRoleBinding/traefik - 30m app.kubernetes.io/managed-by=Helm
kube-system ├── ConfigMap/traefik - 30m app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system ├── ConfigMap/traefik-test - 30m app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system ├── Deployment/traefik 1/1 30m app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system ├── Secret/traefik-default-cert - 30m app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system ├── Service/traefik - 30m app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system ├── Service/traefik-prometheus - 30m app.kubernetes.io/managed-by=Helm,app=traefik,chart=traefik-1.81.0,heritage=Helm,release=traefik
kube-system └── ServiceAccount/traefik - 30m app.kubernetes.io/managed-by=Helm
```

List of supported relationships used for discovering dependent objects:
Expand Down
66 changes: 54 additions & 12 deletions pkg/cmd/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,21 @@ func (o *CmdOptions) Run() error {

// Fetch the release to ensure it exists before proceeding
client := action.NewGet(o.ActionConfig)
release, err := client.Run(o.RequestRelease)
r, err := client.Run(o.RequestRelease)
if err != nil {
return err
}
klog.V(4).Infof("Release manifest:\n%s\n", release.Manifest)
klog.V(4).Infof("Release manifest:\n%s\n", r.Manifest)

// Fetch all resources in the manifests from the cluster
objects, err := o.getManifestObjects(release)
objects, err := o.getManifestObjects(r)
if err != nil {
return err
}
klog.V(4).Infof("Got %d objects from release manifest", len(objects))

// Construct relationship tree to print out
rootNode := releaseToNode(release)
rootNode := releaseToNode(r)
rootUID := rootNode.GetUID()
nodeMap := graph.NodeMap{rootUID: rootNode}
for ix, o := range objects {
Expand Down Expand Up @@ -272,17 +272,59 @@ func (o *CmdOptions) printObj(nodeMap graph.NodeMap, rootUID types.UID) error {
return printer.PrintObj(table, o.Out)
}

// getReleaseReadyStatus returns the ready & status value of a Helm release
// object.
func getReleaseReadyStatus(r *release.Release) (string, string) {
switch r.Info.Status {
case release.StatusDeployed:
return "True", "Deployed"
case release.StatusFailed:
return "False", "Failed"
case release.StatusPendingInstall:
return "False", "PendingInstall"
case release.StatusPendingRollback:
return "False", "PendingRollback"
case release.StatusPendingUpgrade:
return "False", "PendingUpgrade"
case release.StatusSuperseded:
return "False", "Superseded"
case release.StatusUninstalled:
return "False", "Uninstalled"
case release.StatusUninstalling:
return "False", "Uninstalling"
case release.StatusUnknown:
fallthrough
default:
return "False", "Unknown"
}
}

// releaseToNode converts a Helm release object into a Node in the relationship
// tree.
func releaseToNode(release *release.Release) *graph.Node {
rootUID := types.UID("")
root := unstructuredv1.Unstructured{Object: map[string]interface{}{}}
root.SetName(release.Name)
root.SetNamespace(release.Namespace)
root.SetCreationTimestamp(metav1.Time{Time: release.Info.FirstDeployed.Time})
root.SetUID(rootUID)
func releaseToNode(r *release.Release) *graph.Node {
root := new(unstructuredv1.Unstructured)
ready, status := getReleaseReadyStatus(r)
// Set "Ready" condition values based on the printer.objectReadyReasonJSONPath
// & printer.objectReadyStatusJSONPath paths
root.SetUnstructuredContent(
map[string]interface{}{
"status": map[string]interface{}{
"conditions": []interface{}{
map[string]interface{}{
"type": "Ready",
"status": ready,
"reason": status,
},
},
},
},
)
root.SetName(r.Name)
root.SetNamespace(r.Namespace)
root.SetCreationTimestamp(metav1.Time{Time: r.Info.FirstDeployed.Time})
root.SetUID(types.UID(""))
return &graph.Node{
Unstructured: &root,
Unstructured: root,
UID: root.GetUID(),
Name: root.GetName(),
Namespace: root.GetNamespace(),
Expand Down

0 comments on commit 23aee89

Please sign in to comment.