Skip to content

Commit

Permalink
finishing advanced feature ngrok repetition 1
Browse files Browse the repository at this point in the history
  • Loading branch information
zufardhiyaulhaq committed Jul 16, 2020
1 parent 032eaff commit f2b87a7
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 13 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
Ngrok operator provide developer easy access to private Kubernetes cluster for testing purpose via ngrok. Automate the creation of ngrok tunnel via CRDs!

### Feature
- [x] basic ngrok feature
- [x] support HTTP
- [ ] support TCP
- [ ] support Costum Configuration
- [x] support TCP
- [x] support costum configuration
- [x] custom domain
- [x] custom TCP address
- [x] custom region
- [x] enable/disable inspection
- [x] support HTTP auth
- [ ] service for ngrok object (dashboard related)

### Developing ngrok-operator
This operator build based on [operator-sdk](https://sdk.operatorframework.io/docs/install-operator-sdk/). To build this operator, you need [operator-sdk](https://sdk.operatorframework.io/docs/install-operator-sdk/).
Expand Down Expand Up @@ -38,11 +43,13 @@ kubectl apply -f examples/helloworld/
```
kubectl get ngrok --all-namespaces
NAMESPACE NAME STATUS URL
default nginx-ngrok created https://d5150f7c3588.ngrok.io
helloworld helloworld-ngrok created https://fa03f71fbe18.ngrok.io
default nginx-ngrok created https://9496e56ed0bc.ngrok.io
default nginx-ngrok-full created https://ngrok.zufardhiyaulhaq.com
helloworld helloworld-ngrok created https://d00ba8cb0b95.ngrok.io
```
- access the URL
```
https://d5150f7c3588.ngrok.io
https://ngrok.zufardhiyaulhaq.com
https://fa03f71fbe18.ngrok.io/hello
```
4 changes: 2 additions & 2 deletions charts/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
apiVersion: v1
name: ngrok-operator
type: application
version: 0.0.1
appVersion: 0.0.1
version: 0.0.2
appVersion: 0.0.2
description: ngrok-operator for managing ngrok lifecycle
home: https://github.com/zufardhiyaulhaq/ngrok-operator
keywords:
Expand Down
4 changes: 2 additions & 2 deletions charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Helm chart for ngrok-operators
### Installing the charts
From root directory of ngrok-operator. Please edit the values.yaml inside charts before applying.
```
helm install ./charts --name ngrok-operator
helm install ./charts --name-template ngrok-operator
```

### Configuration

| Parameter | Description | Default |
|-|-| -|
| operator.image | Image for ngrok-operator | zufardhiyaulhaq/ngrok-operator |
| operator.tag | Tag for image ngrok-operator | 0.0.1 |
| operator.tag | Tag for image ngrok-operator | 0.0.2 |
| operator.pullPolicy | pullPolicy | Always |
| operator.replica | number of replica | 1 |

Expand Down
27 changes: 27 additions & 0 deletions charts/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,36 @@ spec:
spec:
description: NgrokSpec defines the desired state of Ngrok
properties:
auth:
type: string
authtoken:
type: string
hostname:
type: string
inspect:
default: false
type: boolean
port:
format: int32
type: integer
protocol:
default: http
enum:
- http
- tcp
type: string
region:
enum:
- us
- eu
- ap
- au
- sa
- jp
- in
type: string
remote_addr:
type: string
service:
type: string
required:
Expand Down
2 changes: 1 addition & 1 deletion charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ operator:
# image of ngrok-operator
image: "zufardhiyaulhaq/ngrok-operator"
# tag of ngrok-operator image
tag: "0.0.1"
tag: "0.0.2"
# pullPolicy for operator image
pullPolicy: "Always"
# number of replica for deployment
Expand Down
17 changes: 17 additions & 0 deletions deploy/crds/ngrok.com_ngroks_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ spec:
spec:
description: NgrokSpec defines the desired state of Ngrok
properties:
auth:
type: string
authtoken:
type: string
hostname:
type: string
inspect:
default: false
type: boolean
port:
format: int32
type: integer
Expand All @@ -53,6 +58,18 @@ spec:
- http
- tcp
type: string
region:
enum:
- us
- eu
- ap
- au
- sa
- jp
- in
type: string
remote_addr:
type: string
service:
type: string
required:
Expand Down
6 changes: 6 additions & 0 deletions examples/helloworld/ngrok.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ metadata:
name: helloworld-ngrok
namespace: helloworld
spec:
# protocol used, currently support http & tcp
# tcp is less tested, please create issue
# default is http
protocol: http

# service section represent
# the service name in the same namespace
service: helloworld-service

# port section represent
# the service port in the same namespace
port: 5000
20 changes: 20 additions & 0 deletions examples/http-full-configuration/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
spec:
selector:
matchLabels:
run: nginx
replicas: 1
template:
metadata:
labels:
run: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
41 changes: 41 additions & 0 deletions examples/http-full-configuration/ngrok.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: ngrok.com/v1alpha1
kind: Ngrok
metadata:
name: nginx-ngrok-full
namespace: default
spec:
# ngrok authtoken
authtoken: your-auth-token

# protocol used, currently support http & tcp
# tcp is less tested, please create issue
# if there is an issue with tcp
protocol: http

# region where ngrok run
# refer to the docs
# https://ngrok.com/docs
region: ap

# auth protect your http
# with user password combination
# <user>:<password>
auth: user:password

# enable inspection
# only works for http protocol
inspect: true

# this supported starting with basic plan
# using custom hostname require to set authtoken
# the behaviour when set `hostname` with free account
# is unknown!
hostname: ngrok.zufardhiyaulhaq.com

# service section represent
# the service name in the same namespace
service: nginx-service

# port section represent
# the service port in the same namespace
port: 80
11 changes: 11 additions & 0 deletions examples/http-full-configuration/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: default
spec:
ports:
- port: 80
protocol: TCP
selector:
run: nginx
6 changes: 6 additions & 0 deletions examples/nginx/ngrok.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ metadata:
name: nginx-ngrok
namespace: default
spec:
# protocol used, currently support http & tcp
# tcp is less tested, please create issue
# default is http
protocol: http

# service section represent
# the service name in the same namespace
service: nginx-service

# port section represent
# the service port in the same namespace
port: 80
14 changes: 14 additions & 0 deletions pkg/apis/ngrok/v1alpha1/ngrok_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,22 @@ type NgrokSpec struct {
// +optional
AuthToken string `json:"authtoken"`

// +optional
Auth string `json:"auth"`

// +optional
Hostname string `json:"hostname"`

// +optional
RemoteAddr string `json:"remote_addr"`

// +kubebuilder:validation:Enum=us;eu;ap;au;sa;jp;in
// +optional
Region string `json:"region"`

// +kubebuilder:default:=false
// +optional
Inspect bool `json:"inspect"`
}

// NgrokStatus defines the observed state of Ngrok
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/ngrok/ngrok_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (r *ReconcileNgrok) Reconcile(request reconcile.Request) (reconcile.Result,

bodyString := string(body)

matcher, err := regexp.Compile(`https(.*?)io`)
matcher, err := regexp.Compile(`https://.[^"]+`)
if err != nil {
return reconcile.Result{}, err
}
Expand Down Expand Up @@ -235,7 +235,7 @@ func newNgrokPod(cr *ngrokv1alpha1.Ngrok) *corev1.Pod {
{
Name: "ngrok",
Image: "wernight/ngrok",
Command: []string{"ngrok", "--config", "/ngrok/ngrok.conf", "--all"},
Command: []string{"ngrok", "start", "--config", "/ngrok/ngrok.conf", "--all"},
Ports: []corev1.ContainerPort{
{ContainerPort: ngrokPort},
},
Expand Down Expand Up @@ -265,7 +265,7 @@ func newNgrokPod(cr *ngrokv1alpha1.Ngrok) *corev1.Pod {

func generateConfiguration(cr *ngrokv1alpha1.Ngrok) string {
var output bytes.Buffer
tmpl := "template/configuration.tmpl"
tmpl := "templates/configuration.tmpl"

tpl, err := template.ParseFiles(tmpl)
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions templates/configuration.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,29 @@ web_addr: 0.0.0.0:4040
authtoken: {{ .Spec.AuthToken }}
{{end}}

{{if .Spec.Region }}
region: {{ .Spec.Region }}
{{end}}

tunnels:
app:
proto: {{ .Spec.Protocol }}
addr: {{ .Spec.Service }}:{{ .Spec.Port }}

{{if eq .Spec.Protocol "http"}}
inspect: {{ .Spec.Inspect }}

{{if .Spec.Auth }}
auth: {{ .Spec.Auth }}
{{ end }}

{{if .Spec.AuthToken }}{{if .Spec.Hostname }}
hostname: {{ .Spec.Hostname }}
{{end}}{{end}}
{{end}}

{{if eq .Spec.Protocol "tcp"}}
{{if .Spec.AuthToken }}{{if .Spec.Hostname }}
remote_addr: {{ .Spec.Hostname }}
{{end}}{{end}}
{{end}}

0 comments on commit f2b87a7

Please sign in to comment.