Skip to content

Commit

Permalink
Merge pull request #83 from jonstacks/issue-55
Browse files Browse the repository at this point in the history
Add Helm Common Values
  • Loading branch information
jonstacks authored Dec 19, 2022
2 parents 20538c2 + 9ccfe47 commit cb8bd16
Show file tree
Hide file tree
Showing 29 changed files with 689 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `ngrok-ingress-controller-${tag}`,
name: tag,
name: `ngrok-ingress-controller-${tag}`,
body: `${tag}`,
draft: false,
prerelease: false
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ KUSTOMIZE = go run sigs.k8s.io/kustomize/kustomize/v3

ENVTEST = go run sigs.k8s.io/controller-runtime/tools/setup-envtest

HELM_CHART_DIR = ./helm/ingress-controller

# Targets

.PHONY: all
Expand Down Expand Up @@ -107,7 +109,7 @@ uninstall: manifests ## Uninstall CRDs from the K8s cluster specified in ~/.kube

.PHONY: deploy
deploy: docker-build manifests ## Deploy controller to the K8s cluster specified in ~/.kube/config.
helm upgrade ngrok-ingress-controller helm/ingress-controller --install \
helm upgrade ngrok-ingress-controller $(HELM_CHART_DIR) --install \
--namespace ngrok-ingress-controller \
--create-namespace \
--set podAnnotations."k8s\.ngrok\.com/test"="\{\"env\": \"local\"\}" \
Expand All @@ -121,9 +123,14 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi

.PHONY: helm-lint
helm-lint: ## Lint the helm chart
helm lint helm/ingress-controller
helm lint $(HELM_CHART_DIR)

.PHONY: helm-test
helm-test: ## Run helm unittest plugin
./scripts/helm-setup.sh
cd helm/ingress-controller && helm unittest --helm3 .
helm unittest --helm3 $(HELM_CHART_DIR)

