Skip to content

Commit

Permalink
Add oneClickDemoMode to helm values.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
hjkatz committed Nov 12, 2024
1 parent 366bc26 commit 4f627f9
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 2 deletions.
45 changes: 44 additions & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ type managerOpts struct {
zapOpts *zap.Options
clusterDomain string

// when true, ngrok-op will allow required fields to be optional
// then it will go Ready and log errors about registration state due to missing required fields
// this is useful for marketplace installations where our users do not have a chance to add their required configuration
// yet we still want a 1-click install to work
//
// when false, ngrok-op will require all required fields to be present before going Ready
// and will log errors about missing required fields
oneClickDemoMode bool

// feature flags
enableFeatureIngress bool
enableFeatureGateway bool
Expand Down Expand Up @@ -146,6 +155,7 @@ func cmd() *cobra.Command {
// TODO(operator-rename): Same as above, but for the manager name.
c.Flags().StringVar(&opts.managerName, "manager-name", "ngrok-ingress-controller-manager", "Manager name to identify unique ngrok ingress controller instances")
c.Flags().StringVar(&opts.clusterDomain, "cluster-domain", "svc.cluster.local", "Cluster domain used in the cluster")
c.Flags().BoolVar(&opts.oneClickDemoMode, "one-click-demo-mode", false, "Run the operator in one-click-demo mode (Ready, but not running)")

// feature flags
c.Flags().BoolVar(&opts.enableFeatureIngress, "enable-feature-ingress", true, "Enables the Ingress controller")
Expand Down Expand Up @@ -190,6 +200,10 @@ func startOperator(ctx context.Context, opts managerOpts) error {
return fmt.Errorf("unable to load manager: %w", err)
}

if opts.oneClickDemoMode {
return runOneClickDemoMode(ctx, opts, k8sClient, mgr)
}

return runNormalMode(ctx, opts, k8sClient, mgr)
}

Expand All @@ -198,6 +212,35 @@ func startOperator(ctx context.Context, opts managerOpts) error {
// - the operator will log errors about missing required fields
// - the operator will go Ready and log errors about registration state due to missing required fields
func runOneClickDemoMode(ctx context.Context, opts managerOpts, k8sClient client.Client, mgr ctrl.Manager) error {
// register healthchecks
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
return fmt.Errorf("error setting up readyz check: %w", err)
}
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
return fmt.Errorf("error setting up health check: %w", err)
}

// start a ticker to print demo log messages
go func() {
ticker := time.NewTicker(10 * time.Second)
for {
select {
case <-ctx.Done():
break
case <-ticker.C:
setupLog.Error(errors.New("Running in one-click-demo mode"), "Ready even if required fields are missing!")
setupLog.Info("The ngrok-operator is running in one-click-demo mode which means the operator is not actually reconciling resources.")
setupLog.Info("Please provide ngrok API key and ngrok Authtoken in your Helm values to run the operator for real.")
setupLog.Info("Please set `oneClickDemoMode: false` in your Helm values to run the operator for real.")
}
}
}()

setupLog.Info("starting api-manager in one-click-demo mode")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
return fmt.Errorf("error starting api-manager: %w", err)
}

return nil
}

Expand Down Expand Up @@ -288,7 +331,7 @@ func runNormalMode(ctx context.Context, opts managerOpts, k8sClient client.Clien
return fmt.Errorf("error setting up health check: %w", err)
}

setupLog.Info("starting api-manager")
setupLog.Info("starting api-manager in normal mode")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
return fmt.Errorf("error starting api-manager: %w", err)
}
Expand Down
2 changes: 2 additions & 0 deletions helm/ngrok-operator/templates/agent/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if and .Values.ingress.enabled (not .Values.oneClickDemoMode) }}
{{- $component := "agent" }}
{{- $rbacChecksum := include (print $.Template.BasePath "/agent/rbac.yaml") . | sha256sum }}
{{- $agent := .Values.agent }}
Expand Down Expand Up @@ -124,3 +125,4 @@ spec:
volumes:
{{ toYaml .Values.extraVolumes | nindent 6 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.bindings.enabled }}
{{- if and .Values.bindings.enabled (not .Values.oneClickDemoMode) }}
{{- $component := "bindings-forwarder" }}
{{- $rbacChecksum := include (print $.Template.BasePath "/bindings-forwarder/rbac.yaml") . | sha256sum }}
{{- $forwarder := .Values.bindings.forwarder }}
Expand Down
3 changes: 3 additions & 0 deletions helm/ngrok-operator/templates/controller-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ spec:
args:
- --release-name={{ .Release.Name }}
{{- include "ngrok-operator.manager.cliFeatureFlags" . | nindent 8 }}
{{- if .Values.oneClickDemoMode }}
- --one-click-demo-mode
{{- end }}
{{- if .Values.bindings.enabled }}
- --bindings-name={{ .Values.bindings.name }}
- --bindings-allowed-urls={{ join "," .Values.bindings.allowedURLs }}
Expand Down
3 changes: 3 additions & 0 deletions helm/ngrok-operator/tests/agent/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ suite: test agent deployment
templates:
- agent/deployment.yaml
- agent/rbac.yaml
set:
ingress:
enabled: true
tests:
- it: Should match snapshot
asserts:
Expand Down
9 changes: 9 additions & 0 deletions helm/ngrok-operator/tests/controller-deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ tests:
- contains:
path: spec.template.spec.containers[0].args
content: --bindings-allowed-urls=test.example,http://*
- it: Should pass one-click-demo mode if set
set:
oneClickDemoMode: true
template: controller-deployment.yaml
documentIndex: 0 # Document 0 is the deployment since its the first template
asserts:
- contains:
path: spec.template.spec.containers[0].args
content: --one-click-demo-mode
- it: Should pass log format argument if set
set:
log:
Expand Down
2 changes: 2 additions & 0 deletions helm/ngrok-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
## @param description ngrok-operator description that will appear in the ngrok dashboard
## @param commonLabels Labels to add to all deployed objects
## @param commonAnnotations Annotations to add to all deployed objects
## @param oneClickDemoMode If true, then the operator will startup without required fields or API registration, become Ready, but not actually be running
nameOverride: ""
fullnameOverride: ""
description: "The official ngrok Kubernetes Operator."
commonLabels: {}
commonAnnotations: {}
oneClickDemoMode: false

##
## @section Image configuration
Expand Down

0 comments on commit 4f627f9

Please sign in to comment.