This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ingress information to bug report
Signed-off-by: Thomas Stringer <[email protected]>
- Loading branch information
1 parent
04f7062
commit 6ed8486
Showing
4 changed files
with
169 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
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,138 @@ | ||
package bugreport | ||
|
||
import ( | ||
"context" | ||
"path" | ||
"strings" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
nginxIngressControllerLabelSelector string = "app.kubernetes.io/name=ingress-nginx" | ||
contourIngressControllerLabelSelector string = "app.kubernetes.io/name=contour" | ||
|
||
ingressResourceName string = "ingresses" | ||
ingressBackendResourceName string = "ingressbackends" | ||
) | ||
|
||
func (c *Config) collectIngressReport() error { | ||
namespaceList, err := c.KubeClient.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, namespace := range namespaceList.Items { | ||
ingressList, err := c.KubeClient.NetworkingV1().Ingresses(namespace.Name).List(context.Background(), metav1.ListOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
for _, ingress := range ingressList.Items { | ||
for _, cmd := range ingressReportCommands(namespace.Name, ingress.Name, ingressResourceName) { | ||
filename := path.Join( | ||
c.rootNamespaceDirPath(), | ||
namespace.Name, | ||
ingressResourceName, | ||
ingress.Name, | ||
commandsDirName, | ||
strings.Join(cmd, "_"), | ||
) | ||
if err := runCmdAndWriteToFile(cmd, filename); err != nil { | ||
return err | ||
} | ||
} | ||
c.completionSuccess("Collected report for ingress %s/%s", ingress.Namespace, ingress.Name) | ||
} | ||
|
||
ingressBackendList, err := c.PolicyClient.PolicyV1alpha1().IngressBackends(namespace.Name).List(context.Background(), metav1.ListOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, ingressBackend := range ingressBackendList.Items { | ||
for _, cmd := range ingressReportCommands(namespace.Name, ingressBackend.Name, ingressBackendResourceName) { | ||
filename := path.Join( | ||
c.rootNamespaceDirPath(), | ||
namespace.Name, | ||
ingressBackendResourceName, | ||
ingressBackend.Name, | ||
commandsDirName, | ||
strings.Join(cmd, "_"), | ||
) | ||
if err := runCmdAndWriteToFile(cmd, filename); err != nil { | ||
return err | ||
} | ||
} | ||
c.completionSuccess("Collected report for ingress backend %s/%s", ingressBackend.Namespace, ingressBackend.Name) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Config) collectIngressControllerReport() error { | ||
ingressControllerLabelsSelectors := []string{ | ||
nginxIngressControllerLabelSelector, | ||
contourIngressControllerLabelSelector, | ||
} | ||
for _, labelSelector := range ingressControllerLabelsSelectors { | ||
if err := c.collectIngressControllerReportByLabelSelector(labelSelector); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Config) collectIngressControllerReportByLabelSelector(labelSelector string) error { | ||
namespaceList, err := c.KubeClient.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, namespace := range namespaceList.Items { | ||
podList, err := c.KubeClient.CoreV1().Pods(namespace.Name).List( | ||
context.Background(), | ||
metav1.ListOptions{LabelSelector: labelSelector}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, pod := range podList.Items { | ||
cmds := append( | ||
ingressControllerReportCommands(pod.Namespace, pod.Name), | ||
ingressReportCommands(pod.Namespace, pod.Name, "pods")..., | ||
) | ||
for _, cmd := range cmds { | ||
filename := path.Join( | ||
c.rootNamespaceDirPath(), | ||
namespace.Name, | ||
rootPodDirName, | ||
pod.Name, | ||
commandsDirName, | ||
strings.Join(cmd, "_"), | ||
) | ||
if err := runCmdAndWriteToFile(cmd, filename); err != nil { | ||
return err | ||
} | ||
} | ||
c.completionSuccess("Collected report for ingress controller %s/%s", pod.Namespace, pod.Name) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func ingressReportCommands(namespace, resourceName, resourceType string) [][]string { | ||
return [][]string{ | ||
{"kubectl", "get", resourceType, "-n", namespace, resourceName, "-o", "yaml"}, | ||
{"kubectl", "describe", resourceType, "-n", namespace, resourceName}, | ||
} | ||
} | ||
|
||
func ingressControllerReportCommands(namespace, resourceName string) [][]string { | ||
return [][]string{ | ||
{"kubectl", "logs", "-n", namespace, resourceName}, | ||
} | ||
} |
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