-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
180 changed files
with
274 additions
and
41,842 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ test/drone/ | |
test/bitcoind/ | ||
test/tomcat/ | ||
temp/ | ||
test-operator/ | ||
test-operator/ | ||
helm2go-operator-sdk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,96 @@ | ||
[![Build Status](https://travis-ci.org/redhat-nfvpe/service-assurance-poc.svg?branch=master)](https://travis-ci.org/redhat-nfvpe/helm2go-operator-sdk) [![Go Report Card](https://goreportcard.com/badge/github.com/redhat-nfvpe/helm2go-operator-sdk)](https://goreportcard.com/report/github.com/redhat-nfvpe/helm2go-operator-sdk) | ||
|
||
|
||
![alt text](docs/design.png) | ||
|
||
## Design | ||
## Overview | ||
--- | ||
This project is a small tool to produce Go Operators corresponding to Helm Charts in a reproducible and scalable way. Read more about the design in the [design doc](docs/Design.md). | ||
|
||
### Render | ||
Render handles the primary steps in the Helm to Go Kubernetes pathway. The main responsibility of this package is to render valid Helm charts. Additionally, the package can write the injected files to a specified temp directory. | ||
[Helm](https://github.com/helm/helm) is a tool used for managing Kubernetes charts. Charts are packages of pre-configured Kubernetes resources. Helm allows for versioning and distribution of native Kubernetes applications. | ||
|
||
### Convert | ||
Convert handles the secondary steps in the Helm to Go Kubernetes pathway. The main responsibility of this package is the unmarshal the rendered YAML files and produce raw Kubernetes resources. | ||
Go Operators are native Kubernetes applications used to deploy, upgrade, and manage other Kubernetes applications. | ||
|
||
The file `pkg/convert/convert.go` contains the main logic to accomplish the conversion itself. `YAMLUnmarshalResources` receives an absolute path to a directory and simply unmarshals all resource files one at a time. | ||
|
||
## Workflow | ||
--- | ||
The tool provides the following workflow to develop operators in Go from corresponding Helm Charts: | ||
|
||
1. Identify Helm Chart | ||
* Tool supports local charts | ||
* Tool supports external charts i.e. those hosted on external repositories | ||
2. Specify the neccessary resource, and the API is generated adding Custom Resource Definitions (CRDs) | ||
3. *Supported* Kubernetes Resources Controllers are automatically generated | ||
4. User must write the reconciling logic for the controller using the [Operator-SDK](https://github.com/operator-framework/operator-sdk) and [controller-runtime](https://godoc.org/sigs.k8s.io/controller-runtime) APIs. | ||
5. Use the [Operator-SDK](https://github.com/operator-framework/operator-sdk) CLI to build and generate the operator deployment manifests. | ||
|
||
## Flags | ||
The existing flags are as listed: | ||
``` | ||
--api-version string Kubernetes apiVersion and has a format of $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1) | ||
--cluster-scoped Operator cluster scoped or not | ||
--helm-chart string Initialize helm operator with existing helm chart (<URL>, <repo>/<name>, or local path) | ||
--helm-chart-ca-file string CA File For External Repo (Optional) | ||
--helm-chart-cert-file string Cert File For External Repo (Optional) | ||
--helm-chart-key-file string Key File For External Repo (Optional) | ||
--helm-chart-version string Specific version of the helm chart (default is latest version) | ||
--help help for convert | ||
--kind string Kubernetes CustomResourceDefintion kind. (e.g AppService) | ||
--password string Password for chart repo (Optional) | ||
--username string Username for chart repo (Optional) | ||
``` | ||
|
||
## How To Use | ||
## Prerequisites | ||
--- | ||
* [git](https://git-scm.com/downloads) | ||
* [go](https://golang.org/dl/) version v1.12+ | ||
* [operator-sdk](https://github.com/operator-framework/operator-sdk) version v0.8+ | ||
* [dep](https://golang.github.io/dep/docs/installation.html) version v0.5.0+ | ||
|
||
To create an operator from an existing *local* helm chart: | ||
|
||
## Quick Start | ||
--- | ||
In the following example, we will create an nginx-operator using the existing [Bitnami Nginx](https://github.com/bitnami/charts/tree/master/bitnami/nginx) Helm Chart. | ||
|
||
### Create, Build and Deploy an *nginx-operator* from Local Chart | ||
``` | ||
go run main.go convert <OperatorName> --helm-chart=/path/to/chart --kind=Kind --api-version=apps.example.com/v1alpha1 | ||
# Create an nginx-operator that defines the Ngnix CR | ||
$ export GO111MODULE=on | ||
# Begin scaffolding process | ||
$ helm2go-operator-sdk convert nginx-operator --helm-chart=/path/to/nginx --api-version=web.example.com/v1alpha1 --kind=Ngnix | ||
# Enter operator directory | ||
$ cd nginx-operator | ||
# Build the operator | ||
$ export GO111MODULE=off | ||
$ operator-sdk build quay.io/example/image | ||
$ docker push quay.io/example/image | ||
# Deploy the Operator | ||
# Update the operator manifest to use the built image name (if you are performing these steps on OSX, see note below) | ||
$ sed -i 's|REPLACE_IMAGE|quay.io/example/app-operator|g' deploy/operator.yaml | ||
# On OSX use: | ||
$ sed -i "" 's|REPLACE_IMAGE|quay.io/example/app-operator|g' deploy/operator.yaml | ||
# Setup Service Account | ||
$ kubectl create -f deploy/service_account.yaml | ||
# Setup RBAC | ||
$ kubectl create -f deploy/role.yaml | ||
$ kubectl create -f deploy/role_binding.yaml | ||
# Setup the CRD | ||
$ kubectl create -f deploy/crds/web_v1alpha1_nginx_crd.yaml | ||
# Deploy the app-operator | ||
$ kubectl create -f deploy/operator.yaml | ||
# Create an AppService CR | ||
# The default controller will watch for AppService objects and create a pod for each CR | ||
$ kubectl create -f deploy/crds/app_v1alpha1_nginx_cr.yaml | ||
# Verify that a pod is created | ||
$ kubectl get pod -l app=example-nginx | ||
NAME READY STATUS RESTARTS AGE | ||
example-nginx-pod 1/1 Running 0 1m | ||
``` | ||
|
||
To create an operator from an *external* helm chart: | ||
## Supported Kubernetes Resources | ||
--- | ||
The tool currently supports a very limited selection of Kubernetes resources, as listed here: | ||
``` | ||
go run main.go convert <OperatorName> --helm-chart-repo=https://charts.example.io/ --helm-chart=example-chart --kind=Kind --api-version=apps.example.com/v1alpha1 | ||
Role | ||
ClusterRole | ||
RoleBinding | ||
ClusterRoleBinding | ||
ServiceAccount | ||
Service | ||
Deployment | ||
``` | ||
If attempting to parse a Kubernetes resource other than the ones listed above the tool will prompt the user to either `continue` code generation without the unsupported resources or `stop` the code generation all together. | ||
|
||
|
||
## Common Problems | ||
--- | ||
If you are experiencing build errors: `go: error loading module requirements`, execute the following command `export GO111MODULES=off` within the operator folder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# CLI Guide | ||
|
||
**_Note:_** Binary has not yet been build. | ||
|
||
```terminal | ||
Usage: | ||
go run main.go [command] | ||
``` | ||
|
||
## convert | ||
--- | ||
Scaffolds a Go Operator for a corresponding Helm Chart. | ||
|
||
### Args | ||
* `operator-name` - name of the new operator | ||
|
||
### Flags | ||
* `--helm-chart` - Name of the helm chart. If using an external repo, specify the name within the repo i.e. `nginx`. If using a local chart provide `path/to/chart` | ||
* `--helm-chart-repo` - Specify external chart repo if necessary. | ||
* `--helm-chart-version` - Specify external chart version if necessary. | ||
* `--username` - Specify external repo username if necessary. | ||
* `--password` - Specify external repo password if necessary. | ||
* `--helm-chart-cert-file` - Specify Cert File for external repo if necessary. | ||
* `--helm-chart-key-file` - Specify Key File for external repo if necessary. | ||
* `--helm-chart-ca-file` - Specify CA File for external repo if necessary. | ||
* `--api-version` - Kubernetes API Version and has a format of `<groupName>/<version>` i.e. `app.example.com/v1alpha1` | ||
* `--kind` - Kubernetes Custom Resource Definition kind. | ||
* `--cluster-scoped` - Operator cluster scoped or not. | ||
|
||
### Example | ||
``` | ||
$ go run main.go convert nginx-operator --helm-chart=path/to/chart --api-version=web.example.com/v1alpha1 --kind=Nginx | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
![alt text](design.png) | ||
|
||
## Design | ||
|
||
### Render | ||
Render handles the primary steps in the Helm to Go Kubernetes pathway. The main responsibility of this package is to render valid Helm charts. Additionally, the package can write the injected files to a specified temp directory. | ||
|
||
### Convert | ||
Convert handles the secondary steps in the Helm to Go Kubernetes pathway. The main responsibility of this package is the unmarshal the rendered YAML files and produce raw Kubernetes resources. | ||
|
||
The file `pkg/convert/convert.go` contains the main logic to accomplish the conversion itself. `YAMLUnmarshalResources` receives an absolute path to a directory and simply unmarshals all resource files one at a time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.