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

workaround for .Capabilities.APIVersions #277

Merged
merged 1 commit into from
Dec 1, 2021

Conversation

kd7lxl
Copy link
Collaborator

@kd7lxl kd7lxl commented Dec 1, 2021

What this PR does:
#227 introduced policy/v1 for PodDisruptionBudgets with a conditional based on .Capabilities.APIVersions:

{{- if .Capabilities.APIVersions.Has "policy/v1"}}

By default, helm template populates .Capabilities.APIVersions with all API versions known to Kubernetes client-go v1.22. Many CD tools use this to render the template, then naively try to deploy to Kubernetes clusters that don't support policy/v1, such as v1.20 (e.g., argoproj/argo-cd#7291). This results in error messages like no matches for kind "PodDisruptionBudget" in version "policy/v1".

helm template provides a couple ways to hint a more specific set of API versions:

  • --api-versions can explicitly append API versions to .Capabilities.APIVersions
  • --kube-version can override .Capabilities.KubeVersion, but doesn't have any effect on .Capabilities.APIVersions
  • --validate will interrogate Kubernetes to get an accurate list of API versions

Currently, this chart only works currently with helm template --validate and helm install.

This PR provides a workaround so that all three methods of hinting API version support to helm template work as expected. This should make it easier for users of naive CD tools to deploy this chart successfully.

Demo with various options:

% helm template . -s templates/distributor/distributor-poddisruptionbudget.yaml | grep apiVersion
apiVersion: policy/v1beta1
% helm template . -s templates/distributor/distributor-poddisruptionbudget.yaml --kube-version v1.20 | grep apiVersion
apiVersion: policy/v1beta1
% helm template . -s templates/distributor/distributor-poddisruptionbudget.yaml --kube-version v1.21 | grep apiVersion 
apiVersion: policy/v1
% helm template . -s templates/distributor/distributor-poddisruptionbudget.yaml --api-versions=policy/v1/PodDisruptionBudget | grep apiVersion
apiVersion: policy/v1
% helm template . -s templates/distributor/distributor-poddisruptionbudget.yaml --validate | grep apiVersion
apiVersion: policy/v1

Checklist

  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@kd7lxl kd7lxl requested a review from nschad December 1, 2021 19:33
Signed-off-by: Tom Hayward <thayward@infoblox.com>
Copy link
Collaborator

@nschad nschad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with ArgoCD, works great!

@nschad nschad merged commit eac1eb8 into cortexproject:master Dec 1, 2021
@kd7lxl kd7lxl deleted the policy branch December 1, 2021 21:02
@nschad nschad mentioned this pull request Dec 1, 2021
1 task
@nschad
Copy link
Collaborator

nschad commented Dec 1, 2021

Improvement: #279

ishustava pushed a commit to hashicorp/consul-k8s that referenced this pull request Jan 10, 2022
Checking for existing version using just "policy/v1" doesn't work when running helm template,
and as a result helm will generate a version of PodDisruptionBudget that is not supported by the cluster 
(see cortexproject/cortex-helm-chart#277).

The workaround is to add Kind to the '.Capabilities.APIVersions.Has' check so that 'helm template' will generate the right version of the PodDisruptionBudget resource.
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

Successfully merging this pull request may close these issues.

2 participants