Skip to content

Commit 5ca0b34

Browse files
committed
DeployableByOlmCheck: collect pod status and logs
Signed-off-by: Caleb Xu <caxu@redhat.com>
1 parent 24d0962 commit 5ca0b34

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

internal/policy/operator/deployable_by_olm.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,41 @@ func (p *DeployableByOlmCheck) cleanUp(ctx context.Context, operatorData operato
657657
if err := p.writeToFile(ctx, deployment); err != nil {
658658
logger.Error(err, "could not write deployment to storage")
659659
}
660+
661+
pods, err := p.openshiftClient.GetDeploymentPods(ctx, deploymentName, operatorData.InstallNamespace)
662+
if err != nil {
663+
logger.Info(fmt.Sprintf("warning: unable to retrieve deployment pods: %s", err))
664+
continue
665+
}
666+
667+
for _, pod := range pods {
668+
jsonManifest, err := json.Marshal(pod.Status)
669+
if err != nil {
670+
logger.Error(err, "unable to marshal to json")
671+
}
672+
673+
filename := fmt.Sprintf("%s-PodStatus.json", pod.Name)
674+
if artifactWriter := artifacts.WriterFromContext(ctx); artifactWriter != nil {
675+
if _, err := artifactWriter.WriteFile(filename, bytes.NewReader(jsonManifest)); err != nil {
676+
logger.Error(err, "failed to write the PodStatus to the file")
677+
}
678+
}
679+
680+
logs, err := p.openshiftClient.GetPodLogs(ctx, pod.Name, pod.Namespace)
681+
if err != nil {
682+
logger.Info(fmt.Sprintf("warning: unable to retrieve pod logs: %s", err))
683+
continue
684+
}
685+
686+
for container, logContents := range logs {
687+
filename := fmt.Sprintf("podLogs-%s-%s.json", pod.Name, container)
688+
if artifactWriter := artifacts.WriterFromContext(ctx); artifactWriter != nil {
689+
if _, err := artifactWriter.WriteFile(filename, logContents); err != nil {
690+
logger.Error(err, "failed to write the pod logs to the file")
691+
}
692+
}
693+
}
694+
}
660695
}
661696

662697
logger.V(log.TRC).Info("deleting the resources created by DeployableByOLM Check")

0 commit comments

Comments
 (0)