.PHONY: helm-update-snapshots
helm-update-snapshots: ## Update helm unittest snapshots
./scripts/helm-setup.sh
helm unittest --helm3 -u $(HELM_CHART_DIR)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ data:
## How to Configure the Agent
> Warning: This will be deprecated soon when moving to the new lib-ngrok library
* assumes configs will be in a config map named `ngrok-ingress-controller-agent-cm` in the same namespace
* assumes configs will be in a config map named `{{ include "ngrok-ingress-controller.fullname" . }}-agent-cm` in the same namespace
* setup automatically via helm. Values and config map name can be configured in the future via helm
* subset of these that should be configurable https://ngrok.com/docs/ngrok-agent/config#config-full-example
* example config map showing all optional values with their defaults.
Expand All @@ -135,7 +135,7 @@ data:
apiVersion: v1
kind: ConfigMap
metadata:
name: ngrok-ingress-controller-agent-cm
name: {{ include "ngrok-ingress-controller.fullname" . }}-agent-cm
namespace: ngrok-ingress-controller
data:
LOG: stdout
Expand Down
14 changes: 7 additions & 7 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func main() {

type managerOpts struct {
// flags
metricsAddr string
enableLeaderElection bool
probeAddr string
zapOpts *zap.Options
metricsAddr string
electionID string
probeAddr string
zapOpts *zap.Options

// env vars
namespace string
Expand All @@ -77,7 +77,7 @@ func cmd() *cobra.Command {

c.Flags().StringVar(&opts.metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to")
c.Flags().StringVar(&opts.probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
c.Flags().BoolVar(&opts.enableLeaderElection, "leader-elect", false, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
c.Flags().StringVar(&opts.electionID, "election-id", "ngrok-ingress-controller-leader", "The name of the configmap that is used for holding the leader lock")
c.Flags().StringVar(&opts.region, "region", "us", "The region to use for ngrok tunnels")
opts.zapOpts = &zap.Options{Development: true}
goFlagSet := flag.NewFlagSet("manager", flag.ContinueOnError)
Expand Down Expand Up @@ -111,8 +111,8 @@ func runController(ctx context.Context, opts managerOpts) error {
MetricsBindAddress: opts.metricsAddr,
Port: 9443,
HealthProbeBindAddress: opts.probeAddr,
LeaderElection: true,
LeaderElectionID: "ngrok-ingress-controller-leader",
LeaderElection: opts.electionID != "",
LeaderElectionID: opts.electionID,
})
if err != nil {
return fmt.Errorf("unable to start manager: %w", err)
Expand Down
14 changes: 13 additions & 1 deletion helm/ingress-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.2.0
### Added

- Support for different values commonly found in helm charts

# 0.1.0

TODO
TODO
2 changes: 1 addition & 1 deletion helm/ingress-controller/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: ngrok-ingress-controller
description: A Kubernetes ingress controller built using ngrok.
version: 0.1.2
version: 0.2.0
appVersion: 0.1.0
keywords:
- ngrok
Expand Down
47 changes: 32 additions & 15 deletions helm/ingress-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,38 @@ To uninstall the chart:
<!-- Parameters are auto generated via @bitnami/readme-generator-for-helm -->
## Parameters

### Common parameters

| Name | Description | Value |
| ------------------- | ----------------------------------------------------- | ----- |
| `nameOverride` | String to partially override generated resource names | `""` |
| `fullnameOverride` | String to fully override generated resource names | `""` |
| `commonLabels` | Labels to add to all deployed objects | `{}` |
| `commonAnnotations` | Annotations to add to all deployed objects | `{}` |


### Controller parameters

| Name | Description | Value |
| ------------------------ | ----------------------------------------------- | -------------------------------------- |
| `podAnnotations` | Used to inject custom annotations directly into | `{}` |
| `replicaCount` | The number of controllers and agents to run. | `2` |
| `image.repository` | The ngrok ingress controller image repository. | `ngrok/ngrok-ingress-controller` |
| `image.tag` | The ngrok ingress controller image tag. | `latest` |
| `image.pullPolicy` | The ngrok ingress controller image pull policy. | `IfNotPresent` |
| `ingressClass` | The ingress class this controller will satisfy. | `ngrok` |
| `log` | Agent log destination. | `stdout` |
| `region` | ngrok region to create tunnels in. | `us` |
| `credentialsSecret.name` | The name of the K8S secret that contains the | `ngrok-ingress-controller-credentials` |
| `apiKey` | The ngrok API key to use | `""` |
| `authtoken` | The ngrok auth token to use | `""` |
| `resources.limits` | The resources limits for the container | `{}` |
| `resources.requests` | The requested resources for the container | `{}` |
| Name | Description | Value |
| ---------------------------- | --------------------------------------------------------------- | -------------------------------------- |
| `podAnnotations` | Used to inject custom annotations directly into | `{}` |
| `replicaCount` | The number of controllers and agents to run. | `2` |
| `image.registry` | The ngrok ingress controller image registry. | `docker.io` |
| `image.repository` | The ngrok ingress controller image repository. | `ngrok/ngrok-ingress-controller` |
| `image.tag` | The ngrok ingress controller image tag. | `latest` |
| `image.pullPolicy` | The ngrok ingress controller image pull policy. | `IfNotPresent` |
| `image.pullSecrets` | An array of imagePullSecrets to be used when pulling the image. | `[]` |
| `ingressClass.name` | The name of the ingress class to use. | `ngrok` |
| `ingressClass.create` | Whether to create the ingress class. | `true` |
| `ingressClass.default` | Whether to set the ingress class as default. | `true` |
| `log` | Agent log destination. | `stdout` |
| `region` | ngrok region to create tunnels in. | `us` |
| `credentialsSecret.name` | The name of the K8S secret that contains the | `ngrok-ingress-controller-credentials` |
| `apiKey` | The ngrok API key to use | `""` |
| `authtoken` | The ngrok auth token to use | `""` |
| `resources.limits` | The resources limits for the container | `{}` |
| `resources.requests` | The requested resources for the container | `{}` |
| `serviceAccount.create` | Specifies whether a ServiceAccount should be created | `true` |
| `serviceAccount.name` | The name of the ServiceAccount to use. | `""` |
| `serviceAccount.annotations` | Additional annotations to add to the ServiceAccount | `{}` |

76 changes: 76 additions & 0 deletions helm/ingress-controller/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "ngrok-ingress-controller.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "ngrok-ingress-controller.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "ngrok-ingress-controller.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "ngrok-ingress-controller.labels" -}}
helm.sh/chart: {{ include "ngrok-ingress-controller.chart" . }}
{{ include "ngrok-ingress-controller.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/part-of: {{ template "ngrok-ingress-controller.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.commonLabels}}
{{ toYaml .Values.commonLabels }}
{{- end }}
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "ngrok-ingress-controller.selectorLabels" -}}
app.kubernetes.io/name: {{ include "ngrok-ingress-controller.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*
Create the name of the controller service account to use
*/}}
{{- define "ngrok-ingress-controller.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "ngrok-ingress-controller.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Return the ngrok/ingress-controller image name
*/}}
{{- define "ngrok-ingress-controller.image" -}}
{{- $registryName := .Values.image.registry -}}
{{- $repositoryName := .Values.image.repository -}}
{{- $tag := .Values.image.tag | toString -}}
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
{{- end -}}
2 changes: 1 addition & 1 deletion helm/ingress-controller/templates/agent-config-cm.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: ngrok-ingress-controller-agent-cm
name: {{ include "ngrok-ingress-controller.fullname" . }}-agent-cm
namespace: {{ .Release.Namespace }}
data:
LOG: "{{ .Values.log }}"
Expand Down
5 changes: 2 additions & 3 deletions helm/ingress-controller/templates/controller-cm.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: ngrok-ingress-controller-manager-config
name: {{ include "ngrok-ingress-controller.fullname" . }}-manager-config
namespace: {{ .Release.Namespace }}
data:
controller_manager_config.yaml: |
Expand All @@ -13,5 +13,4 @@ data:
bindAddress: 127.0.0.1:8080
leaderElection:
leaderElect: true
resourceName: ngrok-ingress-controller-leader
resourceName: {{ include "ngrok-ingress-controller.fullname" . }}-leader
23 changes: 15 additions & 8 deletions helm/ingress-controller/templates/controller-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: ngrok-ingress-controller
name: ngrok-ingress-controller-manager
{{- include "ngrok-ingress-controller.labels" . | nindent 4 }}
app.kubernetes.io/component: controller
name: {{ include "ngrok-ingress-controller.fullname" . }}-manager
namespace: {{ .Release.Namespace }}
annotations:
checksum/agent-config: {{ include (print $.Template.BasePath "/agent-config-cm.yaml") . | sha256sum }}
Expand All @@ -13,7 +14,8 @@ spec:
replicas: {{.Values.replicaCount}}
selector:
matchLabels:
app: ngrok-ingress-controller
{{- include "ngrok-ingress-controller.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: controller
template:
metadata:
annotations:
Expand All @@ -25,24 +27,29 @@ spec:
prometheus.io/port: '8080'
prometheus.io/scrape: 'true'
labels:
app: ngrok-ingress-controller
{{- include "ngrok-ingress-controller.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: controller
spec:
serviceAccountName: ngrok-ingress-controller-manager
serviceAccountName: {{ template "ngrok-ingress-controller.serviceAccountName" . }}
{{- if .Values.image.pullSecrets }}
imagePullSecrets:
{{- toYaml .Values.image.pullSecrets | nindent 8 }}
{{- end }}
volumes:
- name: scripts
configMap:
name: scripts
defaultMode: 0755
containers:
- name: ngrok-ingress-controller
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
image: {{ include "ngrok-ingress-controller.image" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /manager
args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=:8080
- --leader-elect
- --election-id={{ include "ngrok-ingress-controller.fullname" . }}-leader
{{- if .Values.region }}
- --region={{ .Values.region}}
{{- end }}
Expand Down Expand Up @@ -78,7 +85,7 @@ spec:
- ./scripts/gen-agent-config.sh
envFrom:
- configMapRef:
name: ngrok-ingress-controller-agent-cm
name: {{ include "ngrok-ingress-controller.fullname" . }}-agent-cm
optional: true
env:
- name: NGROK_AUTHTOKEN
Expand Down
12 changes: 3 additions & 9 deletions helm/ingress-controller/templates/controller-rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: ngrok-ingress-controller-manager
namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand Down Expand Up @@ -72,7 +66,7 @@ roleRef:
name: ngrok-ingress-controller-leader-election-role
subjects:
- kind: ServiceAccount
name: ngrok-ingress-controller-manager
name: {{ template "ngrok-ingress-controller.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
Expand All @@ -85,7 +79,7 @@ roleRef:
name: ngrok-ingress-controller-manager-role
subjects:
- kind: ServiceAccount
name: ngrok-ingress-controller-manager
name: {{ template "ngrok-ingress-controller.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
Expand All @@ -98,5 +92,5 @@ roleRef:
name: ngrok-ingress-controller-proxy-role
subjects:
- kind: ServiceAccount
name: ngrok-ingress-controller-manager
name: {{ template "ngrok-ingress-controller.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
15 changes: 15 additions & 0 deletions helm/ingress-controller/templates/controller-serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- if .Values.serviceAccount.create -}}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "ngrok-ingress-controller.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "ngrok-ingress-controller.labels" . | nindent 4 }}
app.kubernetes.io/component: controller
{{- if .Values.serviceAccount.annotations }}
annotations:
{{- toYaml .Values.serviceAccount.annotations | nindent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit cb8bd16

Please sign in to comment.