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

feat: deprecate Helm 2 #1179

Merged
merged 2 commits into from
Apr 7, 2021
Merged

feat: deprecate Helm 2 #1179

merged 2 commits into from
Apr 7, 2021

Conversation

jdolce
Copy link
Contributor

@jdolce jdolce commented Mar 15, 2021

Signed-off-by: Julian Dolce jdolce@qnx.com

What this PR does / why we need it:
Deprecates Helm 2 chart

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):
Fixes #1076

Special notes for your reviewer:

labelNamespace:
enabled: false
image:
repository: bskim45/helm-kubectl-jq
Copy link
Member

Choose a reason for hiding this comment

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

is this only used for kubectl? can we re-use line/kubectl-kustomize image we use for kustomize?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep for sure will look at using that.

@codecov-io
Copy link

codecov-io commented Mar 19, 2021

Codecov Report

Merging #1179 (00ba3a4) into master (5b0472a) will decrease coverage by 0.24%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1179      +/-   ##
==========================================
- Coverage   50.14%   49.89%   -0.25%     
==========================================
  Files          64       64              
  Lines        4465     4465              
==========================================
- Hits         2239     2228      -11     
- Misses       1922     1928       +6     
- Partials      304      309       +5     
Flag Coverage Δ
unittests 49.89% <ø> (-0.25%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...onstrainttemplate/constrainttemplate_controller.go 53.07% <0.00%> (-3.56%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5b0472a...00ba3a4. Read the comment docs.

@jdolce jdolce force-pushed the helm3 branch 3 times, most recently from 00ba3a4 to eb23f69 Compare March 19, 2021 13:54
@jdolce jdolce marked this pull request as ready for review March 19, 2021 14:30
@ritazh ritazh added this to the v3.4.0 milestone Mar 23, 2021
./.staging/helm/linux-amd64/helm install gatekeeper gatekeeper/gatekeeper --version ${BASE_RELEASE} --debug --wait \
--set emitAdmissionEvents=true \
--set emitAuditEvents=true \
--set customResourceDefinitions.create=false;\
Copy link
Member

Choose a reason for hiding this comment

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

customResourceDefinition.create should be removed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why I left this was because this is the currently released chart being installed before we try and do an upgrade. So customResourceDefinition.create is still in that chart.

$ helm install -n gatekeeper-system [RELEASE_NAME] gatekeeper/gatekeeper

# Helm install and create namespace
$ helm install -n gatekeeper-system [RELEASE_NAME] gatekeeper/gatekeeper --create-namespace --set postInstall.labelNamespace.enabled=true
Copy link
Member

Choose a reason for hiding this comment

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

@ritazh @maxsmythe are we okay with this behavior change? this should be documented in release notes.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the behavior change? the --create-namespace flag?

TBH, I don't think of Helm as part of Gatekeeper's backwards compatibility contract b/c it's an installation method, not an interface, though reasonable people can disagree here. More importantly, it may not be possible to maintain backwards compatibility as it seems like some if these changes are forced by upstream changes to Helm itself?

With that in mind, I would do whatever the community standard is for Helm charts when they need to change.

Copy link
Member

@ritazh ritazh Mar 24, 2021

Choose a reason for hiding this comment

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

This postInstall hook is definitely not obvious. +1 on adding it to release notes and all the docs.
Can postInstall.labelNamespace.enabled be default to true so users don't need to do this every time? And this would ensure existing namespace also gets the admission.gatekeeper.sh/ignore=no-self-managing label.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The behaviour change here is that the Helm chart no longer creates and manages the Namespace. Helm will create it if you ask it by setting the --create-namespace flag, but it's not managed by the chart itself. For example if you uninstall the chart the Namespace will remain.

The challenge with this chart is that we want the admission.gatekeeper.sh/ignore label on the Namespace Gatekeeper is installed in, which is what the postInstall hook stuff does.

As an alternative to this could we include a Config in the chart and set a reasonable default to the Namespace, and allow callers to override it? Based on the docs it seems like this is another alternative to the
--exempt-namespace flag. Also happy to set postInstall.labelNamespace.enabled to true by default, and remove the post-upgrade hook so that it only happens on first time installs. Because that labeling only has to happen one time I would think.

Copy link
Member

Choose a reason for hiding this comment

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

happy to set postInstall.labelNamespace.enabled to true by default, and remove the post-upgrade hook so that it only happens on first time installs. Because that labeling only has to happen one time I would think.

+1

name: gatekeeper-update-namespace
namespace: {{ .Release.Namespace | quote }}

{{- end }}
Copy link
Member

Choose a reason for hiding this comment

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

nit: newline

## Exempting Namespace

The Helm chart automatically set the Gatekeeper flag `--exempt-namespace={{ .Release.Namespace }}` in order to exempt the namespace where the chart is installed. In order for this to work correctly the namespace must have the `admission.gatekeeper.sh/ignore` label.
This can be done by setting up the namespace with the label before installing the chart, or setting `postInstall.labelNamespace.enabled: true`, which will add the label to the release namespace during the post install hook.
Copy link
Member

Choose a reason for hiding this comment

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

why does it need the label before installing the chart?

apiVersion: batch/v1
kind: Job
metadata:
name: gatekeeper-update-namespace
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name: gatekeeper-update-namespace
name: gatekeeper-update-namespace-label

@ritazh
Copy link
Member

ritazh commented Mar 24, 2021

I kicked off upgrade / [Helm] Upgrade test (3.4.2) job again. let's make sure that e2e passes without any issues.

@jdolce
Copy link
Contributor Author

jdolce commented Mar 24, 2021

I kicked off upgrade / [Helm] Upgrade test (3.4.2) job again. let's make sure that e2e passes without any issues.

I think there is an issue with the tests where the tests set enforcementAction: warn but that is not a valid value in gatekeeper 3.1.1 which is the base version of the upgrade path.

Error from server (Could not find the provided enforcementAction value within the supported list [deny dryrun]): error when applying patch:
...

@jdolce jdolce force-pushed the helm3 branch 3 times, most recently from c7bd46f to bbc8fe6 Compare March 26, 2021 19:29
@jdolce
Copy link
Contributor Author

jdolce commented Mar 29, 2021

There is an issue with upgrading that makes it difficult if not impossible to upgrade from older versions.

helm install gatekeeper gatekeeper/gatekeeper --version 3.23 ....

This command will install and manage the Helm chart in the default namespace but all of the resources are installed to the gatekeeper-system namespace.

When you upgrade with the changes here we use the following command to replace the resources in gatekeeper-system namespace.

helm upgrade -n gatekeeper-system gatekeeper manifest_staging/charts/gatekeeper

The problem is that since Helm has installed the chart into the default namespace, it can't find the chart in the gatekeeper-namespace to upgrade.

The only way to make this work would be to initially install the chart with createNamespace=false, but that is not in a released version of the chart yet. This does also mean that there is a real potential for current users to not have a valid upgrade path with this chart.

@ritazh
Copy link
Member

ritazh commented Mar 30, 2021

@jdolce Thanks for raising the issue! Sounds like we need a way to derive gatekeeper.namespace to support cases where the helm release namespace and the namespace that contains all the resources are different.

Maybe we need a helper function in cmd/build/helmify/static/templates/_helpers.tpl that defaults gatekeeper.namespace to gatekeeper-system when Release.Namespace is default, otherwise, use Release.Namespace :

{{- define "gatekeeper.namespace" -}}
{{- if .Release.Namespace default }}
{{- printf "gatekeeper-system" }}
{{- else }}
{{- .Release.Namespace }}
{{- end }}
{{- end -}}

This would ensure helm releases will continue to be in the same namespace users specify with -namespace and the resource's namespace will be gatekeeper.namespace. WDYT?

@jdolce
Copy link
Contributor Author

jdolce commented Mar 30, 2021

@ritazh that might work, but I am concerned that it might be confusing as it is not expected Helm behaviour. Someone could have installed the chart into another namespace that isn't default or gatekeeper-system and they would run into the same problem.

I feel like this is kind of stuck in a bad spot where the current behaviour doesn't allow us to follow Helm best practices without some level of breakage. The changes in 3.4 help with this as it allows you to install it correctly, but that won't help folks that have installed on an older version.

My vote would be to break things with this change as we are deprecating something, and it will be easier to call out this behaviour. This will get us on a good track going forward. Doing so will require users to delete the old chart first to re-install it in the gatekeeper-system namespace. Or you could install it in a different namespace, like gatekeeper and run both for a brief moment, and delete the old one.

If we don't want to break anything, I think we can potentially come up with a solution like what Rita mentions above.

@ritazh
Copy link
Member

ritazh commented Mar 31, 2021

@jdolce I have added this to this week's community call agenda.

@ritazh
Copy link
Member

ritazh commented Mar 31, 2021

Per community call:

We want to deprecate support for when the helm release namespace and GK namespace are different
Need to test how existing CT and constraints will be persisted during helm delete and helm install
Side by side upgrade is not supported

@jdolce
Copy link
Contributor Author

jdolce commented Apr 1, 2021

Per community call:

We want to deprecate support for when the helm release namespace and GK namespace are different
Need to test how existing CT and constraints will be persisted during helm delete and helm install
Side by side upgrade is not supported

Just tested this and after uninstalling the helm chart the CRD's remained along with the constraints.

@maxsmythe
Copy link
Contributor

Sounds like the uninstall/reinstall path is viable then?

@jdolce jdolce force-pushed the helm3 branch 5 times, most recently from f893048 to 9085602 Compare April 2, 2021 16:08
@jdolce
Copy link
Contributor Author

jdolce commented Apr 2, 2021

@ritazh @maxsmythe @sozercan I came up with a migration script that seems to work well, and is being used in the upgrade tests. It prevents one from uninstalling the current chart and deleting any resources. There wasn't a clear spot to put this so it's just at the root of the repo. Let me know if there is a better place and I can move it.

```

Option 2:
Run the `helm_migrate.sh` script before installing the 3.4.0 or greater chart. This will remove the Helm secret for the original release, while keeping all of the resources. It then udpates the annotations of the resources so that the new chart can import and manage them.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Run the `helm_migrate.sh` script before installing the 3.4.0 or greater chart. This will remove the Helm secret for the original release, while keeping all of the resources. It then udpates the annotations of the resources so that the new chart can import and manage them.
Run the `helm_migrate.sh` script before installing the 3.4.0 or greater chart. This will remove the Helm secret for the original release, while keeping all of the resources. It then updates the annotations of the resources so that the new chart can import and manage them.


kubectl annotate --overwrite -n gatekeeper-system deployment gatekeeper-controller-manager meta.helm.sh/release-name=${RELEASE_NAME}
kubectl annotate --overwrite -n gatekeeper-system deployment gatekeeper-controller-manager meta.helm.sh/release-namespace=${NEW_NAMESPACE}

Copy link
Member

@sozercan sozercan Apr 2, 2021

Choose a reason for hiding this comment

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

is this missing pdb?

Error: rendered manifests contain a resource that already exists. Unable to continue with install: PodDisruptionBudget "gatekeeper-controller-manager" in namespace "gatekeeper-system" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: key "meta.helm.sh/release-namespace" must equal "gatekeeper-system": current value is "default"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it. Didn't catch it the first time because it's not in the 3.2.3 Helm chart, which is the base revision for the upgrade.

@jdolce jdolce force-pushed the helm3 branch 3 times, most recently from 5bd3d52 to 6421834 Compare April 2, 2021 21:04
```console
$ helm_migrate.sh
$ helm install -n gatekeeper-system gatekeeper gatekeeper/gatekeeper
```
Copy link
Member

Choose a reason for hiding this comment

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

I am not seeing the helm release after doing helm ls here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You would need helm ls -n gatekeeper-system since the chart is installed in that namespace.
You can also see the secret that Helm creates to manage the release kubectl -n gatekeeper-system get secrets -l release=gatekeeper

Signed-off-by: Julian Dolce <jdolce@qnx.com>
Copy link
Member

@sozercan sozercan left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

LGTM

@ritazh ritazh merged commit a6b2d64 into open-policy-agent:master Apr 7, 2021
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.

Deprecate and remove Helm v2 support
5 participants