Skip to content

Commit d302e11

Browse files
committed
Remove fetching of container logs from initializer
Following the focus on the exit code of the command using in the initializer job (Pod), this commit removes the fetching of the container log. There was only a basic JSON unmarshalling applied with no interpretion of what it contained. This is either covered by `k6 inspect` exiting with rc=0 or should be added to the initializer job. If further details about the failure reason needs to be read from the initalizer job, this houdl be the termination message. [1] https://kubernetes.io/docs/tasks/debug/debug-application/determine-reason-pod-failure/#customizing-the-termination-message
1 parent 2868535 commit d302e11

File tree

1 file changed

+1
-54
lines changed

1 file changed

+1
-54
lines changed

controllers/common.go

+1-54
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
package controllers
22

33
import (
4-
"bytes"
54
"context"
6-
"encoding/json"
75
"errors"
86
"fmt"
9-
"io"
10-
"time"
117

128
"github.com/go-logr/logr"
139
"github.com/grafana/k6-operator/api/v1alpha1"
1410
"github.com/grafana/k6-operator/pkg/cloud"
1511
"github.com/grafana/k6-operator/pkg/testrun"
1612
corev1 "k8s.io/api/core/v1"
17-
v1 "k8s.io/api/core/v1"
1813
"k8s.io/apimachinery/pkg/labels"
1914
"k8s.io/apimachinery/pkg/types"
20-
"k8s.io/client-go/kubernetes"
21-
"k8s.io/client-go/rest"
2215
"sigs.k8s.io/controller-runtime/pkg/client"
2316
)
2417

@@ -65,52 +58,6 @@ func inspectTestRun(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
6558
return
6659
}
6760

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-
11461
ready = true
11562
return
11663
}
@@ -201,7 +148,7 @@ func (r *TestRunReconciler) hostnames(ctx context.Context, log logr.Logger, abor
201148
err error
202149
)
203150

204-
sl := &v1.ServiceList{}
151+
sl := &corev1.ServiceList{}
205152

206153
if err = r.List(ctx, sl, opts); err != nil {
207154
log.Error(err, "Could not list services")

0 commit comments

Comments
 (0)