Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Hang Yan <yhang@vmware.com>
  • Loading branch information
hangyan committed Nov 15, 2024
1 parent 40c9d09 commit 933a339
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
31 changes: 11 additions & 20 deletions pkg/antctl/raw/supportbundle/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
systemclientset "antrea.io/antrea/pkg/client/clientset/versioned/typed/system/v1beta1"

"antrea.io/antrea/pkg/util/compress"
"antrea.io/antrea/pkg/util/k8s"
)

const (
Expand Down Expand Up @@ -747,9 +748,7 @@ func downloadPodInfoFromKubernetes(antreaClientset antrea.Interface, k8sClient k
}

var errors []error

for _, pod := range pods.Items {

tmpDir, err := afero.TempDir(defaultFS, "", "bundle_tmp_")
if err != nil {
errors = append(errors, err)
Expand All @@ -759,21 +758,16 @@ func downloadPodInfoFromKubernetes(antreaClientset antrea.Interface, k8sClient k

if pod.Labels["component"] == "antrea-controller" && isControllerFail {
controllerInfo, err := antreaClientset.CrdV1beta1().AntreaControllerInfos().Get(context.TODO(), "antrea-controller", metav1.GetOptions{})
if err != nil {
errors = append(errors, err)
continue
}
data, err := yaml.Marshal(controllerInfo)
if err != nil {
errors = append(errors, err)
continue
if err == nil {
data, err := yaml.Marshal(controllerInfo)
if err == nil {
err = afero.WriteFile(defaultFS, filepath.Join(tmpDir, "controllerinfo"), data, 0644)
errors = append(errors, err)
}
}
err = afero.WriteFile(defaultFS, filepath.Join(tmpDir, "controllerinfo"), data, 0644)
errors = append(errors, err)

err = downloadPodLogs(k8sClient, "controller", pod.Namespace, pod.Name, []string{"antrea-controller"}, dir, tmpDir)
errors = append(errors, err)

}

if _, exist := failedNodesMap[pod.Spec.NodeName]; !exist {
Expand All @@ -783,17 +777,14 @@ func downloadPodInfoFromKubernetes(antreaClientset antrea.Interface, k8sClient k
if pod.Labels["component"] == "antrea-agent" {
if agentInfo, ok := agentInfoMap[pod.Spec.NodeName]; ok {
data, err := yaml.Marshal(agentInfo)
if err != nil {
errors = append(errors, err)
if err == nil {
err = afero.WriteFile(defaultFS, filepath.Join(tmpDir, "agentinfo"), data, 0644)
errors = append(errors, err)
continue
}
err = afero.WriteFile(defaultFS, filepath.Join(tmpDir, "agentinfo"), data, 0644)
errors = append(errors, err)
}

err = downloadPodLogs(k8sClient, "agent_"+pod.Spec.NodeName, pod.Namespace, pod.Name, []string{"antrea-agent", "antrea-ovs", "install-cni"}, dir, tmpDir)
err = downloadPodLogs(k8sClient, "agent_"+pod.Spec.NodeName, pod.Namespace, pod.Name, k8s.GetPodContainerNames(&pod), dir, tmpDir)
errors = append(errors, err)

}
}
return utilerror.NewAggregate(errors)
Expand Down
12 changes: 12 additions & 0 deletions pkg/util/k8s/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ import v1 "k8s.io/api/core/v1"
func IsPodTerminated(pod *v1.Pod) bool {
return pod.Status.Phase == v1.PodFailed || pod.Status.Phase == v1.PodSucceeded
}

// GetPodContainersNames return all the container names in a pod, including init container.
func GetPodContainerNames(pod *v1.Pod) []string {
var names []string
for _, c := range pod.Spec.InitContainers {
names = append(names, c.Name)
}
for _, c := range pod.Spec.Containers {
names = append(names, c.Name)
}
return names
}

0 comments on commit 933a339

Please sign in to comment.