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(deploy): Provide Persistent Volume Claim #82

Merged
merged 8 commits into from
Aug 28, 2023

Conversation

mwangggg
Copy link
Member

fixes: #5

@mwangggg mwangggg added feat New feature or request safe-to-test labels Aug 22, 2023
@mwangggg mwangggg marked this pull request as ready for review August 22, 2023 14:41
@mwangggg mwangggg force-pushed the provide_PVC_storage branch from c1c2bbd to 63ed6a3 Compare August 22, 2023 14:42
@mwangggg mwangggg requested a review from ebaron August 22, 2023 14:42
Copy link
Member

@ebaron ebaron left a comment

Choose a reason for hiding this comment

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

Hi @mwangggg, excellent work! I have a few small suggestions inline and some more general comments:

It would be nice to add some other PVC fields that the user may want to edit. Here are all the fields in the PVC spec the user might want to edit: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims

  • We should default accessModes to just ReadWriteOnce. This is what we use in the operator.
  • You can omit volumeMode, we don't want the user to be able to set this as a block device.
  • selector would be good to add, but just keep the default as an empty object. (e.g. selector: {})
  • storageClassName is important to add, but a bit tricky because Kubernetes distinguishes between the empty string and being unset. Let me think about this one. For now you can ignore this detail and just use the storageClassName (if any) as-is from values.yaml.
  • Annotations would be good to provide as a config option as well. These could be done the same way as Ingress: ingress.yaml values.yaml

I remembered the operator sets some extra environment variables to configure H2Database in file mode when using a PVC instead of empty dir. We should set those environment variables in deployment.yaml as well if the PVC is enabled:
https://github.com/cryostatio/cryostat-operator/blob/2d386930dc96f0dcaf937987ec35874006c53b61/internal/controllers/common/resource_definitions/resource_definitions.go#L750-L770

charts/cryostat/templates/persistent-volumelaim.yaml Outdated Show resolved Hide resolved
charts/cryostat/templates/persistent-volumelaim.yaml Outdated Show resolved Hide resolved
@ebaron
Copy link
Member

ebaron commented Aug 22, 2023

I found a good way to do this. We can leave the value commented-out in values.yaml, with just some metadata for the README generator:

  ## @param pvc.storageClassName [string,nullable] Storage class to use for the persistentVolumeClaim
  # storageClassName:

Then you can use the kindIs function to distinguish between an unset value and the empty string:

      {{- if kindIs "string" .Values.pvc.storageClassName }}
      storageClassName: {{ .Values.pvc.storageClassName | quote }}
      {{- end }}

Here's how it works with different values:
$ helm template --set pvc.enabled=true -s templates/persistent-volumelaim.yaml .

---
# Source: cryostat/templates/persistent-volumelaim.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: release-name-persistent-volumeclaim
spec:
  resources:
    requests:
      storage: 500Mi

$ helm template --set pvc.enabled=true,pvc.storageClassName="" -s templates/persistent-volumelaim.yaml .

---
# Source: cryostat/templates/persistent-volumelaim.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: release-name-persistent-volumeclaim
spec:
  resources:
    requests:
      storage: 500Mi
      storageClassName: ""

$ helm template --set pvc.enabled=true,pvc.storageClassName=foo -s templates/persistent-volumelaim.yaml .

---
# Source: cryostat/templates/persistent-volumelaim.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: release-name-persistent-volumeclaim
spec:
  resources:
    requests:
      storage: 500Mi
      storageClassName: "foo"

@ebaron
Copy link
Member

ebaron commented Aug 22, 2023

The testing seems to be failing with:
Error: UPGRADE FAILED: template: cryostat/templates/pvc.yaml:1:14: executing "cryostat/templates/pvc.yaml" at <.Values.pvc.enabled>: nil pointer evaluating interface {}.enabled

I think this is caused by helm/chart-testing#525, which keeps the old values.yaml without any pvc entries. I saw this workaround mentioned that is probably the simplest fix: https://stackoverflow.com/a/68807258. We should just need this specifically on pvc.enabled checks. Anything else referencing nested pvc values should be contained in those checks anyways.

charts/cryostat/templates/pvc.yaml Outdated Show resolved Hide resolved
charts/cryostat/templates/pvc.yaml Outdated Show resolved Hide resolved
charts/cryostat/values.yaml Outdated Show resolved Hide resolved
Copy link
Member

@ebaron ebaron left a comment

Choose a reason for hiding this comment

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

Hi @mwangggg, changes look great! Could I get you to regenerate the README and schema file?

We use this project: https://github.com/bitnami-labs/readme-generator-for-helm/

  1. Clone that repo
  2. cd /path/to/cryostat-helm/charts/cryostat
  3. /path/to/readme-generator-for-helm/bin/index.js -v values.yaml -s values.schema.json -r README.md

@ebaron
Copy link
Member

ebaron commented Aug 24, 2023

I had some trouble when testing this in OpenShift. I think I ran into trouble when executing the post-install steps:

NOTES:

  1. Tell Cryostat how to serve external traffic:
export ROUTE_HOST=$(oc get route -n helm cryostat -o jsonpath="{.status.ingress[0].host}")
export GRAFANA_ROUTE_HOST=$(oc get route -n helm cryostat-grafana -o jsonpath="{.status.ingress[0].host}")
kubectl -n helm set env deploy --containers=cryostat cryostat CRYOSTAT_WEB_HOST=$ROUTE_HOST GRAFANA_DASHBOARD_URL=https://$GRAFANA_ROUTE_HOST

When running these steps, the configuration change triggers a redeployment. This can lead to these two bugs cryostatio/cryostat-operator#487, cryostatio/cryostat-operator#491. I think we should apply the same fix here that we did in the operator (cryostatio/cryostat-operator#499): let's set the deployment spec's replicas to 1 and strategy.type to Recreate.

@mwangggg
Copy link
Member Author

I set the replicas and strategy.type specs to the deployment.yaml folder, but would it be preferable to add them values.yaml and set them there?

@ebaron
Copy link
Member

ebaron commented Aug 28, 2023

I set the replicas and strategy.type specs to the deployment.yaml folder, but would it be preferable to add them values.yaml and set them there?

I think the way you did it is preferable. Allowing the user to change these fields could easily result in a non-working deployment.

Copy link
Member

@ebaron ebaron left a comment

Choose a reason for hiding this comment

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

Seems to work well, thanks for the great work @mwangggg!

@ebaron ebaron merged commit 74181c2 into cryostatio:main Aug 28, 2023
@mwangggg mwangggg deleted the provide_PVC_storage branch March 12, 2024 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request safe-to-test
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Story] Provide option for PVC storage instead of emptyDir
2 participants