Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load cluster domain as a config option. Fall back to default if not set #339

Merged
merged 11 commits into from
Aug 23, 2024
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# Image URL to use all building/pushing image targets
IMG ?= kubernetes-ingress-controller

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.23

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.2
0.11.0
4 changes: 3 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type managerOpts struct {
managerName string
useExperimentalGatewayAPI bool
zapOpts *zap.Options
clusterDomain string

// env vars
namespace string
Expand Down Expand Up @@ -114,6 +115,7 @@ func cmd() *cobra.Command {
c.Flags().StringVar(&opts.watchNamespace, "watch-namespace", "", "Namespace to watch for Kubernetes resources. Defaults to all namespaces.")
c.Flags().StringVar(&opts.managerName, "manager-name", "ngrok-ingress-controller-manager", "Manager name to identify unique ngrok ingress controller instances")
c.Flags().BoolVar(&opts.useExperimentalGatewayAPI, "use-experimental-gateway-api", false, "sets up experemental gatewayAPI")
c.Flags().StringVar(&opts.clusterDomain, "cluster-domain", "svc.cluster.local", "Cluster domain used in the cluster")
jonstacks marked this conversation as resolved.
Show resolved Hide resolved
opts.zapOpts = &zap.Options{}
goFlagSet := flag.NewFlagSet("manager", flag.ContinueOnError)
opts.zapOpts.BindFlags(goFlagSet)
Expand Down Expand Up @@ -304,7 +306,7 @@ func runController(ctx context.Context, opts managerOpts) error {
// getDriver returns a new Driver instance that is seeded with the current state of the cluster.
func getDriver(ctx context.Context, mgr manager.Manager, options managerOpts) (*store.Driver, error) {
logger := mgr.GetLogger().WithName("cache-store-driver")
d := store.NewDriver(logger, mgr.GetScheme(), options.controllerName, types.NamespacedName{
d := store.NewDriver(logger, mgr.GetScheme(), options.controllerName, options.clusterDomain, types.NamespacedName{
Namespace: options.namespace,
Name: options.managerName,
})
Expand Down
3 changes: 3 additions & 0 deletions helm/ingress-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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.13.0
- exposes clusterDomain variable to inject cluster-domain config option. Defaults to svc.cluster.local domain.

## 0.12.1

- Update to version 0.10.1 of the ingress controller, which includes:
Expand Down
4 changes: 2 additions & 2 deletions helm/ingress-controller/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
name: kubernetes-ingress-controller
description: A Kubernetes ingress controller built using ngrok.
version: 0.12.2
appVersion: 0.10.2
version: 0.13.0
appVersion: 0.11.0
keywords:
- ngrok
- networking
Expand Down
1 change: 1 addition & 0 deletions helm/ingress-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ To uninstall the chart:
| `credentials.authtoken` | Your ngrok authtoken. If provided, it will be will be written to the secret and the apiKey must be provided as well. | `""` |
| `region` | ngrok region to create tunnels in. Defaults to connect to the closest geographical region. | `""` |
| `serverAddr` | This is the URL of the ngrok server to connect to. You should set this if you are using a custom ingress URL. | `""` |
| `clusterDomain` | Injects the cluster domain name for service discovery. | `svc.cluster.local` |
| `metaData` | This is a map of key/value pairs that will be added as meta data to all ngrok api resources created | `{}` |
| `affinity` | Affinity for the controller pod assignment | `{}` |
| `podAffinityPreset` | Pod affinity preset. Ignored if `affinity` is set. Allowed values: `soft` or `hard` | `""` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ spec:
- --metrics-bind-address=:8080
- --election-id={{ include "kubernetes-ingress-controller.fullname" . }}-leader
- --manager-name={{ include "kubernetes-ingress-controller.fullname" . }}-manager
{{- if .Values.clusterDomain }}
- --cluster-domain={{ .Values.clusterDomain }}
{{- end }}
securityContext:
allowPrivilegeEscalation: false
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ tests:
mountPath: /test-volume
asserts:
- matchSnapshot: {}
- it: Should use the specified cluster domain name
set:
clusterDomain: svc.example.com
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
pattern: --cluster=domain=svc.example.com
- it: Should use the specified secret name for the credentials secret
set:
credentials.secret.name: test-secret-name
Expand Down
3 changes: 3 additions & 0 deletions helm/ingress-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ region: ""
## @param serverAddr This is the URL of the ngrok server to connect to. You should set this if you are using a custom ingress URL.
serverAddr: ""

## @param clusterDomain Injects the cluster domain name for service discovery.
clusterDomain: svc.cluster.local

## @param metaData This is a map of key/value pairs that will be added as meta data to all ngrok api resources created
metaData: {}

Expand Down
18 changes: 9 additions & 9 deletions internal/store/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const clusterDomain = "svc.cluster.local" // TODO: We can technically figure this out by looking at things like our resolv.conf or we can just take this as a helm option

const (
labelControllerNamespace = "k8s.ngrok.com/controller-namespace"
labelControllerName = "k8s.ngrok.com/controller-name"
Expand All @@ -46,6 +44,7 @@ type Driver struct {
scheme *runtime.Scheme
customMetadata string
managerName types.NamespacedName
clusterDomain string

syncMu sync.Mutex
syncRunning bool
Expand All @@ -55,15 +54,16 @@ type Driver struct {
}

// NewDriver creates a new driver with a basic logger and cache store setup
func NewDriver(logger logr.Logger, scheme *runtime.Scheme, controllerName string, managerName types.NamespacedName) *Driver {
func NewDriver(logger logr.Logger, scheme *runtime.Scheme, controllerName string, clusterDomain string, managerName types.NamespacedName) *Driver {
cacheStores := NewCacheStores(logger)
s := New(cacheStores, controllerName, logger)
return &Driver{
store: s,
cacheStores: cacheStores,
log: logger,
scheme: scheme,
managerName: managerName,
store: s,
cacheStores: cacheStores,
log: logger,
scheme: scheme,
managerName: managerName,
clusterDomain: clusterDomain,
}
}

Expand Down Expand Up @@ -680,7 +680,7 @@ func (d *Driver) calculateTunnels() map[tunnelKey]ingressv1alpha1.Tunnel {
key := tunnelKey{ingress.Namespace, serviceName, strconv.Itoa(int(servicePort))}
tunnel, found := tunnels[key]
if !found {
targetAddr := fmt.Sprintf("%s.%s.%s:%d", serviceName, key.namespace, clusterDomain, servicePort)
targetAddr := fmt.Sprintf("%s.%s.%s:%d", serviceName, key.namespace, d.clusterDomain, servicePort)
tunnel = ingressv1alpha1.Tunnel{
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-%d-", serviceName, servicePort),
Expand Down
3 changes: 2 additions & 1 deletion internal/store/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ var _ = Describe("Driver", func() {
var driver *Driver
var scheme = runtime.NewScheme()
cname := "cnametarget.com"
clusterDomain := "svc.cluster.local"
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(ingressv1alpha1.AddToScheme(scheme))
BeforeEach(func() {
// create a fake logger to pass into the cachestore
logger := logr.New(logr.Discard().GetSink())
driver = NewDriver(logger, scheme, defaultControllerName, types.NamespacedName{
driver = NewDriver(logger, scheme, defaultControllerName, clusterDomain, types.NamespacedName{
Name: defaultManagerName,
})
driver.syncAllowConcurrent = true
Expand Down
Loading