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

[operator] Add Helm chart #204

Merged
merged 15 commits into from Oct 16, 2020

Conversation

consideRatio
Copy link
Contributor

@consideRatio consideRatio commented Oct 14, 2020

I understood that you are accepting contributions where a Helm chart is defined for the starboard-operator, so this is meant to fix #187. Me and @krol3 both started working on this in parallel, but as discussed in #197 (comment) continue with a PR here that @krol3 will review!

PR ambition

In this PR, I've tried to follow the current state of the evolving best practices of Helm charts and created a foundation that will be relatively easy to maintain in the future. As an example, I've tried to avoid the anti-patterns of hardcoding support for a limited set of environment variables which would have needed to be updated as the starboard-operator binary added more configuration options.

Part of this PR

Undecided if part of PR

  • Create a GitHub Actions CI test running helm template which only triggers when the chart folder is changed.
  • Document the experimental state of the Helm chart somewhere

Not part of this PR

  • Create a Helm chart registry where this Helm chart be published
  • Define CI jobs to package and publish the Helm chart to a Helm chart registry
  • Define CI jobs to start a local k8s cluster, install it, and verify it functions
  • Create a values.schema.json that automatically validates passed Helm values to helm template|install|upgrade

Things to consider

  • Are configuration options named sensibly?
  • Are configuration options documented in values.yaml good enough?
  • I've assumed that starboard-operator does not support being run alongside another starboard-operator, and that it wouldn't make sense to require it to be running in a highly available configuration. Is this correct?

@codecov
Copy link

codecov bot commented Oct 14, 2020

Codecov Report

Merging #204 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #204   +/-   ##
=======================================
  Coverage   35.46%   35.46%           
=======================================
  Files          37       37           
  Lines        1844     1844           
=======================================
  Hits          654      654           
  Misses       1079     1079           
  Partials      111      111           

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 ad6b9b9...a46df45. Read the comment docs.

@consideRatio
Copy link
Contributor Author

@krol3 I consider this ready for review at this point! I'm running low on time to do everything I planned (basic CI test for example), but this is now in a functional state it seems from my local testing.

@krol3
Copy link
Contributor

krol3 commented Oct 15, 2020

Hi @consideRatio I tested and It's working the helm chart. I will close my PR.

- name: OPERATOR_TARGET_NAMESPACES
value: {{ tpl .Values.targetNamespaces . | quote }}
- name: OPERATOR_METRICS_BIND_ADDRESS
value: ":8080"
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use: {{ print ":" .Values.image.metricsPort | quote }}

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 think we can avoid needing to add configuration of this because users will only access this through the k8s Service, which in turn points to the Pod's port named metrics.

Hmmm, the k8s Service port can currently be configured with service.port, but I think we should name that metricsPort like you suggest here as that probably makes it less confusing about what the service is meant for currently, and also in case we want to expose something else that isn't metrics on another port.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Users of another Helm chat I've worked with have been fine without configuring the container/pod port for a very long time, so we opted there to not add it at any point in time: https://github.com/jupyterhub/zero-to-jupyterhub-k8s/blob/master/jupyterhub/templates/hub/deployment.yaml#L199-L201

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 9143ca1 to rename service.port to service.metricsPort - do you agree this is sufficient?

# have annotations which will help prometheus as a target for
# scraping of metrics
- name: metrics
containerPort: 8080
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here: {{ .Values.image.metricsPort }}

@consideRatio
Copy link
Contributor Author

Thank you @krol3 for your review and testing that things seem to work on your end as well ❤️ 🎉

@danielpacak danielpacak self-requested a review October 16, 2020 15:13
Copy link
Contributor

@danielpacak danielpacak left a comment

Choose a reason for hiding this comment

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

Great job @consideRatio ! I really appreciate your contribution. I also tested the Helm chart in my cluster and it works as expected.

I left a few comments / questions and in general I do agree with your assumptions that the follow up tasks, such as CI integration and updates to the README, can be done in separate PRs.

Before we merge this one, I'm wondering whether we should add a template to define the VulnerabilityReports custom resource. Some people say that the operator itself should not install the CRDs that it manages, but here we have a Helm chart, which provides means of installation.

