kubevirt / containerized-data-importer

Data Import Service for kubernetes, designed with kubevirt in mind.
Apache License 2.0
395 stars 249 forks source link

Make reverse proxy send error messages to klog and to virtctl #3307

Closed EduardGomezEscandell closed 1 month ago

EduardGomezEscandell commented 1 month ago

What this PR does / why we need it: Upload proxy uses the httputil.ReverseProxy.

When httputil.ReverseProxy fails, it sends a message down the standard library's default logger. This can be seen in the pod's log but the client simply receives a 5xx error and no context.

This PR redirects messages away from the standard logger and into both the k8s logger and the client.

Changes in virtctl output BEFORE

unexpected return value 502,

AFTER

unexpected return value 502, error in upload-proxy: http: proxy error: dial tcp 10.101.34.134:443: connect: connection timed out

Changes in upload-proxy logs BEFORE

2024/05/09 16:30:08 http: proxy error: dial tcp 172.30.111.109:443: connect: connection timed out

AFTER

E0605 11:02:45.551559       1 uploadproxy.go:323] Error in reverse proxy: http: proxy error: dial tcp 10.101.34.134:443: connect: connection timed out

Which issue(s) this PR fixes https://issues.redhat.com/browse/CNV-41624

Special notes for your reviewer:

Release note:

Improve error reporting in upload-proxy
EduardGomezEscandell commented 1 month ago

To exercise this fix you need a VM image, then you can run this script:

IMAGE=./cirros-0.6.2-x86_64-disk.img

# Start cluster
make cluster-up
make cluster-sync

# Patch cluster (Solved in https://github.com/kubevirt/containerized-data-importer/pull/3306)
host_port=$(./cluster-up/cli.sh ports uploadproxy | xargs)
override="https://127.0.0.1:$host_port"
kubectl patch cdi cdi --type merge -p '{"spec": {"config": {"uploadProxyURLOverride": "'"$override"'"}}}'

# Break the uploadproxy
cat << EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: 
  name: default-deny-ingress
spec: 
  podSelector: {}
  policyTypes: 
  - Ingress
EOF

# Exercise the error
virtctl image-upload dv hello-example --size=1Gi --image-path "${IMAGE}" --force-bind --insecure

Keep it mind it takes a while to fail because it keeps retrying.

EduardGomezEscandell commented 1 month ago

/cc @awels

awels commented 1 month ago

/retest

EduardGomezEscandell commented 1 month ago

/retest

EduardGomezEscandell commented 1 month ago

/cc @awels

awels commented 1 month ago

/approve

kubevirt-bot commented 1 month ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: awels

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/kubevirt/containerized-data-importer/blob/main/OWNERS)~~ [awels] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment