github.imxd.top/operator-framework/operator-sdk@v0.8.2/doc/proposals/helm-operator.md (about)

     1  ## Helm Operator Proposal
     2  
     3  ### Background
     4  
     5  As was mentioned in the [Ansible Operator Proposal](./ansible-operator.md), not everyone is a golang developer, so the SDK needs to support other types of operators to gain adoption across a wider community of users.
     6  
     7  [Helm](https://helm.sh/) is one of the most widely-used tools for Kubernetes application management, and it bills itself as the "package manager for Kubernetes." Operators serve a nearly identical function, but they improve on Helm's concepts by incorporating an always-on reconciliation loop rather than relying on an imperative user-driven command line tool. By integrating Helm's templating engine and release management into an operator, the SDK will further increase the number of potential users by adding the ability to deploy Charts (e.g. from Helm's [large catalog of existing Charts](https://github.com/helm/charts)) as operators with very little extra effort.
     8  
     9  ### Goals
    10  
    11  The goal of the Helm Operator will be to create a fully functional framework for Helm Chart developers to create operators. It will also expose a library for golang users to use Helm in their operator if they so choose. These two goals in conjunction will allow users to select the best technology for their project or skillset.
    12  
    13  ### New Operator Type
    14  
    15  This proposal creates a new type of operator called `helm`. The new type is used to tell the tooling to act on that type of operator.
    16  
    17  ### Package Structure
    18  
    19  Packages will be added to the operator-sdk. These packages are designed to be usable by the end user if they choose to and should have a well documented public API. The proposed packages are:
    20  
    21  * /operator-sdk/pkg/helm/client
    22    * Will contain a helper function to create a Helm client from `controller-runtime` manager.
    23  
    24  * /operator-sdk/pkg/helm/controller
    25    * Will contain an exported `HelmOperatorReconciler` that implements the `controller-runtime` `reconcile.Reconciler` interface.
    26    * Will contain an exported `Add` function that creates a controller using the `HelmOperatorReconciler` and adds watches based on a set of watch options passed to the `Add` function.
    27  
    28  * /operator-sdk/pkg/helm/engine
    29    * Will contain a Helm Engine implementation that adds owner references to generated Kubernetes resource assets, which is necessary for garbage collection of Helm chart resources.
    30  
    31  * /operator-sdk/pkg/helm/internal
    32    * Will contain types and utilities used by other Helm packages in the SDK.
    33  
    34  * /operator-sdk/pkg/helm/release
    35    * Will contain the `Manager` types and interfaces. A `Manager` is responsible for:
    36      * Implementing Helm's Tiller functions that are necessary to install, update, and uninstall releases.
    37      * Reconciling an existing release's resources.
    38    * A default `Manager` implementation is provided in this package but is not exported.
    39    * Package functions:
    40      * `NewManager` - function that returns a new Manager for a provided helm chart.
    41      * `NewManagersFromEnv` - function that returns a map of GVK to Manager types based on environment variables.
    42      * `NewManagersFromFile` - function that returns a map of GVK to Manager types based on a provided config file.
    43  
    44  ### Commands
    45  
    46  We are adding and updating existing commands to accommodate the Helm operator.  Changes to the `cmd` package as well as changes to the generator are needed.
    47  
    48  #### New
    49  
    50  New functionality will be updates to allow Helm operator developers to create a new boilerplate operator structure with everything necessary to get started developing and deploying a Helm operator with the SDK.
    51  
    52  ```
    53  operator-sdk new <project-name> --type=helm --kind=<kind> --api-version=<group/version>
    54  ```
    55  
    56  Flags:
    57  * `--type=helm` is required to create Helm operator project.
    58  * **Required:** --kind - the kind for the CRD.
    59  * **Required:** --api-version - the group/version for the CRD.
    60  
    61  This will be new scaffolding for the above command under the hood. We will:
    62  * Create a `./<project-name>` directory.
    63  * Create a `./<project-name>/helm-charts` directory.
    64  * Generate a simple default chart at `./<project-name>/helm-charts/<kind>`.
    65  * Create a new watches file at `./<project-name>/watches.yaml`. The chart and GVK will be defaulted based on input to the `new` command.
    66  * Create a `./<project-name>/deploy` with the Kubernetes resource files necessary to run the operator.
    67  * Create a `./build/Dockerfile` that uses the watches file and the helm chart. It will use the Helm operator as its base image.
    68  
    69  The resulting structure will be:
    70  
    71  ```
    72  <project-name>
    73  |   watches.yaml
    74  |
    75  |-- build
    76  |   |   Dockerfile
    77  |
    78  |-- helm-charts
    79  |   |-- <kind>
    80  |       |   Chart.yaml
    81  |       |   ...
    82  |
    83  |-- deploy
    84  |   |   operator.yaml
    85  |   |   role_binding.yaml
    86  |   |   role.yaml
    87  |   |   service_account.yaml
    88  |   |
    89  |   |-- crds
    90  |       |   <gvk>_crd.yaml
    91  |       |   <gvk>_cr.yaml
    92  ```
    93  
    94  The SDK CLI will use the presence of the `helm-charts` directory to detect a `helm` type project.
    95  
    96  #### Add
    97  
    98  Add functionality will be updated to allow Helm operator developers to add new CRDs/CRs and to update the watches.yaml file for additional Helm charts. The command helps when a user wants to watch more than one CRD for their operator.
    99  
   100  ```
   101  operator-sdk add crd --api-version=<group>/<version> --kind=<kind> --update-watches=<true|false>
   102  ```
   103  
   104  Flags:
   105  * **Required:** --kind - the kind for the CRD.
   106  * **Required:** --api-version - the group/version for the CRD.
   107  * **Optional:** --update-watches - whether or not to update watches.yaml file (default: false).
   108  
   109  **NOTE:** `operator-sdk add` subcommands `api` and `controller` will not be supported, since they are only valid for Go operators. Running these subcommands in a Helm operator project will result in an error.
   110  
   111  #### Up
   112  
   113  Up functionality will be updated to allow Helm operator developers to run their operator locally, using the `operator-sdk` binary's built-in helm operator implementation.
   114  
   115  ```
   116  operator-sdk up local
   117  ```
   118  
   119  This should use the known structure and the helm operator code to run the operator from this location. The existing code will need to be updated with a new operator type check for `helm` (in addition to existing `go` and `ansible` types). The command works by running the operator-sdk binary, which includes the Helm operator code, as the operator process.
   120  
   121  #### Build
   122  
   123  Build functionality will be updated to support building a docker image from the Helm operator directory structure.
   124  
   125  ```
   126  operator-sdk build <image-name>
   127  ```
   128  
   129  #### Test
   130  
   131  The SDK `test` command currently only supports Go projects, so there will be no support for the `operator-sdk test` subcommand in the initial integration of the Helm operator.
   132  
   133  ### Base Image
   134  
   135  The SDK team will maintain a build job for the `helm-operator` base image with the following tagging methodology:
   136  * Builds on the master branch that pass nightly CI tests will be tagged with `:master`
   137  * Builds for tags that pass CI will be tagged with `:<tag>`. If the tag is also the greatest semantic version for the repository, the image will also be tagged with `:latest`.
   138  
   139  The go binary included in the base image will be built with `GOOS=linux` and `GOARCH=amd64`.
   140  
   141  The base image repository will be `quay.io/water-hole/helm-operator`.
   142  
   143  ### Observations and open questions
   144  
   145  * There will be a large amount of overlap in the `operator-sdk` commands for the Ansible and Helm operators. We should take care to extract the reusable features of the Ansible operator commands into a shared library, usable by both Helm and Ansible commands.
   146  
   147  * There is a moderate amount of complexity already related to how operator types are handled between the `go` and `ansible` types. With the addition of a third type, there may need to be a larger design proposal for operator types. For example, do we need to define an `Operator` interface that each of the operator types can implement for flag verification, scaffolding, project detection, etc.?