In order to see messages sent and received from/to the K8s client and debug possible issues, having all the http requests to K8s API logged it's interesting. Having the endpoint, and payload sent/received and http headers.
We'll also check if OkHTTP logging can be configured to print those messages.
I checked code and looks like we're already using okhttp logging-interceptor for this:
If I set logging level to trace in my simplelogger.properties file:
org.slf4j.simpleLogger.defaultLogLevel=trace
If I execute some code like this:
try (OpenShiftClient client = new DefaultOpenShiftClient()) {
SelfSubjectAccessReview ssar = new SelfSubjectAccessReviewBuilder()
.withNewSpec()
.withNewResourceAttributes()
.withGroup("apps")
.withResource("deployments")
.withVerb("create")
.withNamespace("rokumar")
.endResourceAttributes()
.endSpec()
.build();
ssar = client.authorization().v1().selfSubjectAccessReview().create(ssar);
}
It produces the following log:
[main] DEBUG io.fabric8.kubernetes.client.Config - Trying to configure client from Kubernetes config...
[main] DEBUG io.fabric8.kubernetes.client.Config - Found for Kubernetes config at: [/home/rohaan/.kube/config].
Oct 12, 2020 12:17:06 PM okhttp3.internal.platform.Platform log
INFO: --> POST https://api.example.openshift.com/apis/authorization.k8s.io/v1/selfsubjectaccessreviews http/1.1
Oct 12, 2020 12:17:06 PM okhttp3.internal.platform.Platform log
INFO: Content-Type: application/json; charset=utf-8
Oct 12, 2020 12:17:06 PM okhttp3.internal.platform.Platform log
INFO: Content-Length: 183
Oct 12, 2020 12:17:06 PM okhttp3.internal.platform.Platform log
INFO: Host: api.example.openshift.com
Oct 12, 2020 12:17:06 PM okhttp3.internal.platform.Platform log
INFO: Connection: Keep-Alive
Oct 12, 2020 12:17:06 PM okhttp3.internal.platform.Platform log
INFO: Accept-Encoding: gzip
Oct 12, 2020 12:17:06 PM okhttp3.internal.platform.Platform log
INFO: User-Agent: okhttp/3.12.12
Oct 12, 2020 12:17:06 PM okhttp3.internal.platform.Platform log
INFO:
Oct 12, 2020 12:17:06 PM okhttp3.internal.platform.Platform log
INFO: {"apiVersion":"authorization.k8s.io/v1","kind":"SelfSubjectAccessReview","spec":{"resourceAttributes":{"group":"apps","namespace":"rokumar","resource":"deployments","verb":"create"}}}
Oct 12, 2020 12:17:06 PM okhttp3.internal.platform.Platform log
INFO: --> END POST (183-byte body)
Oct 12, 2020 12:17:07 PM okhttp3.internal.platform.Platform log
INFO: <-- 201 Created https://api.example.openshift.com/apis/authorization.k8s.io/v1/selfsubjectaccessreviews (334ms)
Oct 12, 2020 12:17:07 PM okhttp3.internal.platform.Platform log
INFO: Audit-Id: 8529c650-caec-423b-a3e6-3200af80f7c4
Oct 12, 2020 12:17:07 PM okhttp3.internal.platform.Platform log
INFO: Cache-Control: no-store
Oct 12, 2020 12:17:07 PM okhttp3.internal.platform.Platform log
INFO: Content-Type: application/json
Oct 12, 2020 12:17:07 PM okhttp3.internal.platform.Platform log
INFO: Date: Mon, 12 Oct 2020 06:47:06 GMT
Oct 12, 2020 12:17:07 PM okhttp3.internal.platform.Platform log
INFO: Content-Length: 283
Oct 12, 2020 12:17:07 PM okhttp3.internal.platform.Platform log
INFO:
Oct 12, 2020 12:17:07 PM okhttp3.internal.platform.Platform log
INFO: {"kind":"SelfSubjectAccessReview","apiVersion":"authorization.k8s.io/v1","metadata":{"creationTimestamp":null},"spec":{"resourceAttributes":{"namespace":"rokumar","verb":"create","group":"apps","resource":"deployments"}},"status":{"allowed":false,"reason":"no RBAC policy matched"}}
Oct 12, 2020 12:17:07 PM okhttp3.internal.platform.Platform log
INFO: <-- END HTTP (283-byte body)
Process finished with exit code 0
I think all we need to do is to document this :-) . Maybe we can add a section in our CHEATSHEET about it?
@jonathanvila : Hi, Would you like to contribute a PR for this? I think it would be awesome if you could submit a Doc improvement PR to address this issue?