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

charts: Add helm charts for Inspektor Gadget #1707

Merged
merged 3 commits into from
Jul 3, 2023
Merged

Conversation

mqasimsarfraz
Copy link
Member

@mqasimsarfraz mqasimsarfraz commented Jun 2, 2023

This PR introduces helm charts for Inspektor Gadget. The idea is to have a single source of truth for deploy command as helm charts to avoid running into issues in future. The current approach will reuse the CRDs in both installation workflows. In case of manifest, helm will be source of truth and helm generated manifest is used as base (deploy.yaml) for deploy command. In terms of versioning, I want to start with 1:1 versioning between chart version and app version since it is simple and recommend in the start and app version will used for container image tag unless specified.

For publishing we will setup a index like here using helm repo index ... but pointing to charts in our release assets. I want this change to go in and then automate that step.

Related: #414

Testing done

$ make minikube-start
$ make -C charts APP_VERSION=latest install
NAME: gadget
LAST DEPLOYED: Fri Jun  2 17:31:35 2023
NAMESPACE: gadget
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Inspektor Gadget latest installed successfully!

For usage details, visit https://www.inspektor-gadget.io
$ kubectl get pods -n gadget
NAME           READY   STATUS    RESTARTS   AGE
gadget-nsrx2   1/1     Running   0          2m30s

You can verify the charts using:

$ make -C charts [build/package]
$ ls -la charts/bin/gadget
...
-rw-rw-r-- 1 qasim qasim  529 Jun  2 17:04 Chart.yaml
drwxrwxr-x 2 qasim qasim 4096 Jun  2 17:04 crds
-rw-rw-r-- 1 qasim qasim  358 Jun  2 17:04 .helmignore
-rw-r--r-- 1 root  root  2887 Jun  2 17:04 README.md
-rw-rw-r-- 1 qasim qasim 1549 Jun  2 17:04 README.md.gotmpl
drwxrwxr-x 2 qasim qasim 4096 Jun  2 17:04 templates
-rw-rw-r-- 1 qasim qasim 1173 Jun  2 17:04 values.yaml

Ensuring no regression in deploy.yaml

