-
Notifications
You must be signed in to change notification settings - Fork 12
include kubectl describe output #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
5fb75ab
4d502ad
27ce4b6
8675cfa
066f42f
308444a
e42945e
c1e0103
a22c061
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -581,6 +581,73 @@ Collecting PGO CLI logs... | |
writeInfo(cmd, fmt.Sprintf("There is no PGUpgrade object associated with cluster '%s'", clusterName)) | ||
} | ||
|
||
// Run kubectl describe and similar commands | ||
writeInfo(cmd, "Running kubectl describe nodes...") | ||
err = runKubectlCommand(tw, cmd, clusterName+"/describe/nodes", "describe", "nodes") | ||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl describe nodes: %s", err)) | ||
} | ||
|
||
writeInfo(cmd, "Running kubectl cluster-info dump...") | ||
err = runKubectlCommand(tw, cmd, clusterName+"/describe/cluster-info.json", "cluster-info", "dump") | ||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl cluster-info dump: %s", err)) | ||
} | ||
|
||
writeInfo(cmd, "Running kubectl describe postgrescluster...") | ||
err = runKubectlCommand(tw, cmd, clusterName+"/describe/postgrescluster", "describe", "postgrescluster", clusterName, "-n", namespace) | ||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl describe postgrescluster: %s", err)) | ||
} | ||
|
||
writeInfo(cmd, "Running kubectl describe crd crunchybridgeclusters...") | ||
err = runKubectlCommand(tw, cmd, clusterName+"/describe/crds/crunchybridgeclusters", "describe", "crds", "crunchybridgeclusters") | ||
philrhurst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl describe crd crunchybridgeclusters: %s", err)) | ||
} | ||
|
||
writeInfo(cmd, "Running kubectl describe crd pgadmins...") | ||
err = runKubectlCommand(tw, cmd, clusterName+"/describe/crds/pgadmins", "describe", "crds", "pgadmins") | ||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl describe crd pgadmins: %s", err)) | ||
} | ||
|
||
writeInfo(cmd, "Running kubectl describe crd pgupgrades...") | ||
err = runKubectlCommand(tw, cmd, clusterName+"/describe/crds/pgupgrades", "describe", "crds", "pgupgrades") | ||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl describe crd pgupgrades: %s", err)) | ||
} | ||
|
||
writeInfo(cmd, "Running kubectl describe crd postgresclusters...") | ||
err = runKubectlCommand(tw, cmd, clusterName+"/describe/crds/postgresclusters", "describe", "crds", "postgresclusters") | ||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl describe crd postgresclusters: %s", err)) | ||
} | ||
|
||
writeInfo(cmd, "Running kubectl describe clusterrole...") | ||
err = runKubectlCommand(tw, cmd, clusterName+"/describe/clusterrole", "describe", "clusterrole", "postgres-operator") | ||
benjaminjb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl describe clusterrole: %s", err)) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Should this be tucked into the logic block btw 611-615? Or wait -- should we print out the err we got on 610 before overwriting it with the err on 614? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I think there's a way to improve the flow and really show the check for 'postgresoperator' is a special case without make the overall structure too-hard-to-follow at a glance. |
||
|
||
writeInfo(cmd, "Running kubectl describe clusterrolebinding...") | ||
err = runKubectlCommand(tw, cmd, clusterName+"/describe/clusterrolebinding", "describe", "clusterrolebinding", "postgres-operator") | ||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl describe clusterrolebinding: %s", err)) | ||
} | ||
|
||
writeInfo(cmd, "Running kubectl describe lease...") | ||
err = runKubectlCommand(tw, cmd, "operator/describe/lease", "describe", "lease", "-n", operatorNamespace) | ||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl describe lease: %s", err)) | ||
} | ||
|
||
writeInfo(cmd, "Running kubectl describe pgadmin...") | ||
err = runKubectlCommand(tw, cmd, "pgadmin/describe/pgadmin", "describe", "pgadmin", "-n", namespace) | ||
philrhurst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl describe pgadmin: %s", err)) | ||
} | ||
|
||
// Print cli output | ||
writeInfo(cmd, "Collecting PGO CLI logs...") | ||
path := clusterName + "/cli.log" | ||
|
@@ -640,6 +707,28 @@ There was an error running 'kubectl get pgupgrade'. Verify permissions and that | |
return nil | ||
} | ||
|
||
func runKubectlCommand(tw *tar.Writer, cmd *cobra.Command, path string, cmdArgs ...string) error { | ||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer cancel() // Ensure the context is canceled to avoid leaks | ||
|
||
ex := exec.CommandContext(ctx, "kubectl", cmdArgs...) | ||
msg, err := ex.Output() | ||
|
||
if err != nil { | ||
msg = append(msg, err.Error()...) | ||
msg = append(msg, []byte(` | ||
There was an error running the command. Verify permissions and that the resource exists.`)...) | ||
|
||
writeInfo(cmd, fmt.Sprintf("Error: '%s'", msg)) | ||
} | ||
|
||
if err := writeTar(tw, msg, path, cmd); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// exportSizeReport defines the message displayed when a support export archive | ||
// is created. If the size of the archive file is greater than 25MiB, an alternate | ||
// message is displayed. | ||
|
@@ -1229,8 +1318,9 @@ func gatherPostgresLogsAndConfigs(ctx context.Context, | |
commands := []Command{ | ||
{path: "pg_controldata", description: "pg_controldata"}, | ||
{path: "df -h /pgdata", description: "disk free"}, | ||
{path: "du -h /pgdata", description: "disk usage"}, | ||
{path: "du -h /pgdata | column -t -o \" \"", description: "disk usage"}, | ||
{path: "ls /pgdata/*/archive_status/*.ready | wc -l", description: "Archive Ready File Count"}, | ||
{path: "psql -P format=wrapped -P columns=180 -c \"select name,setting,source,sourcefile,sourceline FROM pg_settings order by 1\"", description: "PG Settings"}, | ||
} | ||
|
||
var buf bytes.Buffer | ||
|
@@ -1670,6 +1760,10 @@ func gatherPodLogs(ctx context.Context, | |
} | ||
|
||
for _, pod := range pods.Items { | ||
err = runKubectlCommand(tw, cmd, rootDir+"/describe/"+"pods/"+pod.GetName(), "describe", "pods", pod.GetName(), "-n", namespace) | ||
if err != nil { | ||
writeInfo(cmd, fmt.Sprintf("Error running kubectl describe pods: %s", err)) | ||
} | ||
containers := pod.Spec.Containers | ||
containers = append(containers, pod.Spec.InitContainers...) | ||
for _, container := range containers { | ||
|
Uh oh!
There was an error while loading. Please reload this page.