kubernetes-sigs / cloud-provider-kind

Cloud provider for KIND clusters
Apache License 2.0
146 stars 34 forks source link

Verbose logs should show exact wrapped command being executed #133

Open kriswuollett opened 2 weeks ago

kriswuollett commented 2 weeks ago

Suggest something like base64-encoding the rendered wrapped commands in high verbosity logs so they could be copy and pasted without any issues like shell quoting or line continuations. Expected workflow something like:

% # copy the base64-encoded text
% pbpaste | base64 -d > cmd.sh && chmod +x cmd.sh
% # inspect the cmd.sh file and copy its contents
% # paste the contents in to terminal and run the command

OR, the command to use with curl if it was an API call (like found in browser dev tools).

Reason:

Due to #132 I was not able to debug why cloud-provider-kind was not working with nerdctl because the failed to create continers log entry does not show what I could likely copy and paste for the wrapped docker command:

I0912 21:03:53.930481  117970 event.go:389] "Event occurred" object="projectcontour/envoy" fieldPath="" kind="Service" apiVersion="v1" type="Warning" reason="SyncLoadBalancerFailed" message=<
    Error syncing load balancer: failed to ensure load balancer: failed to create continers kindccm-GZ4YR5X5RDVG26ZXXYAU2GKKAVOAEUPJFJGPZD72 [--detach --tty --label io.x-k8s.cloud-provider-kind.cluster=nyc3-shared --label io.x-k8s.cloud-provider-kind.loadbalancer.name=nyc3-shared/projectcontour/envoy --net kind --init=false --hostname kindccm-GZ4YR5X5RDVG26ZXXYAU2GKKAVOAEUPJFJGPZD72 --privileged --restart=on-failure --sysctl=net.ipv4.ip_forward=1 --sysctl=net.ipv6.conf.all.disable_ipv6=0 --sysctl=net.ipv6.conf.all.forwarding=1 --sysctl=net.ipv4.conf.all.rp_filter=0 --publish=10000/TCP --publish-all envoyproxy/envoy:v1.30.1 bash -c echo -en 'node:
      cluster: cloud-provider-kind
      id: cloud-provider-kind-id

    dynamic_resources:
      cds_config:
        resource_api_version: V3
        path: /home/envoy/cds.yaml
      lds_config:
        resource_api_version: V3
        path: /home/envoy/lds.yaml

    admin:
      access_log_path: /dev/stdout
      address:
        socket_address:
          address: 0.0.0.0
          port_value: 10000
    ' > /home/envoy/envoy.yaml && touch /home/envoy/cds.yaml && touch /home/envoy/lds.yaml && while true; do envoy -c /home/envoy/envoy.yaml && break; sleep 1; done]: exit status 1
 >
BenTheElder commented 1 week ago

As an alternative I recommend something like delve or strace to debug this sort of thing with go.

We don't currently log commands in kind because that resulted in users assuming it was supported to just run those commands manually (sometimes plus their own flags) against the images leading to a lot of support headaches when the exec docker is an implementation detail and one we need good control over to make things work (IE running arbitrary similar commands wouldn't work). Given the code is open source and the process is running locally, advanced users have options to trace the implementation details.

cloud-provider-kind is a little different, but I'm a little wary of this now, there wasn't an obvious way to say "this is the command we're running but here be dragons". that may be less true for this project, but it's re-using the packages from kind.

We do capture the full exec details on errors currently, as something of a middle ground. And it could be revisited in kind, but it will be hard for this repo to do it without revisiting it in kind.

Regarding #132, commenting