Skip to content

Commit

Permalink
Merge pull request #1103 from Mixaster995/enhancement/improve-describe
Browse files Browse the repository at this point in the history
Improved describe method
  • Loading branch information
denis-tingaikin authored Dec 2, 2021
2 parents 1103b8c + 6780ef3 commit d8b8af7
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions extensions/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os/signal"
"path/filepath"
"regexp"
"strings"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -205,12 +206,11 @@ func capture(name string) context.CancelFunc {
}
}

//nolint
func describePods(name string) {
getCtx, cancel := context.WithTimeout(ctx, config.Timeout)
defer cancel()

_, err := kubeClient.CoreV1().Namespaces().Get(getCtx, "nsm-system", metav1.GetOptions{})
nsList, err := kubeClient.CoreV1().Namespaces().List(getCtx, metav1.ListOptions{})
if err != nil {
return
}
Expand All @@ -220,7 +220,24 @@ func describePods(name string) {
return
}

runner.Run("kubectl describe pods -n nsm-system >" + filepath.Join(config.ArtifactsDir, name, "describe.log"))
for _, ns := range filterNamespaces(nsList) {
_, _, exitCode, err := runner.Run("kubectl describe pods -n " + ns + ">" + filepath.Join(config.ArtifactsDir, name, "describe-"+ns+".log"))
if exitCode != 0 || err != nil {
logrus.Errorf("An error while retrieving describe for namespace: %v", ns)
}
}
}

func filterNamespaces(nsList *corev1.NamespaceList) []string {
var rv []string

for i := 0; i < len(nsList.Items); i++ {
if (nsList.Items[i].Name == "spire" || nsList.Items[i].Name == "nsm-system" || strings.HasPrefix(nsList.Items[i].Name, "ns-")) && nsList.Items[i].Status.Phase == corev1.NamespaceActive {
rv = append(rv, nsList.Items[i].Name)
}
}

return rv
}

// Capture returns a function that saves logs since Capture function has been called.
Expand Down

0 comments on commit d8b8af7

Please sign in to comment.