Beyond that, I assume that the Helm chart is self contained, i.e. does not require $ starboard init or $ kubectl starboard init command to be run.

That said, do you think we can somehow symbolically link to https://github.com/aquasecurity/starboard/blob/master/deploy/crd/vulnerabilityreports.crd.yaml and send it to Kubernetes API along with other Helm templates? Otherwise we may assume that a deployer defines CRs with kubectl create command.

I also realized that the operator should (programmatically) check if CRs are defined before it spawns any scan job. Otherwise we're waisting resources just to find out that we cannot save a report because of an unknown resource.

deploy/helm/values.yaml Outdated Show resolved Hide resolved
deploy/helm/templates/rbac.yaml Show resolved Hide resolved
deploy/helm/values.yaml Outdated Show resolved Hide resolved
deploy/helm/values.yaml Show resolved Hide resolved
@consideRatio
Copy link
Contributor Author

consideRatio commented Oct 16, 2020

Thank you for your review @danielpacak! 🎉 ❤️

Before we merge this one, I'm wondering whether we should add a template to define the VulnerabilityReports custom resource. Some people say that the operator itself should not install the CRDs that it manages, but here we have a Helm chart, which provides means of installation.

Helm 3 supports this, but it is an evolving best practice. I think its the right call to bundle the CRDs with the helm chart. They won't be templates that render with values, and they won't be managed by Helm after install in general I think. For more info, see: https://helm.sh/docs/chart_best_practices/custom_resource_definitions/

  • CRDs added
  • container securityContext runAsUser/runAsGroup updated to match predefined user/group in Dockerfile
  • Note about OPERATOR_NAMESPACE being inferred added.
  • Decide if rbac.create: true is to remain or be hardcoded as true. I'm not confident about the matter myself, but I suggest to let it remain unless better understanding about why so many helm chart has this setup and its no longer relevant for this helm chart.

@consideRatio consideRatio changed the title Add Helm chart [operator] Add Helm chart Oct 16, 2020
@danielpacak
Copy link
Contributor

Thank you for your review @danielpacak! 🎉 ❤️

Before we merge this one, I'm wondering whether we should add a template to define the VulnerabilityReports custom resource. Some people say that the operator itself should not install the CRDs that it manages, but here we have a Helm chart, which provides means of installation.

Helm 3 supports this, but it is an evolving best practice. I think its the right call to bundle the CRDs with the helm chart. They won't be templates that render with values, and they won't be managed by Helm after install in general I think. For more info, see: https://helm.sh/docs/chart_best_practices/custom_resource_definitions/

  • CRDs added
  • container securityContext runAsUser/runAsGroup updated to match predefined user/group in Dockerfile
  • Note about OPERATOR_NAMESPACE being inferred added.
  • Decide if rbac.create: true is to remain or be hardcoded as true. I'm not confident about the matter myself, but I suggest to let it remain unless better understanding about why so many helm chart has this setup and its no longer relevant for this helm chart.

Thanks for adding the crds to the chart. I didn't know that it's supported by Helm 3! Regarding caveats, I think we're good. If someone wants to managed CRD upgrades we'd suggest installing with OLM / https://operatorhub.io/operator/starboard-operator anyway.

Copy link
Contributor

@danielpacak danielpacak left a comment

Choose a reason for hiding this comment

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

Once again great job @consideRatio ! I'm going to merge the PR. As mentioned in the conversation we can follow up with in dedicated PR for such tasks as automated integration tests run as part of our CI workflow.

Regarding the support for multiple Helm releases running in the same cluster, I think we cannot do much about that. This problem is addressed by Operator Lifecycle Manager, where you define an OperatorGroup to configure multi-tenancy support of the operator. For example, if target namespaces specified by two different OperatorGroup instances intersect, the OLM won't validate such configuration.

I'll update docs / installation guide with Helm chart in this PR #201

@danielpacak danielpacak merged commit 2c0bcbc into aquasecurity:master Oct 16, 2020
@consideRatio
Copy link
Contributor Author

Wieee! Thank you for your review and encouragement @danielpacak ❤️ 🎉 🌻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[operator] Allow deploying operator with Helm chart
3 participants