...

Source file src/github.com/linkerd/linkerd2/controller/api/destination/opaque_ports_adaptor.go

Documentation: github.com/linkerd/linkerd2/controller/api/destination

     1  package destination
     2  
     3  import (
     4  	"github.com/linkerd/linkerd2/controller/api/destination/watcher"
     5  	sp "github.com/linkerd/linkerd2/controller/gen/apis/serviceprofile/v1alpha2"
     6  )
     7  
     8  // opaquePortsAdaptor holds an underlying ProfileUpdateListener and updates
     9  // that listener with changes to a service's opaque ports annotation. It
    10  // implements OpaquePortsUpdateListener and should be passed to a source of
    11  // profile updates and opaque ports updates.
    12  type opaquePortsAdaptor struct {
    13  	listener    watcher.ProfileUpdateListener
    14  	profile     *sp.ServiceProfile
    15  	opaquePorts map[uint32]struct{}
    16  }
    17  
    18  func newOpaquePortsAdaptor(listener watcher.ProfileUpdateListener) *opaquePortsAdaptor {
    19  	return &opaquePortsAdaptor{
    20  		listener: listener,
    21  	}
    22  }
    23  
    24  func (opa *opaquePortsAdaptor) Update(profile *sp.ServiceProfile) {
    25  	opa.profile = profile
    26  	opa.publish()
    27  }
    28  
    29  func (opa *opaquePortsAdaptor) UpdateService(ports map[uint32]struct{}) {
    30  	opa.opaquePorts = ports
    31  	opa.publish()
    32  }
    33  
    34  func (opa *opaquePortsAdaptor) publish() {
    35  	if opa.profile != nil {
    36  		p := *opa.profile
    37  		p.Spec.OpaquePorts = opa.opaquePorts
    38  		opa.listener.Update(&p)
    39  	}
    40  }
    41  

View as plain text