38 Commits

Author SHA1 Message Date
alex bezek 3187082b0e RBAC overhaul (#804)
* docs: add RBAC overhaul design spec and requirements

Captures the motivation, constraints, and design decisions for the RBAC
overhaul before the implementation changes land.

* refactor(rbac): remove kubebuilder RBAC markers and disable controller-gen RBAC output

RBAC is now defined explicitly in Helm templates rather than generated
from code annotations. Removes all +kubebuilder:rbac markers from
controllers and drain.go, and drops the rbac output target from
controller-gen so it no longer clobbers the Helm-managed files.

* refactor(rbac): reorganize operator component RBAC into per-component Helm templates

Replaces the monolithic controller-rbac.yaml and per-component rbac.yaml
files with a consistent per-component directory structure (agent/,
api-manager/, bindings-forwarder/). Each component now owns its own
Role, RoleBinding, and optional namespace-scoped variants.

Key changes:
- agent: split rbac.yaml into role.yaml + rolebinding.yaml with
  optional namespaced variants for namespace-scoped installs
- api-manager: moved from templates/rbac/role.yaml into dedicated
  api-manager/ directory alongside its other templates; adds
  leader-election-role.yaml and namespaced role support
- bindings-forwarder: renamed rbac.yaml -> role.yaml for consistency
- Deleted controller-rbac.yaml (replaced by api-manager/role.yaml)
- Renamed controller-{cm,deployment,pdb,serviceaccount}.yaml into
  api-manager/ directory for cohesion
- Renamed service-account.yaml -> serviceaccount.yaml everywhere
- values.yaml/schema: adds crdAccessRoles and per-component RBAC flags

* feat(rbac): add CRD editor/viewer ClusterRoles for ngrok resources

Moves existing editor/viewer roles into a dedicated rbac/crd-access/
subdirectory with consistent naming, and adds new roles for
NgrokTrafficPolicy (previously missing).

These ClusterRoles are for users of the operator — granting cluster
members read or write access to ngrok CRDs — as opposed to the
operator's own service account permissions.

* test(rbac): update Helm unit tests and add chainsaw e2e RBAC verification

Updates all Helm unit tests and snapshots to match the reorganized
template structure (per-component directories, renamed files). Adds
new test suites for api-manager RBAC and crd-access roles.

Also adds a chainsaw e2e test that verifies the operator's service
accounts have exactly the permissions they need — no more, no less.

* chore: update generated artifacts after RBAC overhaul

Regenerates manifest-bundle.yaml and updates the Helm README to
reflect the new values added for per-component RBAC configuration.

* remove plan and chainsaw tests and make bindings not try to use watchNamespace

* break out k8soperator permissions and bindings permissions to separate role

* update requirements and gen manifest bundle

* make agent and api manager only query their release namespace when looking for the kubernetesoperator crd

* make bindings role always be created even if bindings is disabled
2026-05-06 18:42:34 +00:00
alex bezek 395937dc90 Fix/k8sop 247 gateway controller fixes (#798)
* fix(gateway): correct inverted validation logic in validateGateway — bug 2.1

The condition checked if gateway was Accepted (valid) and returned
an error, which is backwards. Fixed to return error only when
gateway is NOT accepted.

Bug-ID: 2.1

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(gateway): avoid mutating cached gateway objects in predicates — bug 2.3

secretReferencedByGateway() and configMapReferencedByGateway()
mutated certRef.Namespace on cached Gateway objects via shared
pointers, corrupting the informer cache. Replaced with local
variable computation.

Bug-ID: 2.3

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(gateway): default nil parentRef namespace in findHTTPRouteForGateway — bug 2.17

Per Gateway API spec, nil parentRef.Namespace defaults to the
route's namespace. The code skipped the namespace check entirely,
matching any gateway with the same name regardless of namespace.

Bug-ID: 2.17

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(lint): consolidate duplicate corev1/v1 import aliases

The test file had both corev1 and v1 as aliases for k8s.io/api/core/v1,
which won't compile. Consolidate to corev1 matching the rest of the package.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: address PR feedback on gateway changes

- Extract certRefMatches helper to remove duplication across three
  call sites in secretReferencedByGateway and configMapReferencedByGateway
- Remove validateGateway Describe block: return value is discarded by
  the caller so the bug is not user-observable, and existing env tests
  already cover accepted/not-accepted paths
- Remove findHTTPRouteForGateway Describe block: watch mapper behavior
  is not user-observable via CR status; existing HTTPRoute env tests
  cover reconcile behavior
- Revert corev1 alias back to v1 so this PR does not touch the import

* fix lint

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jonathan Stacks <jonstacks@users.noreply.github.com>
2026-04-24 18:24:05 +00:00
alex bezek 72cef66086 Alex/object modified errors (#773)
* use patches and retries to avoid the object has been modified error we see

* add retryOnConflict to driver ingress update as well

* fix lint
2026-04-09 16:00:11 +00:00
Copilot c60f1a0e31 Fix flaky GatewayClass finalizer test due to missing Eventually timeout (#789)
Fix flaky test: add missing timeout/interval to Eventually in gatewayclass_controller_test.go


Agent-Logs-Url: https://github.com/ngrok/ngrok-operator/sessions/e112d372-6409-44f1-a8fe-05faf6262c59

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jonstacks <6900888+jonstacks@users.noreply.github.com>
2026-03-24 22:12:17 +00:00
Jonathan Stacks aa1781d348 Dependency updates (#785)
* chore: Update to go 1.26.1

Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>

* chore: Run 'go fix ./...' for go 1.26.1

Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>

* chore: Upgrade go modules

Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>

* chore: Fix deprecations and linter warnings

Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>

---------

Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>
2026-03-23 16:50:43 +00:00
alex bezek cadf84e9da Fix driver sync to not log errors for non-error scenarios (#768)
* Fix driver sync to not log errors for non-error scenarios

* Add debouncer test
2026-03-18 16:11:58 +00:00
alex bezek d8422ba7a1 Don't overwrite other ingress/gateway class resource statuses (#781)
* Don't overwrite other ingress/gateway class resource statuses

* Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* add tests and return empty when controllname is not set

* check parent ref controller name when validating

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-03-17 15:36:11 +00:00
Jonathan Stacks 6a86b394f9 fix: Don't add finalizers or write status to routes targeting non-ngrok Gateways (#770)
* feat(devenv): Add bashInteractive

Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>

* fix(controller): skip reconciliation for [HTTP,TLS,TCP]Routes not referencing ngrok-managed Gateways

Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>

* test: Remove gateway chainsaw tests for now

We'll add this back in once we have a better way to do chainsaw tests
with the Gateway API

Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>

---------

Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>
2026-03-03 21:51:43 +00:00
alex bezek a1c728e431 Allow helm uninstall to be configured to handle cleaning up api resou… (#750)
* Allow helm uninstall to be configured to handle cleaning up api resources and removing finalizers

* update helm values readme

* fix lint in drain.go

* Update helm snapshots

* use endpoints-verbose in tests and add a tiny sleep to the drain

* add more go tests

* code review comments addressed: move dockerfile args back, simplify api-manager.go kubernetesoperator changes, and add type of drainstatus in type
2026-02-05 15:59:25 +00:00
alex bezek 907cac3285 fix: correct namespace comparison in secretReferencedByGateway (#745)
Compare certRef.Namespace to secret.Namespace instead of secret.Name
when checking if a TLS secret is referenced by a Gateway listener.
2026-01-26 16:11:32 +00:00
Jonathan Stacks 9b0076439c chore: Rename symbol tcpRoute -> tlsRoute (#739)
Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>
2026-01-07 16:28:25 +00:00
Jonathan Stacks 36b119329d feat: Split ngrok-operators CRDs into their own chart (#732)
Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>
2025-12-16 21:58:31 +00:00
Jonathan Stacks a13039f82f feat: Add util documentation and tests (#707)
Signed-off-by: Jonathan Stacks <jonstacks@users.noreply.github.com>
2025-11-07 02:06:51 +00:00
Jonathan Stacks ec341442ba Test cleanup (#696)
* test: Fix inconsistencies in documentation with By()

* test(lb-services): Use a namespace for each test

Cleans up the code a bit
2025-10-27 21:19:44 +00:00
alex bezek 0151ad1761 Wait for gateway to be deleted before continuing the test to solve ra… (#675)
Wait for gateway to be deleted before continuing the test to solve race condition
2025-09-12 14:54:37 +00:00
Jonathan Stacks 981805a7aa [Breaking Change!] Remove Deprecated CRDs (#664)
* chore!: Remove TCPEdge CRD

* chore!: Remove TLSEdge CRD

* chore!: Remove HTTPSEdge, Tunnel, and NgrokModuleSet CRDs
2025-07-08 16:12:32 +00:00
Jonathan Stacks 279246c3b7 feat(gateway-api): Validate gateway listeners hostname and port (#658)
* feat(gateway-api): Validate gateway listeners hostname and port

* fix: Don't remove the gateway from the store if it is invalid

* fix: don't update gateway status unless it needs updating
2025-06-20 21:31:51 +00:00
Jonathan Stacks e98a4fcff6 fix: httproute should enqueue requests when gateways are deleted (#660) 2025-06-20 20:57:46 +00:00
Jonathan Stacks d6426361de feat: Add a default domain reclaim policy (#656) 2025-05-16 14:59:29 +00:00
Jonathan Stacks 2960d2abfa feat(gateway-api): Add gateay status addresses (#653) 2025-05-14 16:49:45 +00:00
Jonathan Stacks 52e7132ee8 feat(gateway-api): Set accepted conditions on gateways & httproutes (#651)
* chore: Upgrade envtest & k8s version

* test: Enable HTTPReconciler and GatewayReconciler in tests

* test: Add more utilities to testutils package

* refactor: Use meta to set status condition and use test helpers

* feat(gateway-controller): Accept Gateway Controllers

* feat(httproute-controller): Accept HTTP Routes
2025-05-13 23:14:33 +00:00
Jonathan Stacks 79436f1dec chore(tests): Use t.Context() instead of context.Background() in tests (#643)
Also use the GinkgoT().Context() analog in Ginkgo style tests
2025-05-06 16:06:16 +00:00
Alice Lilith 7407d01c45 enable more golangci linters (#630)
* enable more golangci linters

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix lint: remove/rename unused parameters

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix lint: add leading space to comments

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix lint: remove unnecessary type conversions

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix lint: remove redundant else blocks

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix lint: simplify logic and avoid nesting

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix lint: remove redundant if statements

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix lint: unnamed results of the same type may be confusing

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix lint: handle unhandled error

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix lint: fix spelling mistakes

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix lint: fix spelling mistakes

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

---------

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>
2025-04-17 17:35:42 +00:00
Alice Lilith bdfe581b2a add support for TCPRoute & TLSRoute (#621)
* fix mapping strategy translation bug

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* add storage for TPC and TLS routes

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* add controllers for TCPRoute and TLSRoute

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* implement endpoint translation for TLSRoute/TCPRoute

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* add additional store/translator tests and validations

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* add tests for TCP and TLS route controllers

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* improve controller tests

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

---------

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>
2025-04-03 10:36:09 +00:00
Jonathan Stacks 968463695a chore(lint): Enable go-critic (#604) 2025-03-11 22:24:09 +00:00
Alice Lilith 11ffcc9926 Implement AgentEndpoint client certs for upstream (#594)
* add new clientCertRefs field to AgentEndpoint

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* watch and process AgentEndpoint client certificate refs

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* update Gateway API and controller runtime

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* watch Secrets referenced by Gateway BackendTLS.ClientCertificateRef

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* translate Gateway BackendTLS to AgentEndpoint config

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* change generated AgentEndpoint name based on tls

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* generate helm

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

---------

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>
2025-02-24 11:05:31 +00:00
Alice Lilith d317eb31d5 feat: gwapi ReferenceGrant support (#589)
* add controllers for referencegrant support

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* implement referencegrant support

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix allowedRoutes namespace selector logic

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* add ReferenceGrant opt-out flag to helm

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* generate manifests

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* update helm readme metadata

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* regenerate helm snapshots

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* allow agent deployment to parse refgrants flag

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix bindings merge conflict

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

---------

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>
2025-02-20 17:49:53 +00:00
Alice Lilith dadf0c27c9 feat: gateway api -> endpoints (#588)
* update gwapi and controller runtime

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* watch secrets/configmaps used on gateways

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* update ir for gatewayapi translation

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* update translation utils

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* feat: translate gateway api to endpoints

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* update and add translation tests

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* replace deprecated gwapi schema funcs

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* update gomod

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix managerdriver test

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* add support for extended tls options

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

* fix translation test data from bindings conflict

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>

---------

Signed-off-by: Alice-Lilith <a.wasko@ngrok.com>
2025-02-19 23:32:08 +00:00
Alice Lilith f7dd866b5a refactor: store driver (#553)
* split up driver.go

* move driver into its own package

* rename UpdateStoreHandler for api manager driver
2024-12-13 16:41:59 +00:00
Jonathan Stacks 63bb8c9dd0 fix: Add GatewayClass controller (#484)
GatewayClasses should be validated and then accepted according to the spec. See: https://gateway-api.sigs.k8s.io/reference/spec/\#gateway.networking.k8s.io/v1.GatewayClass
2024-11-04 20:18:30 +00:00
Harrison Katz ac83885d6e Standardize logging pattern using ctrl.LoggerFrom(ctx) 2024-10-23 17:27:09 -04:00
Harrison Katz 0c14fbf1ed Adjust package names 2024-09-16 12:45:30 -04:00
Harrison Katz da55683876 Abstract BaseController 2024-09-16 12:45:30 -04:00
Harrison Katz e9a887c433 Update package names and paths to standardize on internal/controller ; package controller 2024-09-16 12:45:30 -04:00
Jonathan Stacks 1e2367de30 Update references from kubernetes-ingress-controller -> ngrok-operator (#426)
* chore(rename): Replace kubernetes-ingress-controller with ngrok-operator

rg github.com/ngrok/kubernetes-ingress-controller . --files-with-matches | xargs sed -i 's/github.com\/ngrok\/kubernetes-ingress-controller/github.com\/ngrok\/ngrok-operator/g'

* chore(rename): Move helm/ingress-controller -> helm/ngrok-operator

* chore(rename): More updates
2024-09-10 15:51:27 -05:00
Oz a79a9008a0 Gateway spins up Ngrok CRDs (#343)
* add experimetnal gateway flag

* update store

* sperate experimental gateway deploy from normal deploy process

* split http edge for gateway

* update helm snapshot tests

* lint

* fix build issue

* remove comments

* use flag in driver seed/sync

* move util functions

* clean-up controller

* add DeleteNamedGateway function

* set domainNaim var

* block httproutes from seeding

* get domainmaps

* init httproute controller (#345)

* init httproute controller

* only start HTTPRouteReconciler if gateway flag is set

* setup reconciler struct

* update reconciler markers

* run httproute edge creation

* Gateway handles traffic

* remove debug log

* map HTTProute to HTTPSEdge

* implement HTTPRouteRules (#347)

* init httproute controller

* only start HTTPRouteReconciler if gateway flag is set

* setup reconciler struct

* update reconciler markers

* run httproute edge creation

* Gateway handles traffic

* remove debug log

* map HTTProute to HTTPSEdge

* add HTTPRouteMatch

* convert filters to traffic policy actions

* fix RequestRedirect filter

* fix request redirect filter

* fix domain issue

* switch request redirect to redirect action

* remove log

* emmit error if regex path match is created

* remove unsupported match types

* add AllowedRoutes check

* rename utils/ to controllers/

* update helm snapshots

* remove spaces

* check if listener has hostname field

* move functions with their structs

* don't finalize ingored gateway

* boolean logic fix

* remove unsed function param

* rename module set func to endpoint policy

* clean up some comments

* fix spelling/copy-paste errors

* fix more boolean errors

* Revert "remove unsed function param"

This reverts commit 02b6795a8b.

* remove hostnames not in gateway domain map

* turn gateway domains to a map

* skip non HTTPS listeners

* pull out boolean inside of getDriver

* fix copy-paste error

* don't build edge if traffic unsupported filters are set

* handle error case for all filters

* merge edgemaps

* don't overwrite gateway domain map

* cleanup comments

* use loop instead of func

* throw more errors

* fix lint

* use guard statements

* rename to hasReference

* inline error check

* encapsulate double pointer to struct
2024-03-14 13:55:25 -05:00
Oz 87891138fc fix spellilng
Co-authored-by: alex bezek <alex@ngrok.com>
2024-01-12 12:49:47 -06:00
Abdirahman Osman 06ffbc8070 init gateway api 2024-01-11 10:41:53 -06:00