# deploy IG on minikube via 'main'
$ git checkout main
$ make kubectl-gadget
$ ./kubectl-gadget deploy
$ git checkout qasim/helm-charts
$ cat pkg/resources/manifests/*.yaml | kubectl diff -f -
...

Todo

  • Add a test in CI that generated manifest has no changes.
  • Add a step in release job to publish helm package.
  • Add an action to publish charts index to charts repository (possibly inspektor-gadget/charts). [Post Merge]
  • Verify helm charts are available on https://artifacthub.io with generated documentation [Post Merge]

@mqasimsarfraz mqasimsarfraz force-pushed the qasim/helm-charts branch 5 times, most recently from 4541472 to c4a252a Compare June 23, 2023 10:10
@mqasimsarfraz mqasimsarfraz marked this pull request as ready for review June 23, 2023 13:19
Copy link
Contributor

@invidian invidian left a comment

Choose a reason for hiding this comment

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

I'm not very familiar with charts publishing process, so I did not review this part of the PR, but manifests etc looks good. Left some questions/suggestions.

charts/Makefile Outdated
sed -i "s/%VERSION%/$(CHART_VERSION)/g" $(CHART_DIR)/Chart.yaml
sed -i "s/%APP_VERSION%/$(IMAGE_TAG)/g" $(CHART_DIR)/Chart.yaml
@echo "Preparing docs"
docker run --user $(shell id -u):$(shell id -g) -v $(shell pwd)/$(CHART_DIR):/helm-docs jnorwood/helm-docs:v1.11.0 -s file
Copy link
Contributor

Choose a reason for hiding this comment

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

jnorwood/helm-docs:v1.11.0 could also be in a variable in case an override is needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

charts/Makefile Outdated
@echo "Charts available at: $(CHART_DIR)"

install: build
$(HELM) install gadget $(CHART_DIR) --namespace gadget --create-namespace
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe namespace could be a variable as well? Is it supported to deploy IG in other namespaces?

Copy link
Member Author

Choose a reason for hiding this comment

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

IG daemonset itself might be fine in different namespace but the client kubectl-gadget expects the pod to be in gadget namespace so perhaps we keep this way. @mauriciovasquezbernal do you have any thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

If that's the case, perhaps all resources should have this namespace hardcoded then? As installing in other namespace will result in broken scenario.

Copy link
Member Author

Choose a reason for hiding this comment

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

all resources should have this namespace hardcoded then?

Good Point, I refactored the templates to use hardcored "gadget" namespace.

@@ -0,0 +1,6 @@
{{ if .Values.createNamespace }}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this manifest is not necessary. IIRC Helm will complain if target namespace does not exist and --create-namespace flag is not specified.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed it. This was a workaround for helm template not adding namespace in the generated manifest :( but makes sense to move this out of charts.

charts/Makefile Outdated
@echo "Charts available at: $(CHART_DIR)"

install: build
$(HELM) install gadget $(CHART_DIR) --namespace gadget --create-namespace
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would make sense to use helm upgrade --install + kubectl apply for CRDs (as helm upgrade does not update CRDs) to be able to iterate on chart when developing it? install is not idempotent.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great. Thanks for a suggestion. The flow is much better now!

Copy link
Member Author

@mqasimsarfraz mqasimsarfraz left a comment

Choose a reason for hiding this comment

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

@invidian Thank you so much for the review!

charts/Makefile Outdated
sed -i "s/%VERSION%/$(CHART_VERSION)/g" $(CHART_DIR)/Chart.yaml
sed -i "s/%APP_VERSION%/$(IMAGE_TAG)/g" $(CHART_DIR)/Chart.yaml
@echo "Preparing docs"
docker run --user $(shell id -u):$(shell id -g) -v $(shell pwd)/$(CHART_DIR):/helm-docs jnorwood/helm-docs:v1.11.0 -s file
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

charts/Makefile Outdated
@echo "Charts available at: $(CHART_DIR)"

install: build
$(HELM) install gadget $(CHART_DIR) --namespace gadget --create-namespace
Copy link
Member Author

Choose a reason for hiding this comment

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

Great. Thanks for a suggestion. The flow is much better now!

charts/Makefile Outdated
@echo "Charts available at: $(CHART_DIR)"

install: build
$(HELM) install gadget $(CHART_DIR) --namespace gadget --create-namespace
Copy link
Member Author

Choose a reason for hiding this comment

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

IG daemonset itself might be fine in different namespace but the client kubectl-gadget expects the pod to be in gadget namespace so perhaps we keep this way. @mauriciovasquezbernal do you have any thoughts on this?

@@ -0,0 +1,6 @@
{{ if .Values.createNamespace }}
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed it. This was a workaround for helm template not adding namespace in the generated manifest :( but makes sense to move this out of charts.

@mqasimsarfraz mqasimsarfraz force-pushed the qasim/helm-charts branch 5 times, most recently from 4dfc944 to 423bd4c Compare June 30, 2023 10:32
{{/*
Namespace used by all resources.
*/}}
{{- define "gadget.namespace" -}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Great idea for still using a template for the namespace in case this changes in the future!

Copy link
Member

@eiffel-fl eiffel-fl left a comment

Choose a reason for hiding this comment

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

I watched your presentation about it and it seems cool.
I nonetheless need to gain more knowledge about helm to test it and then give an approval.

charts/Makefile Outdated
# also helm upgrade does not update CRDs so we need to apply them separately
install: build
$(HELM) upgrade --install gadget $(CHART_DIR) --namespace gadget --create-namespace
kubectl apply -f $(CHART_DIR)/crds
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
kubectl apply -f $(CHART_DIR)/crds
kubectl apply -f $(CHART_DIR)/crds/*

?
Same for below.

charts/README.md Outdated Show resolved Hide resolved
Comment on lines -13 to +17
kind: Role
kind: ClusterRole
Copy link
Member

Choose a reason for hiding this comment

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

Is it OK to change the order of the stuff there?
Wouldn't it be possible for the deploy to fail if B is defined before A while needing A?

Copy link
Member Author

Choose a reason for hiding this comment

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

In general, It might be problem like if namespace is moved in the end we will run into errors. But here we only swap ClusterRole and Role which aren't related so should be fine. Helm decide to order them like that as mentioned in this section.

Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

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

Some comments. I'm a bit worried about the handling of the latest version.

I was on this branch, I did:

$ make -C charts/ install 
...
Inspektor Gadget 0.17.0 installed successfully 

That was surprising as I was expecting the current version to be installed. Is that the expected version to install the last release?

charts/Makefile Outdated
OUTPUT_DIR ?= $(BUILD_DIR)
CHART_DIR := $(BUILD_DIR)/gadget

IMAGE_TAG := $(shell git describe --tags --abbrev=0 --match "v*")

Choose a reason for hiding this comment

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

We already have a script to get the tag: tools/image-tag. It has some additional logic to take the name of the branch into consideration. Should we use it here too?

Btw, if I'm on main and I run make template it'll use the latest version instead of latest as tag. Is that the desired behaviour?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I wasn't too sure about it. I was trying to have 1:1 versioning between chart version and appVersion and that is making it confusing. Chart Version is suppose to be semver and hence tools/image-tag won't work for it so I used on my own way of handling it. But I agree we should use tools/image-tag for appVersion this should make the behavior exactly like deploy command.

Choose a reason for hiding this comment

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

How do other folks handle the chart version of the "latest" app? Or they aren't charts available for "latest" apps?

Copy link
Member Author

Choose a reason for hiding this comment

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

Most of the charts are living outside so they perhaps don't care about latest. Having said that, one can have dev versions (1.0.0-dev) for both chart/app and use --set image.tag=$IMAGE_TAG (e.g cilium) installation and worry about versioning only for releases. What we did now should work fine but in case it gets confusing we can rework it in future?

charts/Makefile Outdated
Comment on lines 34 to 35
$(HELM) uninstall gadget --namespace gadget
kubectl delete -f $(CHART_DIR)/crds

Choose a reason for hiding this comment

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

Shouldn't it be done the other way around? This is how we do this in the deploy command

Also, what happens to the traces CR?: they need the operator to be running to be able to remove it, otherwise the finalizer will never let them be removed. In the undeploy command we have some logic to handle this

I agree we can just simply say it's the user's responsibility to delete them before if this is difficult to handle.

charts/gadget/templates/daemonset.yaml Show resolved Hide resolved
charts/gadget/values.yaml Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
@echo "Charts available at: $(CHART_DIR)"

# install uses 'helm upgrade --install' to make chart installation idempotent,
# also helm upgrade does not update CRDs so we need to apply them separately

Choose a reason for hiding this comment

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

:( this is too bad as users will have to handle additional commands manually.

According to helm/helm#8668 (comment):

If you're chart doesn't install custom resources just the CRDs... you can put the CRDs right into the templates directory.

That seems to be our case. Perhaps we can investigate more to see if we can improve this. Anyway, I'll agree this an improvement and not a blocker for this PR.

@mqasimsarfraz mqasimsarfraz force-pushed the qasim/helm-charts branch 3 times, most recently from 56e3999 to e690d5c Compare June 30, 2023 17:04
Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

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

I think it's ready to go! Thanks for handling this!

charts/Makefile Outdated
CHART_DIR := $(BUILD_DIR)/gadget

# CHART_VERSION must be a valid SemVer string so strip the leading 'v'
CHART_VERSION ?= $(shell git describe --tags --always | sed 's/^v//')

Choose a reason for hiding this comment

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

Would it make sense to use something like 0.9999.0 to avoid any kind of confusion between app and chart version? (Don't hesitate to say not if it doesn't make sense at all)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
@mqasimsarfraz
Copy link
Member Author

Thanks for all the reviews! :)

@mqasimsarfraz mqasimsarfraz merged commit 19c88f6 into main Jul 3, 2023
46 checks passed
@mqasimsarfraz mqasimsarfraz deleted the qasim/helm-charts branch July 3, 2023 08:26
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.

None yet

4 participants