@@ -2,17 +2,29 @@ package outputresult
2
2
3
3
import (
4
4
"encoding/json"
5
- dockertypes "github.com/docker/docker/api/types"
5
+ "os"
6
+ "time"
7
+
6
8
"github.com/kubesphere/s2irun/pkg/api"
7
- utilglog "github.com/kubesphere/s2irun/pkg/utils/glog"
8
9
"k8s.io/apimachinery/pkg/apis/meta/v1"
10
+ "k8s.io/apimachinery/pkg/util/wait"
9
11
"k8s.io/client-go/kubernetes"
10
12
"k8s.io/client-go/util/retry"
11
- "os"
12
13
"sigs.k8s.io/controller-runtime/pkg/client/config"
14
+
15
+ dockertypes "github.com/docker/docker/api/types"
16
+ utilglog "github.com/kubesphere/s2irun/pkg/utils/glog"
13
17
)
14
18
15
- var glog = utilglog .StderrLog
19
+ var (
20
+ Retry = wait.Backoff {
21
+ Steps : 10 ,
22
+ Duration : 10 * time .Millisecond ,
23
+ Factor : 1.0 ,
24
+ Jitter : 0.1 ,
25
+ }
26
+ glog = utilglog .StderrLog
27
+ )
16
28
17
29
func OutputResult (builderConfig * api.Config , imageInspect * dockertypes.ImageInspect , result * api.Result ) {
18
30
// build result info.
@@ -49,10 +61,10 @@ func OutputResult(builderConfig *api.Config, imageInspect *dockertypes.ImageInsp
49
61
}
50
62
51
63
func addBuildResultToAnnotation (buildResult * api.Result ) error {
52
- namespace := os .Getenv (api . S2iRunNamespace )
53
- jobName := os .Getenv (api . S2iRunJobName )
54
- if namespace == "" || jobName == "" {
55
- glog .Warning ("failed to get env S2iRunJobName and S2iRunNamespace " )
64
+ namespace := os .Getenv ("POD_NAMESPACE" )
65
+ podName := os .Getenv ("POD_NAME" )
66
+ if namespace == "" || podName == "" {
67
+ glog .Warning ("failed to get env S2iRun PodName and S2iRun Namespace " )
56
68
return nil
57
69
}
58
70
cfg , err := config .GetConfig ()
@@ -62,20 +74,22 @@ func addBuildResultToAnnotation(buildResult *api.Result) error {
62
74
}
63
75
k8sClient := kubernetes .NewForConfigOrDie (cfg )
64
76
65
- retryErr := retry .RetryOnConflict (retry . DefaultRetry , func () error {
66
- job , err := k8sClient .BatchV1 ().Jobs (namespace ).Get (jobName , v1.GetOptions {})
77
+ retryErr := retry .RetryOnConflict (Retry , func () error {
78
+ pod , err := k8sClient .CoreV1 ().Pods (namespace ).Get (podName , v1.GetOptions {})
67
79
if err != nil {
68
- glog .Errorf ("failed to get job %s in namespace %s, reason: %s" , jobName , namespace , err )
80
+ glog .Errorf ("failed to get pod %s in namespace %s, reason: %s" , podName , namespace , err )
69
81
return err
70
82
}
71
83
72
- //update job annotations
84
+ //update pod annotations
73
85
result , _ := json .Marshal (buildResult .ResultInfo )
74
86
source , _ := json .Marshal (buildResult .SourceInfo )
75
- job .Annotations [api .AnnotationBuildResultKey ] = string (result )
76
- job .Annotations [api .AnnotationBuildSourceKey ] = string (source )
87
+ pod .Annotations = map [string ]string {
88
+ api .AnnotationBuildResultKey : string (result ),
89
+ api .AnnotationBuildSourceKey : string (source ),
90
+ }
77
91
78
- _ , err = k8sClient .BatchV1 ().Jobs (namespace ).Update (job )
92
+ _ , err = k8sClient .CoreV1 ().Pods (namespace ).Update (pod )
79
93
return err
80
94
})
81
95
0 commit comments