|
1 | 1 | package controllers |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "bytes" |
5 | 4 | "context" |
6 | | - "encoding/json" |
7 | 5 | "errors" |
8 | 6 | "fmt" |
9 | | - "io" |
10 | | - "time" |
11 | 7 |
|
12 | 8 | "github.com/go-logr/logr" |
13 | 9 | "github.com/grafana/k6-operator/api/v1alpha1" |
14 | 10 | "github.com/grafana/k6-operator/pkg/cloud" |
15 | 11 | "github.com/grafana/k6-operator/pkg/testrun" |
16 | 12 | corev1 "k8s.io/api/core/v1" |
17 | | - v1 "k8s.io/api/core/v1" |
18 | 13 | "k8s.io/apimachinery/pkg/labels" |
19 | 14 | "k8s.io/apimachinery/pkg/types" |
20 | | - "k8s.io/client-go/kubernetes" |
21 | | - "k8s.io/client-go/rest" |
22 | 15 | "sigs.k8s.io/controller-runtime/pkg/client" |
23 | 16 | ) |
24 | 17 |
|
@@ -65,52 +58,6 @@ func inspectTestRun(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI, |
65 | 58 | return |
66 | 59 | } |
67 | 60 |
|
68 | | - // Here we need to get the output of the pod |
69 | | - // pods/log is not currently supported by controller-runtime client and it is officially |
70 | | - // recommended to use REST client instead: |
71 | | - // https://github.com/kubernetes-sigs/controller-runtime/issues/1229 |
72 | | - |
73 | | - // TODO: if the below errors repeat several times, it'd be a real error case scenario. |
74 | | - // How likely is it? Should we track frequency of these errors here? |
75 | | - config, err := rest.InClusterConfig() |
76 | | - if err != nil { |
77 | | - log.Error(err, "unable to fetch in-cluster REST config") |
78 | | - returnErr = err |
79 | | - return |
80 | | - } |
81 | | - |
82 | | - clientset, err := kubernetes.NewForConfig(config) |
83 | | - if err != nil { |
84 | | - log.Error(err, "unable to get access to clientset") |
85 | | - returnErr = err |
86 | | - return |
87 | | - } |
88 | | - req := clientset.CoreV1().Pods(k6.NamespacedName().Namespace).GetLogs(podList.Items[0].Name, &corev1.PodLogOptions{ |
89 | | - Container: "k6", |
90 | | - }) |
91 | | - ctx, cancel := context.WithTimeout(context.Background(), time.Second*60) |
92 | | - defer cancel() |
93 | | - |
94 | | - podLogs, err := req.Stream(ctx) |
95 | | - if err != nil { |
96 | | - log.Error(err, "unable to stream logs from the pod") |
97 | | - returnErr = err |
98 | | - return |
99 | | - } |
100 | | - defer podLogs.Close() |
101 | | - |
102 | | - buf := new(bytes.Buffer) |
103 | | - _, returnErr = io.Copy(buf, podLogs) |
104 | | - if err != nil { |
105 | | - log.Error(err, "unable to copy logs from the pod") |
106 | | - return |
107 | | - } |
108 | | - |
109 | | - if returnErr = json.Unmarshal(buf.Bytes(), &inspectOutput); returnErr != nil { |
110 | | - // this shouldn't normally happen but if it does, let's log output by default |
111 | | - log.Error(returnErr, fmt.Sprintf("unable to marshal: `%s`", buf.String())) |
112 | | - } |
113 | | - |
114 | 61 | ready = true |
115 | 62 | return |
116 | 63 | } |
@@ -201,7 +148,7 @@ func (r *TestRunReconciler) hostnames(ctx context.Context, log logr.Logger, abor |
201 | 148 | err error |
202 | 149 | ) |
203 | 150 |
|
204 | | - sl := &v1.ServiceList{} |
| 151 | + sl := &corev1.ServiceList{} |
205 | 152 |
|
206 | 153 | if err = r.List(ctx, sl, opts); err != nil { |
207 | 154 | log.Error(err, "Could not list services") |
|
0 commit comments