Shopify / krane

A command-line tool that helps you ship changes to a Kubernetes namespace and understand the result
MIT License
1.38k stars 115 forks source link

Error retrieving raw URIs from Rancher / Proxied-APIs #892

Open strowi opened 2 years ago

strowi commented 2 years ago

Bug report

Might be related to #891 and #827 missing cluster_url on get --raw commands.

krane fails to get raw api-paths because it is missing the cluster_url on some requests:

[INFO][2022-05-27 10:05:20 +0200]   
[INFO][2022-05-27 10:05:20 +0200]   ------------------------------------Phase 1: Initializing deploy------------------------------------
[INFO][2022-05-27 10:05:22 +0200]   All required parameters and files are present
[INFO][2022-05-27 10:05:22 +0200]   Discovering resources:
[WARN][2022-05-27 10:05:23 +0200]   The following command failed and cannot be retried: kubectl get --raw /apis/monitoring.coreos.com/v1alpha1 --context\=rvg --request-timeout\=15
[WARN][2022-05-27 10:05:23 +0200]   Error from server (NotFound): the server could not find the requested resource

[WARN][2022-05-27 10:05:23 +0200]   Error retrieving api path: Error from server (NotFound): the server could not find the requested resource
[WARN][2022-05-27 10:05:23 +0200]   The following command failed and cannot be retried: kubectl get --raw /apis/core.haproxy.org/v1alpha1 --context\=rvg --request-timeout\=15
[WARN][2022-05-27 10:05:23 +0200]   Error from server (NotFound): the server could not find the requested resource

Expected behavior: No errors, deployment should work.

Actual behavior: Deployment failed

Version(s) affected: 2.4.7

Steps to Reproduce

  1. setup some k8s-proxy tool like rancher
  2. try deploying via the rancher cluster-url "https://XYZ/k8s/clusters/c-gzcbw"
  3. see the above error.

Probable fix

A most probably dirty and not complete fix (there are probably other places to update) for me was changing the path in lib/krane/cluster_resource_discovery.rb:

lib/krane/cluster_resource_discovery.rb:

    def fetch_api_path(path)
      @api_path_cache[path] ||= begin
-        raw_json, err, st = kubectl.run("get", "--raw", path, attempts: 2, use_namespace: false)
+        raw_json, err, st = kubectl.run("get", "--raw", base_api_path + path, attempts: 2, use_namespace: false)
        if st.success?
          JSON.parse(raw_json)
        else

regards, strowi

strowi commented 1 year ago

For anyone interested - here is a compileable working version.

strowi commented 7 months ago

not to play gravedigger, but could anyone take a look? Just tried an update from 2.x to v3.4.0, and i am still running into the same issue, which is fixed for e.g. rancher with a simple:

diff --git a/lib/krane/cluster_resource_discovery.rb b/lib/krane/cluster_resource_discovery.rb
index 44f9689..e60af01 100644
--- a/lib/krane/cluster_resource_discovery.rb
+++ b/lib/krane/cluster_resource_discovery.rb
@@ -64,7 +64,7 @@ module Krane

     def fetch_api_path(path)
       @api_path_cache[path] ||= begin
-        raw_json, err, st = kubectl.run("get", "--raw", path, attempts: 2, use_namespace: false)
+        raw_json, err, st = kubectl.run("get", "--raw", base_api_path + path, attempts: 2, use_namespace: false)
         if st.success?
           MultiJson.load(raw_json)
         else

pinging @timothysmith0609 - not sure you're the right person, but you fixed + merged my previous attempts mentioned on the top post.

strowi commented 1 month ago

Problem still exists with 3.6.0 so i created a PR, sadly i have no idea about the failing unit-tests ;( But have verified it working on top-level and sub-domain cluster-urls.