Skip to content

Commit

Permalink
Support clusters with nondefault cluster DNS names
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Leggett authored and harsimranmaan committed Dec 5, 2020
1 parent a8ab783 commit 2c77ee2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Unlike the default `configurable-http-proxy` that ships with Jupyterhub, the tra

The proxy can be deployed to a Kubernetes namespace running Jupyterhub by applying the following config:
Change SUB_DOMAIN_HOST to a value to a hostname where jupyterhub is hosted. The ISTIO_GATEWAY value should be set to
the gateway which handles traffic for jupyterhub.
the gateway which handles traffic for jupyterhub. If your cluster has a non-default domain, you can specify that with CLUSTER_DOMAIN

```yaml
apiVersion: apps/v1
Expand Down Expand Up @@ -83,6 +83,8 @@ spec:
value: jupyterhub
- name: WAIT_FOR_WARMUP
value: "true"
- name: CLUSTER_DOMAIN
value: "cluster.local"
image: splunk/jupyterhub-istio-proxy:0.0.2
imagePullPolicy: IfNotPresent
name: proxy
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var gateway string
var namespace string
var waitForWarmup bool
var vsNamePrefix string
var clusterDomain string

const (
gatewayEnvKey = "ISTIO_GATEWAY"
Expand All @@ -44,6 +45,8 @@ const (
waitForWarmupKey = "WAIT_FOR_WARMUP"
virtualServicePrefixKey = "VIRTUAL_SERVICE_PREFIX"
virtualServicePrefixDefault = "jupyter"
clusterDomainEnvKey = "CLUSTER_DOMAIN"
clusterDomainDefault = "cluster.local"
)

func main() {
Expand Down Expand Up @@ -76,8 +79,11 @@ func main() {
if vsNamePrefix, ok = os.LookupEnv(virtualServicePrefixKey); !ok || vsNamePrefix == "" {
vsNamePrefix = virtualServicePrefixDefault
}
if clusterDomain, ok = os.LookupEnv(clusterDomainEnvKey); !ok || clusterDomain == "" {
clusterDomain = clusterDomainDefault
}
var ic proxy.Istioer
ic, err = proxy.NewIstioClient(namespace, gateway, subDomainHost, waitForWarmup, vsNamePrefix)
ic, err = proxy.NewIstioClient(namespace, gateway, subDomainHost, waitForWarmup, vsNamePrefix, clusterDomain)
if err != nil {
log.Fatalf("failed to create istio client: %s\n", err)
}
Expand Down
2 changes: 1 addition & 1 deletion proxy/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (i *IstioClient) createVirtualService(r route) error {
return err
}
destinationHost, destinationPort := r.splitTarget()
destinationHost = fmt.Sprintf("%s.%s.svc.cluster.local", destinationHost, i.namespace)
destinationHost = fmt.Sprintf("%s.%s.svc.%s", destinationHost, i.namespace, i.clusterDomain)
vsName := i.virtualServiceNameWithPrefix(r.RouteSpec)
vs := virtualService(vsName, i.gateway, i.host, destinationHost, destinationPort, r.RouteSpec, annotations)

Expand Down
5 changes: 3 additions & 2 deletions proxy/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ type IstioClient struct {
namespace string
waitForWarmup bool
vsNamePrefix string
clusterDomain string
}

// NewIstioClient returns a new IstioClient
func NewIstioClient(namespace string, gateway string, host string, waitForWarmup bool, vsNamePrefix string) (*IstioClient, error) {
func NewIstioClient(namespace string, gateway string, host string, waitForWarmup bool, vsNamePrefix string, clusterDomain string) (*IstioClient, error) {
// creates the in-cluster config
config, err := rest.InClusterConfig()
if err != nil {
Expand All @@ -52,7 +53,7 @@ func NewIstioClient(namespace string, gateway string, host string, waitForWarmup
if err != nil {
return nil, err
}
return &IstioClient{Clientset: ic, namespace: namespace, gateway: gateway, host: host, waitForWarmup: waitForWarmup, vsNamePrefix: vsNamePrefix}, nil
return &IstioClient{Clientset: ic, namespace: namespace, gateway: gateway, host: host, waitForWarmup: waitForWarmup, vsNamePrefix: vsNamePrefix, clusterDomain: clusterDomain}, nil
}
func (c IstioClient) virtualServiceAnnotationNameWithPrefix() string {
return fmt.Sprintf("%s.splunk.io/proxy-data", c.virtualServicePrefix())
Expand Down

0 comments on commit 2c77ee2

Please sign in to comment.