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

Add Experimental HelmOps controller. #3092

Merged
merged 15 commits into from
Dec 16, 2024
Merged

Conversation

0xavi0
Copy link
Contributor

@0xavi0 0xavi0 commented Nov 22, 2024

This adds a new custom resource HelmApp (resource name open to debate) that describes a helm chart to be deployed.

The resource contains all the fields from the classic fleet.yaml file plus a few new from the GitRepo resource.

HelmApp yaml example:

apiVersion: fleet.cattle.io/v1alpha1
kind: HelmApp
metadata:
  name: sample1
  namespace: fleet-local
spec:
  helm:
    releaseName: testhelm
    repo: https://charts.bitnami.com/bitnami
    chart: postgresql
    version: 16.2.1
  insecureSkipTLSVerify: true

The implementation tries to share as much as possible from a Bundle spec inside the new resource, because it helps to "transform" the HelmApp into a deployment (no conversion is needed for most of the spec).

The new controller was also implemented splitting the functionality into 2 controllers (similar to what we did for the GitRepo controller). This allows us to reuse most of the status handling code, as display fields in the status of the new resource are as similar as possible to have consistent user experience and to integrate with the UI in the same way the GitRepo does.

When a new HelmApp resource is applied it is transformed into a single Bundle, adding some extra fields to let the Bundle reconciler know that this is not a regular Bundle coming from a GitRepo.

Similar as we did for OCI storage, the Bundle created from a HelmApp does not contain resources. The helm chart to be deployed is downloaded by the agent.

Code for downloading the helm chart is reused from gitops, so the same formats are supported. Insecure TLS skipping was added the the ChartURL and LoadDirectory functions in order to support this for gitops and helmops.

If we need a secret to access the helm repository we can use the helmSecretName field. This secret will be cloned to secrets under the BundleDeployment namespace (same as we did for the OCI storage secret handling).

The PR includes unit, integration (most of code is tested this way) and just one single e2e test so far just to test the whole feature together in a real cluster.

The following image describes how Spec fields are shared between Bundle and HelmApp and how the Status fields are shared between GitRepo and HelmApp:

helmapp2 drawio

Note: This is an experimental feature. In order to activate the HelmApp reconciling and Bundle deployment you need to set the following environment variable: EXPERIMENTAL_HELM_OPS=true

Refers to: #2962

@0xavi0 0xavi0 self-assigned this Nov 22, 2024
@0xavi0 0xavi0 force-pushed the 2962-helm-charts branch 7 times, most recently from 5324f8f to 4ad653a Compare November 27, 2024 09:15
@0xavi0 0xavi0 marked this pull request as ready for review November 28, 2024 16:47
@0xavi0 0xavi0 requested a review from a team as a code owner November 28, 2024 16:47
Copy link
Contributor

@weyfonk weyfonk left a comment

Choose a reason for hiding this comment

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

Thanks for this! Leaving a few comments, many of which are just nitpicks.
This new feature creates bundles synchronously, which may be fine for now as they are more lightweight, without resources, than in the gitOps case. But I wonder if that may become an issue on larger setups (although worker counts will soon be configurable even in the agent).

