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

refactor(chart): provide CRDs in a subchart #414

Conversation

cmontemuino
Copy link
Contributor

Description

This changeset is mainly intended to skip Jaeger CRDs if it is not enabled. It is especially relevant when Jaeger tracing is installed separately from OpenEBS Mayastor.

Moving CRDs to a chart solves several issues: clean uninstall, possibility for upgrades, templating.

Motivation and Context

Helm 3 does not manage CRDs (see https://helm.sh/docs/chart_best_practices/custom_resource_definitions/). helm uninstall won't remove CRDs, and helm updgrade won't upgrade them. Manual intervention is required with the current setup.

  • CRDs installed from crds folder are not included into the helm release.

Additionally, it is not possible to template CRDs in Helm 3 in the crds folder.

Regression

No

How Has This Been Tested?

Same results as before this MR:

helm install --set crds.jaeger.enabled=true mayastor

Skip the installation of Jaeger CRDs:

helm install mayastor

Types of changes

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added unit tests to cover my changes.
    • It seems like this project is not using helm-unittest

@tiagolobocastro
Copy link
Contributor

Seems the commit lint must have a bug as it's crashing :)
Anyhow, I think the fix here is to rename:
fixup! chore: allow chart/charts/crds
to
chore: allow chart/charts/crds
or perhaps
feat: allow chart/charts/crds

@cmontemuino any pros/cons to having the CRD files as a sub-chart, rather than just using a plain crd: true/false and checking for this in the yaml template?

@niladrih please take a look at this PR

Copy link
Member

@niladrih niladrih left a comment

Choose a reason for hiding this comment

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

@cmontemuino -- I understand if you want to move the csi-snapshot CRDs to the chart/template directory. What is the motivation for moving them into a subchart? Maybe a new directory inside the template directory would suffice for this use-case?

chart/README.md Outdated Show resolved Hide resolved
@cmontemuino cmontemuino force-pushed the conditional-install-jaeger-crd branch 3 times, most recently from 6621a36 to c93fde9 Compare February 13, 2024 16:46
@cmontemuino
Copy link
Contributor Author

Seems the commit lint must have a bug as it's crashing :) Anyhow, I think the fix here is to rename: fixup! chore: allow chart/charts/crds to chore: allow chart/charts/crds or perhaps feat: allow chart/charts/crds

@cmontemuino any pros/cons to having the CRD files as a sub-chart, rather than just using a plain crd: true/false and checking for this in the yaml template?

@niladrih please take a look at this PR

thanks for pointing this out. I've just squashed the offending commit

@cmontemuino
Copy link
Contributor Author

@cmontemuino -- I understand if you want to move the csi-snapshot CRDs to the chart/template directory. What is the motivation for moving them into a subchart? Maybe a new directory inside the template directory would suffice for this use-case?

@niladrih do you mean adding the Jaeger CRD as a template?

@cmontemuino
Copy link
Contributor Author

cmontemuino commented Feb 13, 2024

@cmontemuino any pros/cons to having the CRD files as a sub-chart, rather than just using a plain crd: true/false and checking for this in the yaml template?

@tiagolobocastro using Helm 3 approach to install CRDs forces you to upgrade CRDs manually (Helm won't upgrade them if you touch the files). That's problematic when doing GitOps.

That said, the main problem here is to avoid installing the Jaeger CRD. It is not possible to template CRDs in the crd folder.

A better approach here would be to publish CRDs in a separate chart. This PR is about applying the minimum required changes.

@niladrih
Copy link
Member

niladrih commented Feb 22, 2024

@cmontemuino -- I understand if you want to move the csi-snapshot CRDs to the chart/template directory. What is the motivation for moving them into a subchart? Maybe a new directory inside the template directory would suffice for this use-case?

@niladrih do you mean adding the Jaeger CRD as a template?

That's right. Something like this:

{{- if and .Values.crds.enabled .Values.base.jaeger.enabled .Values.crds.jaeger-}}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: jaegers.jaegertracing.io
...
{{- end -}}
{{- if and .Values.crds.enabled .Values.crds.volumeSnapshots-}}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: volumesnapshots.snapshot.storage.k8s.io
...
{{- end -}}
chart/
├── crds
└── templates/
    └── crds/
        ├── jaeger.yaml
        ├── volumesnapshots.yaml
        ├── volumesnapshotclasses.yaml
        └── volumesnapshotcontents.yaml
crds:
  # Toggle installation for all CRDs. A 'false' disables installation for all.
  enabled: true
  # Toggle installation for Kubernetes CSI VolumeSnapshot CRDs.
  volumeSnapshots: true
  # Toggle installation for Jaeger CRD(s). 
  jaeger: true

WDYT @cmontemuino @tiagolobocastro? Is the crds.enabled a little too much?

@cmontemuino
Copy link
Contributor Author

@cmontemuino -- I understand if you want to move the csi-snapshot CRDs to the chart/template directory. What is the motivation for moving them into a subchart? Maybe a new directory inside the template directory would suffice for this use-case?

@niladrih do you mean adding the Jaeger CRD as a template?

That's right. Something like this:

{{- if and .Values.crds.enabled .Values.base.jaeger.enabled .Values.crds.jaeger-}}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: jaegers.jaegertracing.io
...
{{- end -}}
{{- if and .Values.crds.enabled .Values.crds.volumeSnapshots-}}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: volumesnapshots.snapshot.storage.k8s.io
...
{{- end -}}
chart/
├── crds
└── templates/
    └── crds/
        ├── jaeger.yaml
        ├── volumesnapshots.yaml
        ├── volumesnapshotclasses.yaml
        └── volumesnapshotcontents.yaml
crds:
  # Toggle installation for all CRDs. A 'false' disables installation for all.
  enabled: true
  # Toggle installation for Kubernetes CSI VolumeSnapshot CRDs.
  volumeSnapshots: true
  # Toggle installation for Jaeger CRD(s). 
  jaeger: true

WDYT @cmontemuino @tiagolobocastro? Is the crds.enabled a little too much?

Hi @niladrih! What you proposed could work for this repo.
I've checked the CRDs are being referenced from a ClusterRole only, that that's ok with Helm's installation order:

That said, I don't really know what could happen in the operator is consuming some of the CRDs, especially in the case of an upgrade when removing/adding APIs.

There is also the option to use chart hooks, but they don't come free of troubles during upgrades.

The following comes from helm best practices around CRDs:

https://helm.sh/docs/chart_best_practices/custom_resource_definitions/#method-1-let-helm-do-it-for-you

There is no support at this time for upgrading or deleting CRDs using Helm. This was an explicit decision after much community discussion due to the danger for unintentional data loss.

**This is why I've filed issue openebs/mayastor/issues/1586 **

https://helm.sh/docs/chart_best_practices/custom_resource_definitions/#method-2-separate-charts:

Another way to do this is to put the CRD definition in one chart, and then put any resources that use that CRD in another chart.

In this method, each chart must be installed separately. However, this workflow may be more useful for cluster operators who have admin access to a cluster

This PR is a convenient shortcut if you will. A completely separate chart for CRDs might make more sense.

@niladrih
Copy link
Member

niladrih commented Mar 1, 2024

@cmontemuino -- Hmm... let me try this out once. The doc seems convincing, I'll spin up a cluster later today.

@niladrih
Copy link
Member

niladrih commented Mar 8, 2024

@cmontemuino -- Changes look good to me, could you also add a switch for the volumeSnapshot CRDs?

crds:
  # -- Install CRDs
  enabled: true
  jaeger:
    # -- Install Jaeger CRDs
    enabled: false
  volumeSnapshots:
    enabled: true

Copy link
Member

@niladrih niladrih left a comment

Choose a reason for hiding this comment

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

Left few comments.

chart/charts/crds/values.yaml Outdated Show resolved Hide resolved
chart/charts/crds/templates/csi-volume-snapshot-class.yaml Outdated Show resolved Hide resolved
chart/README.md Show resolved Hide resolved
chart/README.md Outdated Show resolved Hide resolved
@cmontemuino cmontemuino force-pushed the conditional-install-jaeger-crd branch from 3117120 to 846d869 Compare March 12, 2024 15:52
@cmontemuino
Copy link
Contributor Author

Hi @niladrih, I've addressed all the comments already.
I'll fix the commit lint by squashing all commits into one. Is this ok?

Copy link
Member

@niladrih niladrih left a comment

Choose a reason for hiding this comment

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

Left one comment

chart/charts/crds/values.yaml Outdated Show resolved Hide resolved
@niladrih
Copy link
Member

@cmontemuino -- I see one issue. I've highlighted that above. Otherwise, changes look good to me. I think I'll approve and queue for a merge when you make the change. Thanks!

@cmontemuino
Copy link
Contributor Author

@cmontemuino -- I see one issue. I've highlighted that above. Otherwise, changes look good to me. I think I'll approve and queue for a merge when you make the change. Thanks!

I see it now. Thanks!

@cmontemuino cmontemuino force-pushed the conditional-install-jaeger-crd branch 3 times, most recently from 5ecab24 to b11cfe5 Compare March 12, 2024 19:20
@cmontemuino
Copy link
Contributor Author

@cmontemuino -- I see one issue. I've highlighted that above. Otherwise, changes look good to me. I think I'll approve and queue for a merge when you make the change. Thanks!

I see it now. Thanks!

@niladrih -- the PR is ready to go now

@niladrih
Copy link
Member

bors merge

@bors-openebs-mayastor
Copy link
Contributor

👎 Rejected by too few approved reviews

@niladrih
Copy link
Member

bors merge

bors-openebs-mayastor bot pushed a commit that referenced this pull request Mar 13, 2024
414: refactor(chart): provide CRDs in a subchart r=niladrih a=cmontemuino

## Description

This changeset is mainly intended to skip Jaeger CRDs if it is not enabled. It is especially relevant when Jaeger tracing is installed separately from OpenEBS Mayastor.

Moving CRDs to a chart solves several issues: clean uninstall, possibility for upgrades, templating.

## Motivation and Context

Helm 3 does not manage CRDs (see https://helm.sh/docs/chart_best_practices/custom_resource_definitions/). `helm uninstall` won't remove CRDs, and `helm updgrade` won't upgrade them. Manual intervention is required with the current setup.
 - CRDs installed from `crds` folder **are not included into the helm release**.

Additionally, it is not possible to template CRDs in Helm 3 in the `crds` folder.

## Regression
<!-- Is this PR fixing a regression? (Yes / No) -->
No

<!-- If Yes, optionally please include version or commit id or PR# that caused this regression, if you have these details. -->

## How Has This Been Tested?
<!

Co-authored-by: cmontemuino <1761056+cmontemuino@users.noreply.github.com>
@bors-openebs-mayastor
Copy link
Contributor

Build failed:

@cmontemuino cmontemuino force-pushed the conditional-install-jaeger-crd branch from 105e441 to 7571cd6 Compare March 14, 2024 06:48
@cmontemuino
Copy link
Contributor Author

@niladrih -- could you please issue bors merge one more time?

@niladrih
Copy link
Member

It failed because of an issue with the helm-doc script.

@niladrih
Copy link
Member

This requires #435.

@niladrih
Copy link
Member

bors merge

bors-openebs-mayastor bot pushed a commit that referenced this pull request Mar 14, 2024
414: refactor(chart): provide CRDs in a subchart r=niladrih a=cmontemuino

## Description

This changeset is mainly intended to skip Jaeger CRDs if it is not enabled. It is especially relevant when Jaeger tracing is installed separately from OpenEBS Mayastor.

Moving CRDs to a chart solves several issues: clean uninstall, possibility for upgrades, templating.

## Motivation and Context

Helm 3 does not manage CRDs (see https://helm.sh/docs/chart_best_practices/custom_resource_definitions/). `helm uninstall` won't remove CRDs, and `helm updgrade` won't upgrade them. Manual intervention is required with the current setup.
 - CRDs installed from `crds` folder **are not included into the helm release**.

Additionally, it is not possible to template CRDs in Helm 3 in the `crds` folder.

## Regression
<!-- Is this PR fixing a regression? (Yes / No) -->
No

<!-- If Yes, optionally please include version or commit id or PR# that caused this regression, if you have these details. -->

## How Has This Been Tested?
<!

Co-authored-by: cmontemuino <1761056+cmontemuino@users.noreply.github.com>
@bors-openebs-mayastor
Copy link
Contributor

Build failed:

@niladrih
Copy link
Member

niladrih commented Mar 14, 2024

@cmontemuino -- could you rebase your PR and run this helm-docs script against your changes:

nix-shell ./chart/shell.nix --run ./scripts/helm/generate-readme.sh 

Add the changes...

git status
git add chart/README.md
git commit ...

And then push to this branch..?

@cmontemuino cmontemuino force-pushed the conditional-install-jaeger-crd branch from 7571cd6 to 1891c92 Compare March 14, 2024 13:19
This changeset is mainly intended to skip Jaeger CRDs if it is not
enabled. This is especially relevant when Jaeger tracing is installed
separately from OpenEBS Mayastor.

Helm 3 does not manage CRDs.
- https://helm.sh/docs/chart_best_practices/custom_resource_definitions

`helm uninstall` won't remove CRDs, and `helm updgrade` won't upgrade
them. Manual intervention is required with the current setup.
 - CRDs installed from `crds` folder are not included into the
 helm release.

Additionally, it is not possible to template CRDs in Helm 3 in the
`crds` folder.

Moving CRDs to a chart solves several issues: clean uninstall,
possibility for upgrades, templating.

Also make volumeSnapshots CRD optional

Signed-off-by: cmontemuino <1761056+cmontemuino@users.noreply.github.com>
Signed-off-by: cmontemuino <1761056+cmontemuino@users.noreply.github.com>
Signed-off-by: cmontemuino <1761056+cmontemuino@users.noreply.github.com>
@cmontemuino cmontemuino force-pushed the conditional-install-jaeger-crd branch from 1891c92 to 92e2c38 Compare March 14, 2024 13:19
@cmontemuino
Copy link
Contributor Author

@cmontemuino -- could you rebase your PR and run this helm-docs script against your changes:

nix-shell ./chart/shell.nix --run ./scripts/helm/generate-readme.sh 

Add the changes...

git status
git add chart/README.md
git commit ...

And then push to this branch..?

@niladrih -- all done

@niladrih
Copy link
Member

bors merge

@bors-openebs-mayastor
Copy link
Contributor

Build succeeded:

@bors-openebs-mayastor bors-openebs-mayastor bot merged commit a00529d into openebs:develop Mar 14, 2024
5 checks passed
@cmontemuino cmontemuino deleted the conditional-install-jaeger-crd branch March 14, 2024 13:29
bors-openebs-mayastor bot pushed a commit that referenced this pull request Mar 22, 2024
454: fix(upgrade-job): look for crds in charts dir r=niladrih a=niladrih

The upgrade-job validates the chart that it's got by checking if all the right directories are where they're supposed to be. Recent changes to the CRD installation method (ref: #414) has resulted in the upgrade-job failing, because things aren't how it expects. This PR changes the CRDs directory path to that of the subchart which encapsulates the CRDs now.

Co-authored-by: Niladri Halder <niladri.halder26@gmail.com>
@tiagolobocastro
Copy link
Contributor

tiagolobocastro commented Mar 26, 2024

@cmontemuino a side effect we're finding from this is that if we uninstall when there are CRs present then as the CRD is removed then the CRs are also removed... this essentially means you lose the snapshots!

I think we should add helm.sh/resource-policy: keep by default and provide an option to change it if required, but this should probably not be the default behaviour.
What do you think?

@cmontemuino
Copy link
Contributor Author

cmontemuino commented Mar 26, 2024

@cmontemuino a side effect we're finding from this is that if we uninstall when there are CRs present then as the CRD is removed then the CRs are also removed... this essentially means you lose the snapshots!

I think we should add helm.sh/resource-policy: keep by default and provide an option to change it if required, but this should probably not be the default behaviour. What do you think?

I think you didn't notice the situation before because helm uninstall does not remove CRDs from crds directory.
What you suggest will work just fine. For people using Argo CD, another different annotation is required.

Would you like me to draft a PR to handle this scenario + documentation?
Basically, we need a new element, something like crds.keep: true.
Then, in the CRD templates, we add the annotation you've mentioned above.

Something like the following:

# CRD code here ...
  metadata:
    {{- if .Values.crds.keep }}
    annotations:
      helm.sh/resource-policy: keep
      {{- if .Capabilities.APIVersions.Has "argoproj.io/v1alpha1" }}
      argocd.argoproj.io/sync-options: Prune=false
      {{- end }}
    {{- end }}

Of course it means tight-coupling to Argo CD (i.e., more maintenance, etc.), which might be non desirable....thus, something like the following might be a better fit:

# CRD code here ...
  metadata:
    {{- if or (.Values.crds.keep) (.Values.crds.annotations }}
    annotations:
      {{- if .Values.crds.keep }}
      helm.sh/resource-policy: keep
      {{- end }}
      {{- range $key, $value := .Values.crds.annotations }}
        {{ $key }}: {{ $value | quote }}
      {{- end }}
    {{- end }}

With good documentation everything should be super clear.

Just let me know if you want me to do it and I'll prepare the PR this week.

@tiagolobocastro
Copy link
Contributor

That sounds good @cmontemuino, we'd like to take that PR if you can make it, otherwise we can look into adding it ourselves, let us know :)

Also, do we need to keep the crd presence check on the template? This seems to be required only if upgrading from v2.5.0 which packed the yaml in the crd folder. In case case we could simply document that one needs to use --set crds.enabled=false rather than keep the crd presence check?

@cmontemuino
Copy link
Contributor Author

      {{- range $key, $value := .Values.crds.annotations }}
        {{ $key }}: {{ $value | quote }}
      {{- end }}

Working on it already. Let me draft a PR and we discuss based on it.

@cmontemuino
Copy link
Contributor Author

      {{- range $key, $value := .Values.crds.annotations }}
        {{ $key }}: {{ $value | quote }}
      {{- end }}

Working on it already. Let me draft a PR and we discuss based on it.

Can we move the conversation here? #458

I need a bit of help to write the PR description too... not sure if this is a feature or regression for example.

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.

4 participants