Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl 1.20.0 compatibility #776

Closed
sjagoe opened this issue Dec 17, 2020 · 5 comments
Closed

kubectl 1.20.0 compatibility #776

sjagoe opened this issue Dec 17, 2020 · 5 comments

Comments

@sjagoe
Copy link

sjagoe commented Dec 17, 2020

Bug report

Krane fails to deploy using kubectl v1.20.0 (released 8 Dec 2020). The reason appears to be changed output from kubectl api-resources that is now getting processed incorrectly.

The new output format is:

$ kubectl api-resources --namespaced
NAME                        SHORTNAMES   APIVERSION                           NAMESPACED   KIND
bindings                                 v1                                   true         Binding
configmaps                  cm           v1                                   true         ConfigMap
...
daemonsets                  ds           apps/v1                              true         DaemonSet
deployments                 deploy       apps/v1                              true         Deployment
...

contrasted with the old output

NAME                        SHORTNAMES   APIGROUP                    NAMESPACED   KIND
bindings                                                             true         Binding
configmaps                  cm                                       true         ConfigMap
...
daemonsets                  ds           apps                        true         DaemonSet
deployments                 deploy       apps                        true         Deployment
...

The new output's APIVERSION column can be used (almost) verbatim to build the list of prunable resources, aside from the v1 api version resources, which need to be specified as core/v1.

Expected behavior: [What you expected to happen]

krane render ... | krane deploy app-namespace kube-cluster --selector=... -f secrets.ejson -
...
------------------------------------------Result: SUCCESS-------------------------------------------
Successfully deployed 45 resources

Actual behavior: [What actually happened]

krane deployments fail on a kubectl error:

Command failed: apply -f /run/user/1000/d20201217-3427-kaoygu --prune --selector ... --prune-whitelist\=v1/configmap --prune-whitelist\=v1/... ....
error: invalid groupversionkind format: v1/configmap, please follow <group/version/kind> 

The kubectl error message was retrieved by applying #714 to my krane installation.

Version(s) affected: [run krane version]

Krane 2.1.3

Steps to Reproduce

  1. Upgrade kubectl to v1.20.0
  2. Use krane to deploy a project that previously deployed correctly

My quick and dirty hack/fix

A quick and dirty hack that made krane work with kubectl 1.20.0. Obviously this isn't a sufficient fix and breaks support for earlier versions of kubectl. I include it here to help give an idea of the issue.

diff --git a/lib/krane/cluster_resource_discovery.rb b/lib/krane/cluster_resource_discovery.rb
index 8626f5fd2..403f60496 100644
--- a/lib/krane/cluster_resource_discovery.rb
+++ b/lib/krane/cluster_resource_discovery.rb
@@ -17,15 +17,13 @@ module Krane
     end

     def prunable_resources(namespaced:)
-      black_list = %w(Namespace Node ControllerRevision)
-      api_versions = fetch_api_versions
-
+      black_list = %w[Namespace Node ControllerRevision]
       fetch_resources(namespaced: namespaced).uniq { |r| r['kind'] }.map do |resource|
         next unless resource['verbs'].one? { |v| v == "delete" }
         next if black_list.include?(resource['kind'])
-        group_versions = api_versions[resource['apigroup'].to_s]
-        version = version_for_kind(group_versions, resource['kind'])
-        [resource['apigroup'], version, resource['kind']].compact.join("/")
+        apiversion = resource['apiversion'].to_s
+        apiversion = 'core/v1' if apiversion == 'v1'
+        [apiversion, resource['kind']].compact.join("/")
       end.compact
     end
@dturn
Copy link
Contributor

dturn commented Dec 18, 2020

Thanks for bringing this up and the patch!

I've got a PR going to add CI support for k8s v1.20. I'll do my best to get this patched in today. If not, it might not happen till January because of holiday vacations.

@scottlaplante
Copy link

@sjagoe excellent writeup. I have stumbled into this as well, though my "situation" differs slightly.

$ k version --short
Client Version: v1.19.4
Server Version: v1.17.13

configmaps apigroup is blank

$ kubectl api-resources -o wide | grep "SHORTNAMES\|configmap"
NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND                             VERBS
configmaps                        cm                                          true         ConfigMap                        [create delete deletecollection get list patch update watch]

blank "becomes" v1 as designed, and yet I get stopped by (essentially):

$ k apply -f ops.yaml --prune --prune-whitelist=v1/configmap
error: invalid GroupVersionKind format: v1/configmap, please follow <group/version/kind>

Would a fix along the lines of "if apigroup is blank or 'v1', set it to 'core/v1'" suffice? (Please treat this as the naïve question that it is, and apologies for not providing actual code...)

@sjagoe
Copy link
Author

sjagoe commented Jan 4, 2021

Would a fix along the lines of

Something like that could work:

  1. If APIGROUP is blank, try to read the APIVERSION column
  2. If APIVERSION is blank, fall back to pre 1.20.0 implementation, otherwise
  3. If APIVERSION is v1, use core/v1, else use it unchanged.

@sjagoe
Copy link
Author

sjagoe commented Jan 21, 2021

It looks like this is included in v2.1.4 and was fixed by #777.

@sjagoe sjagoe closed this as completed Jan 21, 2021
@sjagoe
Copy link
Author

sjagoe commented Jan 21, 2021

It looks like this is fixed but not noted in the changelog for v2.1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants