@@ -47,6 +47,7 @@ import (
4747const controllerAgentName = "inlets-operator"
4848const inletsPROControlPort = 8123
4949const inletsPROVersion = "0.8.5"
50+ const inletsPortsAnnotation = "inlets.dev/ports"
5051
5152const (
5253 // SuccessSynced is used as part of the Event 'reason' when a Tunnel is synced
@@ -389,6 +390,7 @@ func (c *Controller) syncHandler(key string) error {
389390 }
390391 } else {
391392 log .Printf ("Tunnel exists: %s\n " , found .Name )
393+ c .enqueueTunnel (found )
392394
393395 if ! manageService (* c , * service ) {
394396 log .Printf ("Removing tunnel: %s" , found .Name )
@@ -463,57 +465,78 @@ func (c *Controller) syncHandler(key string) error {
463465
464466func createClientDeployment (tunnel * inletsv1alpha1.Tunnel , c * Controller ) error {
465467 if tunnel .Spec .ClientDeploymentRef != nil {
466- // already existing
467- return nil
468- }
468+ get := metav1.GetOptions {}
469+ deployment , err := c .kubeclientset .AppsV1 ().Deployments (tunnel .Namespace ).Get (context .Background (), tunnel .Name + "-client" , get )
470+ if err != nil {
471+ return err
472+ }
473+ service , err := c .kubeclientset .CoreV1 ().Services (tunnel .Namespace ).Get (context .Background (), tunnel .Spec .ServiceName , get )
474+ if err != nil {
475+ return err
476+ }
469477
470- get := metav1.GetOptions {}
471- service , err := c .kubeclientset .CoreV1 ().Services (tunnel .Namespace ).Get (context .Background (), tunnel .Spec .ServiceName , get )
478+ if deployment .ObjectMeta .Annotations != nil && deployment .ObjectMeta .Annotations [inletsPortsAnnotation ] != getPortsString (service ) {
479+ // Swallow error since it's handled on start-up already
480+ licenseKey , _ := c .infraConfig .ProConfig .GetLicenseKey ()
472481
473- if err != nil {
474- return err
475- }
482+ ports := getPortsString (service )
483+ client := makeClient (tunnel ,
484+ c .infraConfig .GetInletsClientImage (),
485+ ports ,
486+ licenseKey ,
487+ c .infraConfig .MaxClientMemory )
476488
477- firstPort := int32 (80 )
489+ _ , err = c .kubeclientset .AppsV1 ().
490+ Deployments (tunnel .Namespace ).
491+ Update (context .Background (), client , metav1.UpdateOptions {})
478492
479- for _ , port := range service .Spec .Ports {
480- if port .Name == "http" {
481- firstPort = port .Port
482- break
493+ if err != nil {
494+ log .Printf ("Error updating deployment: %s" , err )
495+ }
483496 }
484- }
485497
486- // Swallow error since it's handled on start-up already
487- licenseKey , _ := c .infraConfig .ProConfig .GetLicenseKey ()
498+ return nil
499+ } else {
500+
501+ get := metav1.GetOptions {}
502+ service , err := c .kubeclientset .CoreV1 ().Services (tunnel .Namespace ).Get (context .Background (), tunnel .Spec .ServiceName , get )
488503
489- ports := getPortsString (service )
490- client := makeClient (tunnel , firstPort ,
491- c .infraConfig .GetInletsClientImage (),
492- ports ,
493- licenseKey ,
494- c .infraConfig .MaxClientMemory )
504+ if err != nil {
505+ return err
506+ }
495507
496- deployment , err := c .kubeclientset .AppsV1 ().
497- Deployments (tunnel .Namespace ).
498- Create (context .Background (), client , metav1.CreateOptions {})
508+ // Swallow error since it's handled on start-up already
509+ licenseKey , _ := c .infraConfig .ProConfig .GetLicenseKey ()
499510
500- if err != nil {
501- log .Printf ("Error updating deployment: %s" , err )
502- }
511+ ports := getPortsString (service )
512+ client := makeClient (tunnel ,
513+ c .infraConfig .GetInletsClientImage (),
514+ ports ,
515+ licenseKey ,
516+ c .infraConfig .MaxClientMemory )
503517
504- tunnel .Spec .ClientDeploymentRef = & metav1.ObjectMeta {
505- Name : deployment .Name ,
506- Namespace : deployment .Namespace ,
507- }
518+ deployment , err := c .kubeclientset .AppsV1 ().
519+ Deployments (tunnel .Namespace ).
520+ Create (context .Background (), client , metav1.CreateOptions {})
508521
509- if _ , err := c .operatorclientset .InletsV1alpha1 ().
510- Tunnels (tunnel .Namespace ).
511- Update (context .Background (), tunnel , metav1.UpdateOptions {}); err != nil {
512- log .Printf ("Error updating tunnel: %s" , err )
513- return fmt .Errorf ("tunnel update error %s" , err )
514- }
522+ if err != nil {
523+ log .Printf ("Error creating deployment: %s" , err )
524+ }
515525
516- return nil
526+ tunnel .Spec .ClientDeploymentRef = & metav1.ObjectMeta {
527+ Name : deployment .ObjectMeta .Name ,
528+ Namespace : deployment .ObjectMeta .Namespace ,
529+ }
530+
531+ if _ , err := c .operatorclientset .InletsV1alpha1 ().
532+ Tunnels (tunnel .Namespace ).
533+ Update (context .Background (), tunnel , metav1.UpdateOptions {}); err != nil {
534+ log .Printf ("Error updating tunnel: %s" , err )
535+ return fmt .Errorf ("tunnel update error %s" , err )
536+ }
537+
538+ return nil
539+ }
517540}
518541
519542func getHostConfig (c * Controller , tunnel * inletsv1alpha1.Tunnel , planOverride string ) provision.BasicHost {
@@ -700,7 +723,7 @@ func syncProvisioningHostStatus(tunnel *inletsv1alpha1.Tunnel, c *Controller) er
700723 return nil
701724}
702725
703- func makeClient (tunnel * inletsv1alpha1.Tunnel , targetPort int32 , clientImage string , ports , license string , maxMemory string ) * appsv1.Deployment {
726+ func makeClient (tunnel * inletsv1alpha1.Tunnel , clientImage string , ports , license string , maxMemory string ) * appsv1.Deployment {
704727 replicas := int32 (1 )
705728 name := tunnel .Name + "-client"
706729
@@ -731,8 +754,9 @@ func makeClient(tunnel *inletsv1alpha1.Tunnel, targetPort int32, clientImage str
731754
732755 deployment := appsv1.Deployment {
733756 ObjectMeta : metav1.ObjectMeta {
734- Name : name ,
735- Namespace : tunnel .Namespace ,
757+ Name : name ,
758+ Namespace : tunnel .Namespace ,
759+ Annotations : map [string ]string {inletsPortsAnnotation : ports },
736760 OwnerReferences : []metav1.OwnerReference {
737761 * metav1 .NewControllerRef (tunnel , schema.GroupVersionKind {
738762 Group : inletsv1alpha1 .SchemeGroupVersion .Group ,
0 commit comments