Skip to content

Commit

Permalink
fix: dont accept gws with non IP addrs
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneutt committed Sep 26, 2023
1 parent a4377b9 commit 3af7909
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions controllers/gateway_controller_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import (
"context"
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -90,16 +91,28 @@ func updateGatewayStatus(_ context.Context, gateway *gatewayv1beta1.Gateway, svc
// initGatewayStatus initializes the GatewayStatus, setting the ready condition to
// not ready and all the listeners ready status to not ready as well.
func initGatewayStatus(gateway *gatewayv1beta1.Gateway) {
accepted := metav1.Condition{
Type: string(gatewayv1beta1.GatewayConditionAccepted),
Status: metav1.ConditionTrue,
Reason: string(gatewayv1beta1.GatewayReasonAccepted),
ObservedGeneration: gateway.Generation,
LastTransitionTime: metav1.Now(),
Message: "blixt controlplane accepts responsibility for the Gateway",
}
if unsupportedAddr, addrType := gatewayHasUnsupportedAddresses(gateway); unsupportedAddr {
accepted = metav1.Condition{
Type: string(gatewayv1beta1.GatewayConditionAccepted),
Status: metav1.ConditionFalse,
Reason: string(gatewayv1beta1.GatewayReasonUnsupportedAddress),
ObservedGeneration: gateway.Generation,
LastTransitionTime: metav1.Now(),
Message: fmt.Sprintf("blixt only supports Gateway addresses of type IPAddress, %s is not supported", addrType),
}
}

gateway.Status = gatewayv1beta1.GatewayStatus{
Conditions: []metav1.Condition{
{
Type: string(gatewayv1beta1.GatewayConditionAccepted),
Status: metav1.ConditionTrue,
Reason: string(gatewayv1beta1.GatewayReasonAccepted),
ObservedGeneration: gateway.Generation,
LastTransitionTime: metav1.Now(),
Message: "blixt controlplane accepts responsibility for the Gateway",
},
accepted,
{
Type: string(gatewayv1beta1.GatewayConditionProgrammed),
Status: metav1.ConditionFalse,
Expand Down Expand Up @@ -230,3 +243,12 @@ func isGatewayProgrammed(gateway *gatewayv1beta1.Gateway) (status bool, isSet bo
}
return false, false
}

func gatewayHasUnsupportedAddresses(gateway *gatewayv1beta1.Gateway) (bool, string) {
for _, addr := range gateway.Spec.Addresses {
if addr.Type != nil && *addr.Type != gatewayv1beta1.IPAddressType {
return false, string(*addr.Type)
}
}
return true, ""
}

0 comments on commit 3af7909

Please sign in to comment.