github.com/cilium/cilium@v1.16.2/operator/pkg/gateway-api/routechecks/gamma_checks.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package routechecks
     5  
     6  import (
     7  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     8  	gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
     9  )
    10  
    11  func CheckGammaServiceAllowedForNamespace(input Input, parentRef gatewayv1.ParentReference) (bool, error) {
    12  	svc, err := input.GetParentGammaService(parentRef)
    13  	if err != nil {
    14  		input.SetParentCondition(parentRef, metav1.Condition{
    15  			Type:    "Accepted",
    16  			Status:  metav1.ConditionFalse,
    17  			Reason:  "Invalid" + input.GetGVK().Kind,
    18  			Message: err.Error(),
    19  		})
    20  		return false, nil
    21  	}
    22  
    23  	if input.GetNamespace() != svc.GetNamespace() {
    24  		input.SetParentCondition(parentRef, metav1.Condition{
    25  			Type:    "Accepted",
    26  			Status:  metav1.ConditionFalse,
    27  			Reason:  string(gatewayv1.RouteReasonNoMatchingParent),
    28  			Message: input.GetGVK().Kind + " is not allowed to attach to this Service - it and the Service must be in the same namespace",
    29  		})
    30  		return false, nil
    31  	}
    32  	return true, nil
    33  }