Skip to content

Commit

Permalink
fixup! endpointaccessible: check if endpoint parameters changed at ev…
Browse files Browse the repository at this point in the history
…ery sync
  • Loading branch information
liouk committed Dec 21, 2023
1 parent c9aa56a commit 256229d
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions pkg/libs/endpointaccessible/endpoint_accessible_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,18 @@ func (c *endpointAccessibleController) sync(ctx context.Context, syncCtx factory
return err
}

newEndpoints := sets.New[string](endpoints...)
newEndpoints := sets.New(endpoints...)
endpointsChanged := !c.lastEndpoints.Equal(newEndpoints)

client, tlsChanged, err := c.buildTLSClient()
if err != nil {
return err
tlsChanged := false
var tlsConfig *tls.Config
if c.getTLSConfigFn != nil {
tlsConfig, err = c.getTLSConfigFn()
if err != nil {
return err
}

tlsChanged = c.lastServerName != tlsConfig.ServerName || !tlsConfig.RootCAs.Equal(c.lastCA)
}

isPastTimeForCheck := time.Since(c.lastCheckTime) > c.maxCheckLatency
Expand All @@ -109,6 +115,11 @@ func (c *endpointAccessibleController) sync(ctx context.Context, syncCtx factory
c.lastCheckTime = time.Now()
c.lastEndpoints = newEndpoints

client, err := c.buildTLSClient(tlsConfig)
if err != nil {
return err
}

// check all the endpoints in parallel. This matters for pods.
errCh := make(chan error, len(endpoints))
wg := sync.WaitGroup{}
Expand Down Expand Up @@ -174,30 +185,24 @@ func (c *endpointAccessibleController) sync(ctx context.Context, syncCtx factory
return utilerrors.NewAggregate(errors)
}

func (c *endpointAccessibleController) buildTLSClient() (*http.Client, bool, error) {
func (c *endpointAccessibleController) buildTLSClient(tlsConfig *tls.Config) (*http.Client, error) {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}

tlsChanged := false
if c.getTLSConfigFn != nil {
tlsConfig, err := c.getTLSConfigFn()
if err != nil {
return nil, false, err
}
if tlsConfig != nil {
transport.TLSClientConfig = tlsConfig

// these are the fields that are set by our getTLSConfigFn funcs
tlsChanged = c.lastServerName != tlsConfig.ServerName || !tlsConfig.RootCAs.Equal(c.lastCA)
c.lastServerName = tlsConfig.ServerName
c.lastCA = tlsConfig.RootCAs
}

return &http.Client{
Timeout: 5 * time.Second,
Transport: transport,
}, tlsChanged, nil
}, nil
}

0 comments on commit 256229d

Please sign in to comment.