charts/fleet/templates/deployment_helmops.yaml Outdated Show resolved Hide resolved
charts/fleet/templates/rbac_helmops.yaml Outdated Show resolved Hide resolved
internal/bundlereader/loaddirectory.go Outdated Show resolved Hide resolved
internal/bundlereader/loaddirectory.go Outdated Show resolved Hide resolved
internal/bundlereader/charturl.go Outdated Show resolved Hide resolved
internal/bundlereader/helm_test.go Show resolved Hide resolved
integrationtests/helmops/controller/controller_test.go Outdated Show resolved Hide resolved
integrationtests/helmops/controller/controller_test.go Outdated Show resolved Hide resolved
integrationtests/helmops/controller/controller_test.go Outdated Show resolved Hide resolved
@0xavi0 0xavi0 force-pushed the 2962-helm-charts branch 4 times, most recently from fc68a6c to 55f7216 Compare December 5, 2024 13:56
@0xavi0 0xavi0 requested a review from weyfonk December 5, 2024 15:15
internal/cmd/controller/helmops/operator.go Outdated Show resolved Hide resolved
pkg/apis/fleet.cattle.io/v1alpha1/status.go Outdated Show resolved Hide resolved
internal/bundlereader/helm_test.go Outdated Show resolved Hide resolved
integrationtests/helmops/controller/controller_test.go Outdated Show resolved Hide resolved
internal/bundlereader/resources.go Outdated Show resolved Hide resolved
@0xavi0 0xavi0 requested a review from weyfonk December 10, 2024 15:49
@0xavi0 0xavi0 force-pushed the 2962-helm-charts branch 3 times, most recently from f3fc4b6 to 9f1850c Compare December 11, 2024 14:27
@0xavi0 0xavi0 requested a review from weyfonk December 11, 2024 14:59
Comment on lines 14 to 15
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
v1alpha1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
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
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
v1alpha1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
fleetv1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"

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've deleted the v1alpha1 one

It adds a new custom resource `HelmApp` (resource name open to debate) that describes a helm chart to be deployed.

The resource contains all the fealds from the classic `fleet.yaml` file plus a few new from the `GitRepo`
resource.

`HelmApp` yaml example:

```yaml
apiVersion: fleet.cattle.io/v1alpha1
kind: HelmApp
metadata:
  name: sample1
  namespace: fleet-local
spec:
  helm:
    releaseName: testhelm
    repo: https://charts.bitnami.com/bitnami
    chart: postgresql
    version: 16.2.1
  insecureSkipTLSVerify: true
```

The implementation tries to share as much as possible from a `Bundle` spec inside the new resource, because it helps
to "transform" the `HelmApp` into a deployment (no coversion is needed for most of the spec).

The new controller was also implemented splitting the functionality into 2 controllers (similar to what we did for the `GitRepo` controller). This allows us to reuse most of the status handling code, as display fields in the status of the new resource are as similar as possible to have consistent user experience and to integrate with the UI in the same way the `GitRepo` does.

When a new `HelmApp` resource is applied it is transformed into a single `Bundle`, adding some extra fields to let the `Bundle` reconciler know that this is not a regular `Bundle` coming from a `GitRepo`.

Similar as we did for OCI storage, the `Bundle` created from a `HelmApp` does not contain resources. The helm chart to be deployed is downloaded by the agent.

Code for downloading the helm chart is reused from gitops, so the same formats are supported.
Insecure TLS skipping was added the the ChartURL and LoadDirectory functions in order to support this for gitops and helmops.

If we need a secret to access the helm repository we can use the `helmSecretName` field. This secret will be cloned to secrets under the `BundleDeployment` namespace (same as we did for the OCI storage secret handling).

The PR includes unit, integration (most of code is tested this way) and just one single e2e test so far just to test the whole feature together in a real cluster.

Note: This is an experimental feature. In order to activate the `HelmApp` reconciling and `Bundle` deployment you need to the the environment variable: `EXPERIMENTAL_HELM_OPS=true`

Refers to: rancher#2962
This is so we can enable the UI and browse artifacts

Signed-off-by: Xavi Garcia <[email protected]>
Signed-off-by: Xavi Garcia <[email protected]>
Copy link
Member

@manno manno left a comment

Choose a reason for hiding this comment

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

LGTM

@manno manno merged commit 534dbfd into rancher:main Dec 16, 2024
12 checks passed
@manno manno changed the title Initial proposal of the new Helmops controller. New Experimental Helmops controller. Dec 16, 2024
@manno manno changed the title New Experimental Helmops controller. Add Experimental Helmops controller. Dec 16, 2024
@manno manno changed the title Add Experimental Helmops controller. Add Experimental HelmOps controller. Dec 16, 2024
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.

3 participants