@@ -3,10 +3,8 @@ package reporter
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "net/url"
7
6
8
7
"github.com/coder/coder/v2/codersdk"
9
- "github.com/coder/coder/v2/codersdk/agentsdk"
10
8
"github.com/coder/xray/jfrog"
11
9
12
10
corev1"k8s.io/api/core/v1"
@@ -23,14 +21,12 @@ type K8sReporter struct {
23
21
LabelSelector string
24
22
FieldSelector string
25
23
Namespace string
26
- CoderURL * url. URL
24
+ CoderClient CoderClient
27
25
Logger slog.Logger
28
- CoderToken string
29
26
JFrogClient * jfrog.Client
30
27
31
- ctx context. Context
28
+ // Unexported fields are initialized on calls to Init.
32
29
podInformer cache.SharedIndexInformer
33
- errChan chan error
34
30
}
35
31
36
32
type WorkspaceAgent struct {
@@ -39,9 +35,6 @@ type WorkspaceAgent struct {
39
35
}
40
36
41
37
func (k * K8sReporter )Init (ctx context.Context )error {
42
- k .ctx = ctx
43
- k .errChan = make (chan error )
44
-
45
38
podFactory := informers .NewSharedInformerFactoryWithOptions (k .Client ,0 ,informers .WithNamespace (k .Namespace ),informers .WithTweakListOptions (func (lo * v1.ListOptions ) {
46
39
lo .FieldSelector = k .FieldSelector
47
40
lo .LabelSelector = k .LabelSelector
@@ -92,9 +85,7 @@ func (k *K8sReporter) Init(ctx context.Context) error {
92
85
return
93
86
}
94
87
95
- agentClient := agentsdk .New (k .CoderURL )
96
- agentClient .SetSessionToken (agentToken )
97
- manifest ,err := agentClient .Manifest (ctx )
88
+ manifest ,err := k .CoderClient .AgentManifest (ctx ,agentToken )
98
89
if err != nil {
99
90
log .Error (ctx ,"Get agent manifest" ,slog .Error (err ))
100
91
return
@@ -106,9 +97,7 @@ func (k *K8sReporter) Init(ctx context.Context) error {
106
97
slog .F ("workspace_name" ,manifest .WorkspaceName ),
107
98
)
108
99
109
- cclient := codersdk .New (k .CoderURL )
110
- cclient .SetSessionToken (k .CoderToken )
111
- err = cclient .PostJFrogXrayScan (ctx , codersdk.JFrogXrayScan {
100
+ err = k .CoderClient .PostJFrogXrayScan (ctx , codersdk.JFrogXrayScan {
112
101
WorkspaceID :manifest .WorkspaceID ,
113
102
AgentID :manifest .AgentID ,
114
103
Critical :scan .SecurityIssues .Critical ,