-
Notifications
You must be signed in to change notification settings - Fork 123
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
Allow setting resources and allowMultipleNodesPerWorker in the values #160
Allow setting resources and allowMultipleNodesPerWorker in the values #160
Conversation
Thank you for submitting the PR! Before we can accept any contributions, we need you to sign the CLA at https://cla.datastax.com/. Thanks John |
Fixes #156 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also please add/update unit tests?
@@ -28,6 +28,11 @@ spec: | |||
resources: | |||
requests: | |||
storage: {{ .Values.k8ssandra.cassandraLibDirVolume.size | default "5Gi" }} | |||
allowMultipleNodesPerWorker: {{ .Values.allowMultipleNodesPerWorker | default false}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move these properties under the top-level k8ssandra
property?
charts/k8ssandra-cluster/values.yaml
Outdated
@@ -6,6 +6,8 @@ name: k8ssandra | |||
clusterName: k8ssandra | |||
datacenterName: dc1 | |||
size: 1 | |||
allowMultipleNodesPerWorker: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have allowMultipleNodesPerWorker: true
, should there be a validation check for resources being defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this time the validation of the CassandraDatacenter crd gives a pretty clear error message when you fail to set the resources:
Error: admission webhook "cassandradatacenter-webhook.cassandra.datastax.com" denied the request: CassandraDatacenter write rejected, attempted to use multiple nodes per worker without cpu and memory requests and limits
I could add some conditional statements but it would make the template bigger, and the error message less clear I think. Maybe a comment in the default values.yaml?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message from the webhook is great. The problem is that the chart install still happens and other objects still get created. The user would have to helm uninstall
before trying the install again. We could use the required
template function to make sure resources
is defined. It would fail fast before anything gets deployed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah good point!
{{- if .Values.k8ssandra.allowMultipleNodesPerWorker}} | ||
resources: | ||
limits: | ||
{{ toYaml (required "set resource limits/requets when enabling allowMultipleNodesPerWorker" .Values.k8ssandra.resources.limits) | indent 6}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mispelling at "requets"
@@ -130,5 +133,42 @@ var _ = Describe("Verify CassandraDatacenter template", func() { | |||
// Two containers, medusa and cassandra | |||
Expect(len(cassdc.Spec.PodTemplateSpec.Spec.Containers)).To(Equal(2)) | |||
}) | |||
|
|||
It("setting allowMultipleNodesPerWorker to true", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add two more unit tests - one where allowMultipleNodesPerWorker
is true
and resources
are not specified and one where allowMultipleNodesPerWorker
is false
and resources
is set?
|
||
renderTemplate(options) | ||
|
||
Expect(*cassdc.Spec.Resources.Limits.Memory()).To(Equal(resource.MustParse("2Gi"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one other thing needed for the PR. Can you please bump the chart versions to 0.20.0 in each of the 4 charts?
It("setting allowMultipleNodesPerWorker to true", func() { | ||
options := &helm.Options{ | ||
SetValues: map[string]string{ | ||
"k8ssandra.allowMultipleNodesPerWorker": "true", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this is a duplicate test of the one at line 184, minus the resource verification? If so, can you remove it?
tests/unit/template_cassdc_test.go
Outdated
@@ -33,13 +34,23 @@ var _ = Describe("Verify CassandraDatacenter template", func() { | |||
err = nil | |||
}) | |||
|
|||
renderTemplate := func(options *helm.Options) { | |||
renderedOutput := helm.RenderTemplate( | |||
renderTemplateE := func(options *helm.Options) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a similar change in #178 :)
tests/unit/template_cassdc_test.go
Outdated
renderTemplate := func(options *helm.Options) { | ||
renderedOutput := helm.RenderTemplate( | ||
renderTemplateE := func(options *helm.Options) error { | ||
renderedOutput, renderError := helm.RenderTemplateE( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified a bit as,
renderedOutput, err := helm.RenderTemplateE(
GinkgoT(), options, helmChartPath, helmReleaseName,
[]string{"templates/cassdc.yaml"},
)
if err == nil {
err = helm.UnmarshalK8SYamlE(GinkgoT(), renderedOutput, cassdc)
}
return err
Because we using functions that return an error instead of panic, we need to update all the renderTemplate
that should succeed to calls like this:
Expect(renderTemplate(options)).To(Succeed())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah that looks good!
First time programming Go for me, so these patterns are a bit new :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some other PRs have been merged before yours, so you need to bump the chart versions to 0.22.0. After that I think we are ready to merge :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Setting allowMultipleNodesPerWorker to true is only allowed when resources are set.