Skip to content

Commit

Permalink
fix httproute
Browse files Browse the repository at this point in the history
  • Loading branch information
AmaliMatharaarachchi committed Jul 25, 2024
1 parent 68550e5 commit 5adbaa5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 26 deletions.
22 changes: 11 additions & 11 deletions adapter/internal/operator/gateway-api/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (g *GatewayContext) ResetListeners() {
listener := &g.Spec.Listeners[i]
g.Status.Listeners[i] = gwapiv1.ListenerStatus{Name: listener.Name}
g.listeners[i] = &ListenerContext{
listenerStatusId: i,
listenerStatusID: i,
Listener: listener,
gateway: g.Gateway,
}
Expand All @@ -64,7 +64,7 @@ type ListenerContext struct {
*gwapiv1.Listener

gateway *gwapiv1.Gateway
listenerStatusId int
listenerStatusID int
namespaceSelector labels.Selector
tlsSecrets []*v1.Secret
}
Expand All @@ -80,7 +80,7 @@ func (l *ListenerContext) SetCondition(conditionType gwapiv1.ListenerConditionTy
}

index := -1
for i, existing := range l.gateway.Status.Listeners[l.listenerStatusId].Conditions {
for i, existing := range l.gateway.Status.Listeners[l.listenerStatusID].Conditions {
if existing.Type == cond.Type {
// return early if the condition is unchanged
if existing.Status == cond.Status &&
Expand All @@ -95,26 +95,26 @@ func (l *ListenerContext) SetCondition(conditionType gwapiv1.ListenerConditionTy
}

if index > -1 {
l.gateway.Status.Listeners[l.listenerStatusId].Conditions[index] = cond
l.gateway.Status.Listeners[l.listenerStatusID].Conditions[index] = cond
} else {
l.gateway.Status.Listeners[l.listenerStatusId].Conditions = append(l.gateway.Status.Listeners[l.listenerStatusId].Conditions, cond)
l.gateway.Status.Listeners[l.listenerStatusID].Conditions = append(l.gateway.Status.Listeners[l.listenerStatusID].Conditions, cond)
}
}

func (l *ListenerContext) SetSupportedKinds(kinds ...gwapiv1.RouteGroupKind) {
l.gateway.Status.Listeners[l.listenerStatusId].SupportedKinds = kinds
l.gateway.Status.Listeners[l.listenerStatusID].SupportedKinds = kinds
}

func (l *ListenerContext) IncrementAttachedRoutes() {
l.gateway.Status.Listeners[l.listenerStatusId].AttachedRoutes++
l.gateway.Status.Listeners[l.listenerStatusID].AttachedRoutes++
}

func (l *ListenerContext) AttachedRoutes() int32 {
return l.gateway.Status.Listeners[l.listenerStatusId].AttachedRoutes
return l.gateway.Status.Listeners[l.listenerStatusID].AttachedRoutes
}

func (l *ListenerContext) AllowsKind(kind gwapiv1.RouteGroupKind) bool {
for _, allowed := range l.gateway.Status.Listeners[l.listenerStatusId].SupportedKinds {
for _, allowed := range l.gateway.Status.Listeners[l.listenerStatusID].SupportedKinds {
if GroupDerefOr(allowed.Group, "") == GroupDerefOr(kind.Group, "") &&
allowed.Kind == kind.Kind {
return true
Expand Down Expand Up @@ -148,7 +148,7 @@ func (l *ListenerContext) AllowsNamespace(namespace *v1.Namespace) bool {
}

func (l *ListenerContext) IsReady() bool {
for _, cond := range l.gateway.Status.Listeners[l.listenerStatusId].Conditions {
for _, cond := range l.gateway.Status.Listeners[l.listenerStatusID].Conditions {
if cond.Type == string(gwapiv1.ListenerConditionProgrammed) && cond.Status == metav1.ConditionTrue {
return true
}
Expand All @@ -158,7 +158,7 @@ func (l *ListenerContext) IsReady() bool {
}

func (l *ListenerContext) GetConditions() []metav1.Condition {
return l.gateway.Status.Listeners[l.listenerStatusId].Conditions
return l.gateway.Status.Listeners[l.listenerStatusID].Conditions
}

func (l *ListenerContext) SetTLSSecrets(tlsSecrets []*v1.Secret) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// // The full text of the Apache license is available in the LICENSE file at
// // the root of the repo.

// // todo(amali)
package proxy

// import (
Expand Down
16 changes: 16 additions & 0 deletions adapter/internal/operator/gateway-api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,19 @@ func (c *ControllerResources) sort() {
return cmp.Compare(c1.GatewayClass.Name, c2.GatewayClass.Name)
})
}

func (r *Resources) GetEndpointSlicesForBackend(svcNamespace, svcName string, backendKind string) []*discoveryv1.EndpointSlice {
var endpointSlices []*discoveryv1.EndpointSlice
for _, endpointSlice := range r.EndpointSlices {
var backendSelectorLabel string
switch backendKind {
case KindService:
backendSelectorLabel = discoveryv1.LabelServiceName
}
if svcNamespace == endpointSlice.Namespace &&
endpointSlice.GetLabels()[backendSelectorLabel] == svcName {
endpointSlices = append(endpointSlices, endpointSlice)
}
}
return endpointSlices
}
3 changes: 2 additions & 1 deletion adapter/internal/operator/gateway-api/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,8 @@ func (t *Translator) processDestination(backendRefContext BackendRefContext,

// Route to endpoints by default
if !t.EndpointRoutingDisabled {
endpoints, addrType = getIREndpointsFromEndpointSlices(nil, servicePort.Name, servicePort.Protocol)
endpointSlices := resources.GetEndpointSlicesForBackend(backendNamespace, string(backendRef.Name), KindDerefOr(backendRef.Kind, KindService))
endpoints, addrType = getIREndpointsFromEndpointSlices(endpointSlices, servicePort.Name, servicePort.Protocol)
} else {
// Fall back to Service ClusterIP routing
ep := ir.NewDestEndpoint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/

package provider_runner
package runner

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ spec:
mountPath: /home/wso2/security/truststore/partition-server.crt
subPath: {{.Values.wso2.apk.dp.partitionServer.tls.fileName | default "tls.crt"}}
{{- end }}
readinessProbe:
exec:
command: [ "sh", "check_health.sh" ]
initialDelaySeconds: {{ .Values.wso2.apk.dp.adapter.deployment.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.wso2.apk.dp.adapter.deployment.readinessProbe.periodSeconds }}
failureThreshold: {{ .Values.wso2.apk.dp.adapter.deployment.readinessProbe.failureThreshold }}
livenessProbe:
exec:
command: [ "sh", "check_health.sh" ]
initialDelaySeconds: {{ .Values.wso2.apk.dp.adapter.deployment.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.wso2.apk.dp.adapter.deployment.livenessProbe.periodSeconds }}
failureThreshold: {{ .Values.wso2.apk.dp.adapter.deployment.livenessProbe.failureThreshold }}
# readinessProbe:
# exec:
# command: [ "sh", "check_health.sh" ]
# initialDelaySeconds: {{ .Values.wso2.apk.dp.adapter.deployment.readinessProbe.initialDelaySeconds }}
# periodSeconds: {{ .Values.wso2.apk.dp.adapter.deployment.readinessProbe.periodSeconds }}
# failureThreshold: {{ .Values.wso2.apk.dp.adapter.deployment.readinessProbe.failureThreshold }}
# livenessProbe:
# exec:
# command: [ "sh", "check_health.sh" ]
# initialDelaySeconds: {{ .Values.wso2.apk.dp.adapter.deployment.livenessProbe.initialDelaySeconds }}
# periodSeconds: {{ .Values.wso2.apk.dp.adapter.deployment.livenessProbe.periodSeconds }}
# failureThreshold: {{ .Values.wso2.apk.dp.adapter.deployment.livenessProbe.failureThreshold }}
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down

0 comments on commit 5adbaa5

Please sign in to comment.