Skip to content

Commit

Permalink
fix: remove output message
Browse files Browse the repository at this point in the history
  • Loading branch information
vsukhin committed Apr 9, 2024
1 parent 368155a commit c41cb7f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
1 change: 0 additions & 1 deletion pkg/executor/client/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ func (c *JobExecutor) updateResultsFromPod(ctx context.Context, pod corev1.Pod,
if err != nil {
l.Errorw("get pod logs error", "error", err)
c.streamLog(ctx, execution.Id, events.NewErrorLog(err))
return execution.ExecutionResult, err
}

// don't attach logs if logs v2 is enabled - they will be streamed through the logs service
Expand Down
12 changes: 4 additions & 8 deletions pkg/executor/containerexecutor/containerexecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import (
)

const (
// ScraperPodSuffix contains scraper pod suffix
ScraperPodSuffix = "-scraper"

pollTimeout = 24 * time.Hour
pollInterval = 200 * time.Millisecond
jobDefaultDelaySeconds = 180
Expand Down Expand Up @@ -226,7 +229,7 @@ func (c *ContainerExecutor) Logs(ctx context.Context, id, namespace string) (out
ids := []string{id}
if supportArtifacts && execution.ArtifactRequest != nil &&
execution.ArtifactRequest.StorageClassName != "" {
ids = append(ids, id+"-scraper")
ids = append(ids, id+ScraperPodSuffix)
}

for _, podName := range ids {
Expand Down Expand Up @@ -424,7 +427,6 @@ func (c *ContainerExecutor) updateResultsFromPod(
scraperLogs, err = executor.GetPodLogs(ctx, c.clientSet, execution.TestNamespace, *latestScraperPod)
if err != nil {
l.Errorw("get scraper pod logs error", "error", err)
return execution.ExecutionResult, err
}

break
Expand All @@ -444,12 +446,6 @@ func (c *ContainerExecutor) updateResultsFromPod(
executorLogs, err := executor.GetPodLogs(ctx, c.clientSet, execution.TestNamespace, *latestExecutorPod)
if err != nil {
l.Errorw("get executor pod logs error", "error", err)
execution.ExecutionResult.Err(err)
err = c.repository.UpdateResult(ctx, execution.Id, *execution)
if err != nil {
l.Infow("Update result", "error", err)
}
return execution.ExecutionResult, err
}

executorLogs = append(executorLogs, scraperLogs...)
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
executorsclientv1 "github.com/kubeshop/testkube-operator/pkg/client/executors/v1"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/executor"
cexecutor "github.com/kubeshop/testkube/pkg/executor/containerexecutor"
"github.com/kubeshop/testkube/pkg/mapper/tests"
"github.com/kubeshop/testkube/pkg/repository/result"
"github.com/kubeshop/testkube/pkg/repository/testresult"
Expand Down Expand Up @@ -117,7 +118,7 @@ OuterLoop:
}

if supportArtifacts && execution.ArtifactRequest != nil && execution.ArtifactRequest.StorageClassName != "" {
id = execution.Id + "-scraper"
id = execution.Id + cexecutor.ScraperPodSuffix
pods, err = executor.GetJobPods(ctx, client.k8sclient.CoreV1().Pods(execution.TestNamespace), id, 1, 10)
if err == nil {
ScraperLoop:
Expand Down
17 changes: 16 additions & 1 deletion pkg/triggers/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package triggers

import (
"context"
"strings"
"time"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -33,6 +34,7 @@ import (
"github.com/kubeshop/testkube-operator/pkg/validation/tests/v1/testtrigger"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/executor"
cexecutor "github.com/kubeshop/testkube/pkg/executor/containerexecutor"
)

type k8sInformers struct {
Expand Down Expand Up @@ -277,6 +279,7 @@ func (s *Service) podEventHandler(ctx context.Context) cache.ResourceEventHandle
}
if oldPod.Namespace == s.testkubeNamespace && oldPod.Labels["job-name"] != "" && oldPod.Labels[testkube.TestLabelTestName] != "" &&
newPod.Namespace == s.testkubeNamespace && newPod.Labels["job-name"] != "" && newPod.Labels[testkube.TestLabelTestName] != "" &&
!(strings.HasSuffix(oldPod.Name, cexecutor.ScraperPodSuffix) || strings.HasSuffix(newPod.Name, cexecutor.ScraperPodSuffix)) &&
oldPod.Labels["job-name"] == newPod.Labels["job-name"] {
s.checkExecutionPodStatus(ctx, oldPod.Labels["job-name"], []*corev1.Pod{oldPod, newPod})
}
Expand All @@ -288,7 +291,8 @@ func (s *Service) podEventHandler(ctx context.Context) cache.ResourceEventHandle
return
}
s.logger.Debugf("trigger service: watcher component: emiting event: pod %s/%s deleted", pod.Namespace, pod.Name)
if pod.Namespace == s.testkubeNamespace && pod.Labels["job-name"] != "" && pod.Labels[testkube.TestLabelTestName] != "" {
if pod.Namespace == s.testkubeNamespace && pod.Labels["job-name"] != "" && !strings.HasSuffix(pod.Name, cexecutor.ScraperPodSuffix) &&
pod.Labels[testkube.TestLabelTestName] != "" {
s.checkExecutionPodStatus(ctx, pod.Labels["job-name"], []*corev1.Pod{pod})
}
event := newWatcherEvent(testtrigger.EventDeleted, pod, testtrigger.ResourcePod,
Expand Down Expand Up @@ -327,6 +331,17 @@ func (s *Service) checkExecutionPodStatus(ctx context.Context, executionID strin
}

execution.ExecutionResult.ErrorMessage += errorMessage
test, err := s.testsClient.Get(execution.TestName)
if err != nil {
s.logger.Errorf("get test returned an error %v while looking for test name: %s", err, execution.TestName)
return err
}

if test.Spec.ExecutionRequest != nil && test.Spec.ExecutionRequest.NegativeTest {
s.logger.Debugw("test run was expected to fail, and it failed as expected", "test", execution.TestName)
execution.ExecutionResult.Status = testkube.ExecutionStatusPassed
}

err = s.resultRepository.UpdateResult(ctx, executionID, execution)
if err != nil {
s.logger.Errorf("update execution result returned an error %v while storing for execution id: %s", err, executionID)
Expand Down

0 comments on commit c41cb7f

Please sign in to comment.