Skip to content

Commit

Permalink
i
Browse files Browse the repository at this point in the history
feat: add configurable listerner timeout via ingress annotation

Signed-off-by: sakshi-1505 <[email protected]>
  • Loading branch information
sakshi-1505 committed Oct 16, 2023
1 parent 60ad70c commit 3c1ca51
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
32 changes: 31 additions & 1 deletion pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ const (
// IngressControllerTag is added to the related resources.
IngressControllerTag = "octavia.ingress.kubernetes.io"

// IngressAnnotationTimeoutClientData is the timeout for client data in ms
IngressAnnotationTimeoutClientData = "octavia.ingress.kubernetes.io/timeout-client-data"

// IngressAnnotationTimeoutClientData is the timeout for member data in ms
IngressAnnotationTimeoutMemberData = "octavia.ingress.kubernetes.io/timeout-member-data"

// IngressAnnotationTimeoutMemberConnet is the timeout for memer connect in ms
IngressAnnotationTimeoutMemberConnect = "octavia.ingress.kubernetes.io/timeout-member-connect"

// IngressAnnotationTimeoutMemberConnet is the timeout for memer connect in ms
IngressAnnotationTimeoutTCPInspect = "octavia.ingress.kubernetes.io/timeout-tcp-inspect"

// IngressSecretCertName is certificate key name defined in the secret data.
IngressSecretCertName = "tls.crt"
// IngressSecretKeyName is private key name defined in the secret data.
Expand Down Expand Up @@ -728,8 +740,13 @@ func (c *Controller) ensureIngress(ing *nwv1.Ingress) error {

// Create listener
sourceRanges := getStringFromIngressAnnotation(ing, IngressAnnotationSourceRangesKey, "0.0.0.0/0")
timeoutClientData := maybeGetIntFromIngressAnnotation(ing, IngressAnnotationTimeoutClientData)
timeoutMemberConnect := maybeGetIntFromIngressAnnotation(ing, IngressAnnotationTimeoutMemberConnect)
timeoutMemberData := maybeGetIntFromIngressAnnotation(ing, IngressAnnotationTimeoutMemberData)
timeoutTCPInspect := maybeGetIntFromIngressAnnotation(ing, IngressAnnotationTimeoutTCPInspect)

listenerAllowedCIDRs := strings.Split(sourceRanges, ",")
listener, err := c.osClient.EnsureListener(resName, lb.ID, secretRefs, listenerAllowedCIDRs)
listener, err := c.osClient.EnsureListener(resName, lb.ID, secretRefs, listenerAllowedCIDRs, timeoutClientData, timeoutMemberData, timeoutTCPInspect, timeoutMemberConnect)
if err != nil {
return err
}
Expand Down Expand Up @@ -1017,6 +1034,19 @@ func getStringFromIngressAnnotation(ingress *nwv1.Ingress, annotationKey string,
return defaultValue
}

// maybeGetIntFromIngressAnnotation searches a given Ingress for a specific annotationKey and either returns the
// annotation's value or a specified defaultSetting
func maybeGetIntFromIngressAnnotation(ingress *nwv1.Ingress, annotationKey string) *int {
if annotationValue, ok := ingress.Annotations[annotationKey]; ok {
returnValue, err := strconv.Atoi(annotationValue)
if err != nil {
return nil
}
return &returnValue
}
return nil
}

// privateKeyFromPEM converts a PEM block into a crypto.PrivateKey.
func privateKeyFromPEM(pemData []byte) (crypto.PrivateKey, error) {
var result *pem.Block
Expand Down
14 changes: 9 additions & 5 deletions pkg/ingress/controller/openstack/octavia.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (os *OpenStack) UpdateLoadBalancerDescription(lbID string, newDescription s
}

// EnsureListener creates a loadbalancer listener in octavia if it does not exist, wait for the loadbalancer to be ACTIVE.
func (os *OpenStack) EnsureListener(name string, lbID string, secretRefs []string, listenerAllowedCIDRs []string) (*listeners.Listener, error) {
func (os *OpenStack) EnsureListener(name string, lbID string, secretRefs []string, listenerAllowedCIDRs []string, timeoutClientData, timeoutMemberData, timeoutTCPInspect, timeoutMemberConnect *int) (*listeners.Listener, error) {
listener, err := openstackutil.GetListenerByName(os.Octavia, name, lbID)
if err != nil {
if err != cpoerrors.ErrNotFound {
Expand All @@ -340,10 +340,14 @@ func (os *OpenStack) EnsureListener(name string, lbID string, secretRefs []strin
log.WithFields(log.Fields{"lbID": lbID, "listenerName": name}).Info("creating listener")

opts := listeners.CreateOpts{
Name: name,
Protocol: "HTTP",
ProtocolPort: 80, // Ingress Controller only supports http/https for now
LoadbalancerID: lbID,
Name: name,
Protocol: "HTTP",
ProtocolPort: 80, // Ingress Controller only supports http/https for now
LoadbalancerID: lbID,
TimeoutClientData: timeoutClientData,
TimeoutMemberData: timeoutMemberData,
TimeoutMemberConnect: timeoutMemberConnect,
TimeoutTCPInspect: timeoutTCPInspect,
}
if len(secretRefs) > 0 {
opts.DefaultTlsContainerRef = secretRefs[0]
Expand Down

0 comments on commit 3c1ca51

Please sign in to comment.