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(resources): Add Resource Config for Main Deployment #344

Merged
merged 7 commits into from
Apr 6, 2022

Conversation

jaadbarg
Copy link
Contributor

fixes: #332

@andrewazores andrewazores requested a review from ebaron February 25, 2022 18:49
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.

Hey John, I had a new idea about unit testing this feature. We could add a new test Context for testing the case when a user specifies resource requirements, such as:

Context("with resource requirements", func() {
	BeforeEach(func() {
		t.objs = append(t.objs, test.NewCryostatWithResources())
	})
	It("should create expected deployment", func() {
		t.expectDeployment()
	})
})

Then you'd need to add a NewCryostatWithResources function inside test/resources.go. It can call NewCryostat, but add in resource requirements for each type of container before returning.

To add expectations about the resource requirements present in the deployment, you can modify checkMainDeployment:

func (t *cryostatTestInput) checkMainDeployment() {
deployment := &appsv1.Deployment{}
err := t.Client.Get(context.Background(), types.NamespacedName{Name: "cryostat", Namespace: "default"}, deployment)
Expect(err).ToNot(HaveOccurred())
cr := &operatorv1beta1.Cryostat{}
err = t.Client.Get(context.Background(), types.NamespacedName{Name: "cryostat", Namespace: "default"}, cr)
Expect(err).ToNot(HaveOccurred())
Expect(deployment.Name).To(Equal("cryostat"))
Expect(deployment.Namespace).To(Equal("default"))
Expect(deployment.Annotations).To(Equal(map[string]string{
"app.openshift.io/connects-to": "cryostat-operator-controller-manager",
}))
Expect(deployment.Labels).To(Equal(map[string]string{
"app": "cryostat",
"kind": "cryostat",
"component": "cryostat",
"app.kubernetes.io/name": "cryostat",
}))
Expect(metav1.IsControlledBy(deployment, cr)).To(BeTrue())
Expect(deployment.Spec.Selector).To(Equal(test.NewMainDeploymentSelector()))
// compare Pod template
template := deployment.Spec.Template
Expect(template.Name).To(Equal("cryostat"))
Expect(template.Namespace).To(Equal("default"))
Expect(template.Labels).To(Equal(map[string]string{
"app": "cryostat",
"kind": "cryostat",
"component": "cryostat",
}))
Expect(template.Spec.Volumes).To(Equal(test.NewVolumes(t.minimal, t.TLS)))
Expect(template.Spec.SecurityContext).To(Equal(test.NewPodSecurityContext()))
// Check that the networking environment variables are set correctly
coreContainer := template.Spec.Containers[0]
var reportsUrl string
if t.reportReplicas == 0 {
reportsUrl = ""
} else {
reportsUrl = "http://cryostat-reports:10000"
}
checkCoreContainer(&coreContainer, t.minimal, t.TLS, t.externalTLS, t.EnvCoreImageTag, t.controller.IsOpenShift, reportsUrl)
if !t.minimal {
// Check that Grafana is configured properly, depending on the environment
grafanaContainer := template.Spec.Containers[1]
checkGrafanaContainer(&grafanaContainer, t.TLS, t.EnvGrafanaImageTag)
// Check that JFR Datasource is configured properly
datasourceContainer := template.Spec.Containers[2]
checkDatasourceContainer(&datasourceContainer, t.EnvDatasourceImageTag)
}
// Check that the proper Service Account is set
Expect(template.Spec.ServiceAccountName).To(Equal("cryostat"))
}

Before the call to checkCoreContainer, the Cryostat instance is available in the variable cr. You can add a new parameter to checkCoreContainer of type corev1.ResourceRequirements. Then pass the core resource requirements from cr to this function. Then you can add an expectation comparing the argument to the resource requirements found in the container definition. Repeat this for checkDatasourceContainer and checkGrafanaContainer.

@@ -87,6 +87,25 @@ type CryostatSpec struct {
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="JMX Connections Cache Options"
JmxCacheOptions *JmxCacheOptions `json:"jmxCacheOptions,omitempty"`
// Resource requirements for the Cryostat deployment
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:resourceRequirements"}
Copy link
Member

Choose a reason for hiding this comment

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

This should be:

Suggested change
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:resourceRequirements"}
// +operator-sdk:csv:customresourcedefinitions:type=spec

Having the descriptor here prevents the Core/DataSource/Grafana resources from showing in the UI.

Copy link
Member

Choose a reason for hiding this comment

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

This will need another make bundle after changing.

@jaadbarg
Copy link
Contributor Author

jaadbarg commented Apr 2, 2022

@ebaron for some reason when I run make bundle in cryostat-operator.clusterserviceversion.yaml,

operators.operatorframework.io/builder: operator-sdk-v1.4.0+git operators.operatorframework.io/internal-objects: '["flightrecorders.operator.cryostat.io","recordings.operator.cryostat.io"]'

gets changed to

operators.operatorframework.io/builder: operator-sdk-v1.5.0

and that's causing the merge conflict

@ebaron
Copy link
Member

ebaron commented Apr 4, 2022

@jaadbarg the operators.operatorframework.io/builder annotation change I think is just due to a platform inconsistency. Opearator SDK 1.5.0 reports 1.4.0+git on Linux. Don't worry too much about this.

The operators.operatorframework.io/internal-objects annotation issue is probably just a matter of rebasing your branch onto the latest main branch.

git checkout main
git pull origin main
git checkout #332
git rebase main
git push -f <name of your remote fork> #332

@ebaron
Copy link
Member

ebaron commented Apr 4, 2022

Actually, you'll need to make bundle after rebasing. So the process would be something like:

git checkout main
git pull origin main
git checkout #332
git rebase main
make bundle
git commit -a -m 'Regenerate bundle'
git push -f <name of your remote fork> #332

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.

Looks good, thanks John!

@ebaron ebaron merged commit 90c3363 into cryostatio:main Apr 6, 2022
@ebaron ebaron mentioned this pull request Apr 6, 2022
@ebaron ebaron added the feat New feature or request label Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Resource Requirements for Cryostat deployment
3 participants