diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index f5d1a2f..d4d9b60 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -92,7 +92,12 @@ jobs: version: "${{ matrix.kubernetes }}" k3d-args: --no-lb - name: deploy charts - run: helm install ngrok-operator ./charts/ngrok-operator --values ./charts/ngrok-operator/values.yaml --set operator.tag=latest - - run: sleep 30 - - name: check charts installed - run: kubectl get pod + run: helm install ngrok-operator ./charts/ngrok-operator --values ./charts/ngrok-operator/values.yaml --set operator.tag=dev-ci + - name: deploy applications + run: kubectl apply -f ./examples/deployment + - name: deploy ngrok + run: kubectl apply -f ./examples/http/simple + - name: waiting ngrok-operator to start + run: sleep 180 + - name: check ngrok object + run: kubectl get ngrok -A diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index aee5ec8..cb42944 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -84,6 +84,11 @@ jobs: k3d-args: --no-lb - name: deploy charts run: helm install ngrok-operator ./charts/ngrok-operator --values ./charts/ngrok-operator/values.yaml --set operator.tag=dev-ci - - run: sleep 30 - - name: check charts installed - run: kubectl get pod + - name: deploy applications + run: kubectl apply -f ./examples/deployment + - name: deploy ngrok + run: kubectl apply -f ./examples/http/simple + - name: waiting ngrok-operator to start + run: sleep 180 + - name: check ngrok object + run: kubectl get ngrok -A diff --git a/README.md b/README.md index 7f67e3e..3263e0c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Ngrok operator provide developer easy access to private Kubernetes cluster for testing purpose via ngrok. Automate the creation of ngrok tunnel via CRD and automatically reload ngrok session when expired! -![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.1.0](https://img.shields.io/badge/AppVersion-1.1.0-informational?style=flat-square) [![made with Go](https://img.shields.io/badge/made%20with-Go-brightgreen)](http://golang.org) [![Github master branch build](https://img.shields.io/github/workflow/status/zufardhiyaulhaq/ngrok-operator/Master)](https://github.com/zufardhiyaulhaq/ngrok-operator/actions/workflows/master.yml) [![GitHub issues](https://img.shields.io/github/issues/zufardhiyaulhaq/ngrok-operator)](https://github.com/zufardhiyaulhaq/ngrok-operator/issues) [![GitHub pull requests](https://img.shields.io/github/issues-pr/zufardhiyaulhaq/ngrok-operator)](https://github.com/zufardhiyaulhaq/ngrok-operator/pulls) +![Version: 1.1.0](https://img.shields.io/badge/Version-1.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.2.0](https://img.shields.io/badge/AppVersion-1.2.0-informational?style=flat-square) [![made with Go](https://img.shields.io/badge/made%20with-Go-brightgreen)](http://golang.org) [![Github master branch build](https://img.shields.io/github/workflow/status/zufardhiyaulhaq/ngrok-operator/Master)](https://github.com/zufardhiyaulhaq/ngrok-operator/actions/workflows/master.yml) [![GitHub issues](https://img.shields.io/github/issues/zufardhiyaulhaq/ngrok-operator)](https://github.com/zufardhiyaulhaq/ngrok-operator/issues) [![GitHub pull requests](https://img.shields.io/github/issues-pr/zufardhiyaulhaq/ngrok-operator)](https://github.com/zufardhiyaulhaq/ngrok-operator/pulls) ## Installing @@ -16,23 +16,22 @@ helm install my-release zufardhiyaulhaq/ngrok-operator --values values.yaml ## Usage 1. Apply some example ```console -kubectl apply -f examples/nginx -kubectl apply -f examples/helloworld/namespace.yaml -kubectl apply -f examples/helloworld/ +kubectl apply -f examples/deployment/ +kubectl apply -f examples/http/simple/ +kubectl apply -f examples/http/full-configuration/ ``` 2. Check ngrok object ```console kubectl get ngrok --all-namespaces -NAMESPACE NAME STATUS URL -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 +NAMESPACE NAME STATUS URL +default http-simple created https://9496e56ed0bc.ngrok.io +default http-full-configuration created https://ngrok.zufardhiyaulhaq.com ``` + 3. access the URL ```console https://d5150f7c3588.ngrok.io https://ngrok.zufardhiyaulhaq.com -https://fa03f71fbe18.ngrok.io/hello ``` ## Values @@ -41,5 +40,9 @@ https://fa03f71fbe18.ngrok.io/hello |-----|------|---------|-------------| | operator.image | string | `"zufardhiyaulhaq/ngrok-operator"` | | | operator.replica | int | `1` | | -| operator.tag | string | `"v1.1.0"` | | +| operator.tag | string | `"v1.2.0"` | | +| resources.limits.cpu | string | `"200m"` | | +| resources.limits.memory | string | `"100Mi"` | | +| resources.requests.cpu | string | `"100m"` | | +| resources.requests.memory | string | `"20Mi"` | | diff --git a/api/v1alpha1/ngrok_types.go b/api/v1alpha1/ngrok_types.go index 392207b..7949c6a 100644 --- a/api/v1alpha1/ngrok_types.go +++ b/api/v1alpha1/ngrok_types.go @@ -17,15 +17,19 @@ limitations under the License. package v1alpha1 import ( + "fmt" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // NgrokSpec defines the desired state of Ngrok type NgrokSpec struct { Service string `json:"service"` - Port int32 `json:"port"` + // +kubebuilder:validation:Minimum=1 + // +kubebuilder:validation:Maximum=65535 + Port int32 `json:"port"` - // +kubebuilder:validation:Enum=http;tcp + // +kubebuilder:validation:Enum=http;tcp;tls // +kubebuilder:default:=http // +optional Protocol string `json:"protocol"` @@ -38,29 +42,56 @@ type NgrokSpec struct { // +optional AuthTokenType string `json:"authtoken_type"` + // +kubebuilder:validation:Enum=us;eu;ap;au;sa;jp;in // +optional - Auth string `json:"auth"` + Region string `json:"region"` // +optional - Hostname string `json:"hostname"` + Auth string `json:"auth"` // +optional - RemoteAddr string `json:"remote_addr"` + HostHeader string `json:"host_header"` - // +kubebuilder:validation:Enum=us;eu;ap;au;sa;jp;in + // +kubebuilder:validation:Enum=true;false;both // +optional - Region string `json:"region"` + BindTLS string `json:"bind_tls"` // +kubebuilder:validation:Enum=true;false // +kubebuilder:default:=false // +optional Inspect bool `json:"inspect"` + // +optional + Hostname string `json:"hostname"` + + // +optional + RemoteAddr string `json:"remote_addr"` + // +kubebuilder:default:={image: zufardhiyaulhaq/ngrok} // +optional PodSpec PodSpec `json:"podSpec"` } +func (n *NgrokSpec) Validate() error { + if n.Protocol == "http" || n.Protocol == "tls" { + if n.Service == "" { + return fmt.Errorf("service invalid") + } + } + + if n.AuthToken == "" && n.Protocol == "tls" { + return fmt.Errorf("protocol TLS only available in pro") + } + + if n.Protocol == "tcp" { + if n.RemoteAddr == "" { + return fmt.Errorf("remote_addr invalid") + } + } + + return nil +} + type PodSpec struct { // +optional Image string `json:"image"` diff --git a/charts/ngrok-operator/Chart.yaml b/charts/ngrok-operator/Chart.yaml index 77beec5..5f10239 100644 --- a/charts/ngrok-operator/Chart.yaml +++ b/charts/ngrok-operator/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: ngrok-operator description: Ngrok operator provide developer easy access to private Kubernetes cluster for testing purpose via ngrok. Automate the creation of ngrok tunnel via CRD and automatically reload ngrok session when expired! -version: 1.0.0 -appVersion: 1.1.0 +version: 1.1.0 +appVersion: 1.2.0 type: application home: https://github.com/zufardhiyaulhaq/ngrok-operator diff --git a/charts/ngrok-operator/README.md b/charts/ngrok-operator/README.md index 7f67e3e..3263e0c 100644 --- a/charts/ngrok-operator/README.md +++ b/charts/ngrok-operator/README.md @@ -2,7 +2,7 @@ Ngrok operator provide developer easy access to private Kubernetes cluster for testing purpose via ngrok. Automate the creation of ngrok tunnel via CRD and automatically reload ngrok session when expired! -![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.1.0](https://img.shields.io/badge/AppVersion-1.1.0-informational?style=flat-square) [![made with Go](https://img.shields.io/badge/made%20with-Go-brightgreen)](http://golang.org) [![Github master branch build](https://img.shields.io/github/workflow/status/zufardhiyaulhaq/ngrok-operator/Master)](https://github.com/zufardhiyaulhaq/ngrok-operator/actions/workflows/master.yml) [![GitHub issues](https://img.shields.io/github/issues/zufardhiyaulhaq/ngrok-operator)](https://github.com/zufardhiyaulhaq/ngrok-operator/issues) [![GitHub pull requests](https://img.shields.io/github/issues-pr/zufardhiyaulhaq/ngrok-operator)](https://github.com/zufardhiyaulhaq/ngrok-operator/pulls) +![Version: 1.1.0](https://img.shields.io/badge/Version-1.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.2.0](https://img.shields.io/badge/AppVersion-1.2.0-informational?style=flat-square) [![made with Go](https://img.shields.io/badge/made%20with-Go-brightgreen)](http://golang.org) [![Github master branch build](https://img.shields.io/github/workflow/status/zufardhiyaulhaq/ngrok-operator/Master)](https://github.com/zufardhiyaulhaq/ngrok-operator/actions/workflows/master.yml) [![GitHub issues](https://img.shields.io/github/issues/zufardhiyaulhaq/ngrok-operator)](https://github.com/zufardhiyaulhaq/ngrok-operator/issues) [![GitHub pull requests](https://img.shields.io/github/issues-pr/zufardhiyaulhaq/ngrok-operator)](https://github.com/zufardhiyaulhaq/ngrok-operator/pulls) ## Installing @@ -16,23 +16,22 @@ helm install my-release zufardhiyaulhaq/ngrok-operator --values values.yaml ## Usage 1. Apply some example ```console -kubectl apply -f examples/nginx -kubectl apply -f examples/helloworld/namespace.yaml -kubectl apply -f examples/helloworld/ +kubectl apply -f examples/deployment/ +kubectl apply -f examples/http/simple/ +kubectl apply -f examples/http/full-configuration/ ``` 2. Check ngrok object ```console kubectl get ngrok --all-namespaces -NAMESPACE NAME STATUS URL -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 +NAMESPACE NAME STATUS URL +default http-simple created https://9496e56ed0bc.ngrok.io +default http-full-configuration created https://ngrok.zufardhiyaulhaq.com ``` + 3. access the URL ```console https://d5150f7c3588.ngrok.io https://ngrok.zufardhiyaulhaq.com -https://fa03f71fbe18.ngrok.io/hello ``` ## Values @@ -41,5 +40,9 @@ https://fa03f71fbe18.ngrok.io/hello |-----|------|---------|-------------| | operator.image | string | `"zufardhiyaulhaq/ngrok-operator"` | | | operator.replica | int | `1` | | -| operator.tag | string | `"v1.1.0"` | | +| operator.tag | string | `"v1.2.0"` | | +| resources.limits.cpu | string | `"200m"` | | +| resources.limits.memory | string | `"100Mi"` | | +| resources.requests.cpu | string | `"100m"` | | +| resources.requests.memory | string | `"20Mi"` | | diff --git a/charts/ngrok-operator/README.md.gotmpl b/charts/ngrok-operator/README.md.gotmpl index d7eba69..27b9212 100644 --- a/charts/ngrok-operator/README.md.gotmpl +++ b/charts/ngrok-operator/README.md.gotmpl @@ -15,23 +15,22 @@ helm install my-release zufardhiyaulhaq/ngrok-operator --values values.yaml ## Usage 1. Apply some example ```console -kubectl apply -f examples/nginx -kubectl apply -f examples/helloworld/namespace.yaml -kubectl apply -f examples/helloworld/ +kubectl apply -f examples/deployment/ +kubectl apply -f examples/http/simple/ +kubectl apply -f examples/http/full-configuration/ ``` 2. Check ngrok object ```console kubectl get ngrok --all-namespaces -NAMESPACE NAME STATUS URL -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 +NAMESPACE NAME STATUS URL +default http-simple created https://9496e56ed0bc.ngrok.io +default http-full-configuration created https://ngrok.zufardhiyaulhaq.com ``` + 3. access the URL ```console https://d5150f7c3588.ngrok.io https://ngrok.zufardhiyaulhaq.com -https://fa03f71fbe18.ngrok.io/hello ``` {{ template "chart.requirementsSection" . }} diff --git a/charts/ngrok-operator/crds/crds.yaml b/charts/ngrok-operator/crds/crds.yaml index 4c6aad7..8867e33 100644 --- a/charts/ngrok-operator/crds/crds.yaml +++ b/charts/ngrok-operator/crds/crds.yaml @@ -55,6 +55,14 @@ spec: - plain - secret type: string + bind_tls: + enum: + - true + - false + - both + type: string + host_header: + type: string hostname: type: string inspect: @@ -72,12 +80,15 @@ spec: type: object port: format: int32 + maximum: 65535 + minimum: 1 type: integer protocol: default: http enum: - http - tcp + - tls type: string region: enum: diff --git a/charts/ngrok-operator/values.yaml b/charts/ngrok-operator/values.yaml index e253c55..6fca7f1 100644 --- a/charts/ngrok-operator/values.yaml +++ b/charts/ngrok-operator/values.yaml @@ -2,7 +2,7 @@ operator: # image of ngrok-operator image: "zufardhiyaulhaq/ngrok-operator" # tag of ngrok-operator image - tag: "v1.1.0" + tag: "v1.2.0" # number of replica for deployment replica: 1 diff --git a/charts/releases/ngrok-operator-1.1.0.tgz b/charts/releases/ngrok-operator-1.1.0.tgz new file mode 100644 index 0000000..3633309 Binary files /dev/null and b/charts/releases/ngrok-operator-1.1.0.tgz differ diff --git a/config/crd/bases/ngrok.com_ngroks.yaml b/config/crd/bases/ngrok.com_ngroks.yaml index 4c6aad7..8867e33 100644 --- a/config/crd/bases/ngrok.com_ngroks.yaml +++ b/config/crd/bases/ngrok.com_ngroks.yaml @@ -55,6 +55,14 @@ spec: - plain - secret type: string + bind_tls: + enum: + - true + - false + - both + type: string + host_header: + type: string hostname: type: string inspect: @@ -72,12 +80,15 @@ spec: type: object port: format: int32 + maximum: 65535 + minimum: 1 type: integer protocol: default: http enum: - http - tcp + - tls type: string region: enum: diff --git a/controllers/ngrok_controller.go b/controllers/ngrok_controller.go index 14b18e1..74339c0 100644 --- a/controllers/ngrok_controller.go +++ b/controllers/ngrok_controller.go @@ -93,7 +93,7 @@ func (r *NgrokReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl } log.Info("Build configuration") - configuration, err := builder.NewNgrokConfigurationBuilder(r.Client). + configuration, err := builder.NewNgrokConfigurationBuilder(). SetSpec(spec). Build() if err != nil { diff --git a/examples/authtoken-secret/ngrok.yaml b/examples/authtoken-secret/ngrok.yaml deleted file mode 100644 index bdbcba5..0000000 --- a/examples/authtoken-secret/ngrok.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: ngrok.com/v1alpha1 -kind: Ngrok -metadata: - name: ngrok-authtoken-secret - namespace: default -spec: - # ngrok authtoken - authtoken: authtoken-secret - - # ngrok authotken - authtoken_type: secret - - # 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 diff --git a/examples/authtoken-secret/deployment.yaml b/examples/deployment/deployment.yaml similarity index 100% rename from examples/authtoken-secret/deployment.yaml rename to examples/deployment/deployment.yaml diff --git a/examples/authtoken-secret/service.yaml b/examples/deployment/service.yaml similarity index 100% rename from examples/authtoken-secret/service.yaml rename to examples/deployment/service.yaml diff --git a/examples/helloworld/deployment.yaml b/examples/helloworld/deployment.yaml deleted file mode 100644 index 442d5a5..0000000 --- a/examples/helloworld/deployment.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: helloworld-deployment - namespace: helloworld -spec: - selector: - matchLabels: - run: helloworld - replicas: 1 - template: - metadata: - labels: - run: helloworld - spec: - containers: - - name: helloworld - image: docker.io/istio/examples-helloworld-v1 - ports: - - containerPort: 80 diff --git a/examples/helloworld/namespace.yaml b/examples/helloworld/namespace.yaml deleted file mode 100644 index 7dd7b3e..0000000 --- a/examples/helloworld/namespace.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: helloworld diff --git a/examples/helloworld/ngrok.yaml b/examples/helloworld/ngrok.yaml deleted file mode 100644 index 17db168..0000000 --- a/examples/helloworld/ngrok.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: ngrok.com/v1alpha1 -kind: Ngrok -metadata: - name: ngrok-helloworld - 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 diff --git a/examples/helloworld/service.yaml b/examples/helloworld/service.yaml deleted file mode 100644 index f2d55c9..0000000 --- a/examples/helloworld/service.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: helloworld-service - namespace: helloworld -spec: - ports: - - port: 5000 - protocol: TCP - selector: - run: helloworld diff --git a/examples/http-full-configuration/deployment.yaml b/examples/http-full-configuration/deployment.yaml deleted file mode 100644 index 5398d5f..0000000 --- a/examples/http-full-configuration/deployment.yaml +++ /dev/null @@ -1,20 +0,0 @@ -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 diff --git a/examples/http-full-configuration/service.yaml b/examples/http-full-configuration/service.yaml deleted file mode 100644 index 91a16dc..0000000 --- a/examples/http-full-configuration/service.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: nginx-service - namespace: default -spec: - ports: - - port: 80 - protocol: TCP - selector: - run: nginx diff --git a/examples/nginx/ngrok.yaml b/examples/http/authtoken-secret/ngrok.yaml similarity index 75% rename from examples/nginx/ngrok.yaml rename to examples/http/authtoken-secret/ngrok.yaml index c7514b2..57b3c50 100644 --- a/examples/nginx/ngrok.yaml +++ b/examples/http/authtoken-secret/ngrok.yaml @@ -1,18 +1,24 @@ apiVersion: ngrok.com/v1alpha1 kind: Ngrok metadata: - name: nginx-ngrok + name: http-authtoken-secret namespace: default spec: # protocol used, currently support http & tcp # tcp is less tested, please create issue # default is http protocol: http + + # ngrok authtoken + authtoken: authtoken-secret + + # ngrok authotken + authtoken_type: secret # 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 diff --git a/examples/authtoken-secret/secret.yaml b/examples/http/authtoken-secret/secret.yaml similarity index 100% rename from examples/authtoken-secret/secret.yaml rename to examples/http/authtoken-secret/secret.yaml diff --git a/examples/http-full-configuration/ngrok.yaml b/examples/http/full-configuration/ngrok.yaml similarity index 87% rename from examples/http-full-configuration/ngrok.yaml rename to examples/http/full-configuration/ngrok.yaml index 0150387..b866900 100644 --- a/examples/http-full-configuration/ngrok.yaml +++ b/examples/http/full-configuration/ngrok.yaml @@ -1,7 +1,7 @@ apiVersion: ngrok.com/v1alpha1 kind: Ngrok metadata: - name: ngrok-full-configuration + name: http-full-configuration namespace: default spec: # ngrok authtoken @@ -21,6 +21,12 @@ spec: # https://ngrok.com/docs region: ap + # Rewrite the HTTP Host header to this value + host_header: "foo.bar" + + # bind an HTTPS or HTTP endpoint or both + bind_tls: both + # auth protect your http # with user password combination # : diff --git a/examples/http/simple/ngrok.yaml b/examples/http/simple/ngrok.yaml new file mode 100644 index 0000000..18c11c9 --- /dev/null +++ b/examples/http/simple/ngrok.yaml @@ -0,0 +1,57 @@ +apiVersion: ngrok.com/v1alpha1 +kind: Ngrok +metadata: + name: http-simple + 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 +--- +apiVersion: ngrok.com/v1alpha1 +kind: Ngrok +metadata: + name: http-free-full-config + namespace: default +spec: + # 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 + + # Rewrite the HTTP Host header to this value + host_header: "foo.bar" + + # bind an HTTPS or HTTP endpoint or both + bind_tls: both + + # enable inspection + # only works for http protocol + inspect: true + + # 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 + + # define the image for the ngrok + # default to zufardhiyaulhaq/ngrok:latest + podSpec: + image: zufardhiyaulhaq/ngrok diff --git a/examples/nginx/deployment.yaml b/examples/nginx/deployment.yaml deleted file mode 100644 index 5398d5f..0000000 --- a/examples/nginx/deployment.yaml +++ /dev/null @@ -1,20 +0,0 @@ -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 diff --git a/examples/nginx/service.yaml b/examples/nginx/service.yaml deleted file mode 100644 index 91a16dc..0000000 --- a/examples/nginx/service.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: nginx-service - namespace: default -spec: - ports: - - port: 80 - protocol: TCP - selector: - run: nginx diff --git a/go.mod b/go.mod index 3b437d6..ebed4d7 100644 --- a/go.mod +++ b/go.mod @@ -14,10 +14,12 @@ require ( github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc // indirect github.com/golangci/prealloc v0.0.0-20180630174525-215b22d4de21 // indirect github.com/klauspost/cpuid v1.2.0 // indirect + github.com/norwoodj/helm-docs v1.6.0 // indirect github.com/onsi/ginkgo v1.16.4 github.com/onsi/gomega v1.13.0 github.com/shirou/gopsutil v0.0.0-20180427012116-c95755e4bcd7 // indirect github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect + github.com/stretchr/testify v1.7.0 // indirect golang.org/x/tools v0.1.3 // indirect gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect diff --git a/go.sum b/go.sum index 9308a71..26de4e7 100644 --- a/go.sum +++ b/go.sum @@ -57,11 +57,14 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rWPdisA5ynNEsoARbiCBOyGcJM4/OzsM= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= +github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg= github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/sprig v2.15.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= +github.com/Masterminds/sprig v2.20.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= +github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60= github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= @@ -351,6 +354,7 @@ github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254/go.mod h1: github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75/go.mod h1:g2644b03hfBX9Ov0ZBDgXXens4rxSxmqFBbhvKv2yVA= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE= @@ -402,10 +406,12 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo= +github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0= github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.4/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= @@ -520,6 +526,7 @@ github.com/miekg/dns v1.1.35/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7 github.com/miekg/pkcs11 v1.0.2/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -532,6 +539,7 @@ github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:F github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY70sEEpE= github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc= @@ -566,6 +574,8 @@ github.com/nishanths/exhaustive v0.1.0/go.mod h1:S1j9110vxV1ECdCudXRkeMnFQ/DQk9a github.com/nishanths/predeclared v0.0.0-20190419143655-18a43bb90ffc/go.mod h1:62PewwiQTlm/7Rj+cxVYqZvDIUc+JjZq6GHAC1fsObQ= github.com/nishanths/predeclared v0.2.1 h1:1TXtjmy4f3YCFjTxRd8zcFHOmoUir+gp0ESzjFzG2sw= github.com/nishanths/predeclared v0.2.1/go.mod h1:HvkGJcA3naj4lOwnFXFDkFxVtSqQMB9sbB1usJ+xjQE= +github.com/norwoodj/helm-docs v1.6.0 h1:EH2vShsTEsQ0gjvWsrofYV5ylb9p6LdX7LCIvkkFdFA= +github.com/norwoodj/helm-docs v1.6.0/go.mod h1:z8Evt7esakCuqMKuwpVAAp4NyHgQbH3iGWsGmLuBcV0= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -706,6 +716,7 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk= github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= @@ -743,6 +754,7 @@ github.com/tomarrell/wrapcheck/v2 v2.1.0/go.mod h1:crK5eI4RGSUrb9duDTQ5GqcukbKZv github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4= github.com/tommy-muehle/go-mnd/v2 v2.4.0 h1:1t0f8Uiaq+fqKteUR4N9Umr6E99R+lDnLnq7PwX2PPE= github.com/tommy-muehle/go-mnd/v2 v2.4.0/go.mod h1:WsUAkMJMYww6l/ufffCD3m+P7LEvr8TnZn9lwVDlgzw= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ultraware/funlen v0.0.3 h1:5ylVWm8wsNwH5aWo9438pwvsK0QiqVuUrt9bn7S/iLA= github.com/ultraware/funlen v0.0.3/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA= @@ -864,6 +876,7 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -1157,6 +1170,7 @@ google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a/go.mod h1:FWY/as6D google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= @@ -1244,6 +1258,8 @@ k8s.io/component-base v0.21.2 h1:EsnmFFoJ86cEywC0DoIkAUiEV6fjgauNugiw1lmIjs4= k8s.io/component-base v0.21.2/go.mod h1:9lvmIThzdlrJj5Hp8Z/TOgIkdfsNARQ1pT+3PByuiuc= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/helm v2.14.3+incompatible h1:uzotTcZXa/b2SWVoUzM1xiCXVjI38TuxMujS/1s+3Gw= +k8s.io/helm v2.14.3+incompatible/go.mod h1:LZzlS4LQBHfciFOurYBFkCMTaZ0D1l+p0teMg7TSULI= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.8.0 h1:Q3gmuM9hKEjefWFFYF0Mat+YyFJvsUyYuwyNNJ5C9Ts= diff --git a/pkg/builder/configuration_builder.go b/pkg/builder/configuration_builder.go index 8629fa4..494cd1a 100644 --- a/pkg/builder/configuration_builder.go +++ b/pkg/builder/configuration_builder.go @@ -2,19 +2,19 @@ package builder import ( "bytes" - "html/template" + "strings" + "text/template" ngrokcomv1alpha1 "github.com/zufardhiyaulhaq/ngrok-operator/api/v1alpha1" "github.com/zufardhiyaulhaq/ngrok-operator/pkg/utils" - "sigs.k8s.io/controller-runtime/pkg/client" ) type NgrokConfigurationBuilder struct { Spec *ngrokcomv1alpha1.NgrokSpec } -func NewNgrokConfigurationBuilder(client client.Client) *NgrokConfigurationBuilder { +func NewNgrokConfigurationBuilder() *NgrokConfigurationBuilder { return &NgrokConfigurationBuilder{} } @@ -24,17 +24,29 @@ func (n *NgrokConfigurationBuilder) SetSpec(spec *ngrokcomv1alpha1.NgrokSpec) *N } func (n *NgrokConfigurationBuilder) Build() (string, error) { - var configuration bytes.Buffer + err := n.Spec.Validate() + if err != nil { + return "", err + } + + var configurationBuffer bytes.Buffer templateEngine, err := template.New("ngrok").Parse(utils.TMPL) if err != nil { return "", err } - err = templateEngine.Execute(&configuration, n.Spec) + err = templateEngine.Execute(&configurationBuffer, n.Spec) if err != nil { return "", err } - return configuration.String(), nil + var configuration []string + for _, data := range strings.Split(configurationBuffer.String(), "\n") { + if len(strings.TrimSpace(data)) != 0 { + configuration = append(configuration, data) + } + } + + return strings.Join(configuration, "\n"), nil } diff --git a/pkg/builder/configuration_builder_test.go b/pkg/builder/configuration_builder_test.go new file mode 100644 index 0000000..708b284 --- /dev/null +++ b/pkg/builder/configuration_builder_test.go @@ -0,0 +1,112 @@ +package builder_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/zufardhiyaulhaq/ngrok-operator/pkg/builder" + + ngrokcomv1alpha1 "github.com/zufardhiyaulhaq/ngrok-operator/api/v1alpha1" +) + +type configurationBuilderTestCase struct { + name string + spec *ngrokcomv1alpha1.NgrokSpec + expectedConfiguration string + expectedError bool +} + +var testGrid = []configurationBuilderTestCase{ + { + name: "empty service", + spec: &ngrokcomv1alpha1.NgrokSpec{ + Service: "", + Port: 80, + AuthTokenType: "plain", + Protocol: "http", + Inspect: false, + }, + expectedError: true, + expectedConfiguration: "", + }, + { + name: "simple HTTP service", + spec: &ngrokcomv1alpha1.NgrokSpec{ + Service: "foo.bar", + Port: 80, + AuthTokenType: "plain", + Protocol: "http", + Inspect: false, + }, + expectedError: false, + expectedConfiguration: `web_addr: 0.0.0.0:4040 +tunnels: + app: + proto: http + addr: foo.bar:80 + inspect: false`, + }, + { + name: "full HTTP service", + spec: &ngrokcomv1alpha1.NgrokSpec{ + Service: "foo.bar", + Port: 80, + Region: "us", + Auth: "foo:bar", + AuthToken: "foo", + AuthTokenType: "plain", + Protocol: "http", + BindTLS: "true", + Inspect: false, + HostHeader: "foo.dev", + Hostname: "foo.bar", + }, + expectedError: false, + expectedConfiguration: `web_addr: 0.0.0.0:4040 +authtoken: foo +region: us +tunnels: + app: + proto: http + addr: foo.bar:80 + inspect: false + auth: foo:bar + host_header: foo.dev + bind_tls: true + hostname: foo.bar`, + }, + { + name: "simple TCP service", + spec: &ngrokcomv1alpha1.NgrokSpec{ + Service: "foo.bar", + Port: 80, + Protocol: "tcp", + RemoteAddr: "1.tcp.ngrok.io:12345", + }, + expectedError: false, + expectedConfiguration: `web_addr: 0.0.0.0:4040 +tunnels: + app: + proto: tcp + addr: foo.bar:80 + remote_addr: 1.tcp.ngrok.io:12345`, + }, +} + +func TestConfigurationBuilder(t *testing.T) { + for _, test := range testGrid { + t.Run(test.name, func(t *testing.T) { + configuration, err := builder.NewNgrokConfigurationBuilder(). + SetSpec(test.spec). + Build() + + assert.Equal(t, configuration, test.expectedConfiguration) + + if test.expectedError { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +} diff --git a/pkg/builder/pod_builder.go b/pkg/builder/pod_builder.go index 01b1fa0..efa0205 100644 --- a/pkg/builder/pod_builder.go +++ b/pkg/builder/pod_builder.go @@ -39,6 +39,13 @@ func (n *NgrokPodBuilder) Build() (*corev1.Pod, error) { "app": n.Name, "generated": "ngrok-operator", }, + Annotations: map[string]string{ + "sidecar.istio.io/inject": "false", + "linkerd.io/inject": "disabled", + "kuma.io/sidecar-injection": "disabled", + "appmesh.k8s.aws/sidecarInjectorWebhook": "disabled", + "injector.nsm.nginx.com/auto-inject": "false", + }, }, Spec: corev1.PodSpec{ Containers: []corev1.Container{ diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 4aedc4a..6dcad2d 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -11,31 +11,49 @@ import ( ) const NGROK_URL_REGEX = `https://.[^"]+` -const TMPL = `web_addr: 0.0.0.0:4040 -{{if .AuthToken }} +const TMPL = ` +web_addr: 0.0.0.0:4040 + +{{ if .AuthToken }} authtoken: {{ .AuthToken }} -{{end}} -{{if .Region }} +{{ end }} + +{{ if .Region }} region: {{ .Region }} -{{end}} +{{ end }} + tunnels: app: proto: {{ .Protocol }} addr: {{ .Service }}:{{ .Port }} - {{if eq .Protocol "http"}} + + {{ if eq .Protocol "http" }} inspect: {{ .Inspect }} - {{if .Auth }} + {{if .AuthToken }}{{if .Auth }} auth: {{ .Auth }} + {{ end }}{{ end }} + {{if .HostHeader }} + host_header: {{ .HostHeader }} + {{ end }} + {{if .BindTLS }} + bind_tls: {{ .BindTLS }} {{ end }} {{if .AuthToken }}{{if .Hostname }} hostname: {{ .Hostname }} - {{end}}{{end}} - {{end}} - {{if eq .Protocol "tcp"}} - {{if .AuthToken }}{{if .RemoteAddr }} + {{ end }}{{ end }} + {{ end }} + + {{if .AuthToken }} + {{ if eq .Protocol "tls" }}{{if .Hostname }} + hostname: {{ .Hostname }} + {{ end }}{{ end }} + {{ end }} + + {{if eq .Protocol "tcp" }} + {{if .RemoteAddr }} remote_addr: {{ .RemoteAddr }} - {{end}}{{end}} - {{end}} + {{ end }} + {{ end }} ` func GetNgrokURL(api string) (string, error) {