github.com/tigera/api@v0.0.0-20240320170621-278e89a8c5fb/pkg/apis/projectcalico/v3/egressgatewaypolicy.go (about)

     1  // Copyright (c) 2023 Tigera, Inc. All rights reserved.
     2  
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package v3
    16  
    17  import (
    18  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    19  )
    20  
    21  const (
    22  	KindEgressGatewayPolicy     = "EgressGatewayPolicy"
    23  	KindEgressGatewayPolicyList = "EgressGatewayPolicyList"
    24  )
    25  
    26  // +genclient:nonNamespaced
    27  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    28  
    29  // EgressGatewayPolicyList is a list of EgressGatewayPolicy resources.
    30  type EgressGatewayPolicyList struct {
    31  	metav1.TypeMeta `json:",inline"`
    32  	metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    33  
    34  	Items []EgressGatewayPolicy `json:"items" protobuf:"bytes,2,rep,name=items"`
    35  }
    36  
    37  // +genclient
    38  // +genclient:nonNamespaced
    39  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    40  
    41  type EgressGatewayPolicy struct {
    42  	metav1.TypeMeta   `json:",inline"`
    43  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    44  
    45  	Spec EgressGatewayPolicySpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
    46  }
    47  
    48  // EgressGatewayPolicySpec contains the egress policy rules for each destination network
    49  type EgressGatewayPolicySpec struct {
    50  	// The ordered set of Egress Gateway Policies to define how traffic exit a cluster
    51  	Rules []EgressGatewayRule `json:"rules,omitempty" validate:"required"`
    52  }
    53  
    54  // EgressGatewayRule defines an Egress Gateway to reach a destination network
    55  type EgressGatewayRule struct {
    56  	// The destination network that can be reached via egress gateway.
    57  	// If no destination is set, the default route, 0.0.0.0/0, is used instead.
    58  	// +optional
    59  	Destination *EgressGatewayPolicyDestinationSpec `json:"destination,omitempty" validate:"omitempty"`
    60  
    61  	// The description of the EgressGatewayPolicy rule.
    62  	// +optional
    63  	Description string `json:"description,omitempty" validate:"omitempty,uiDescription"`
    64  
    65  	// Gateway specifies the egress gateway that should be used for the specified destination.
    66  	// If no gateway is set then the destination is routed normally rather than via an egress gateway.
    67  	// +optional
    68  	Gateway *EgressSpec `json:"gateway,omitempty" validate:"omitempty"`
    69  
    70  	// GatewayPreference specifies which egress gateways to use. If set to PreferNodeLocal, egress gateways in the same node as
    71  	// the client will be used if available. Otherwise all the active egress gateways will be used.
    72  	// +kubebuilder:default=None
    73  	// +optional
    74  	GatewayPreference *GatewayPreferenceType `json:"gatewayPreference,omitempty" validate:"omitempty,oneof=None,PreferNodeLocal"`
    75  }
    76  
    77  // DestinationSpec define a destination network that can be reached via an egress gateway
    78  type EgressGatewayPolicyDestinationSpec struct {
    79  	// The destination network CIDR.
    80  	CIDR string `json:"cidr,omitempty" validate:"omitempty,net"`
    81  }
    82  
    83  // New EgressGatewayPolicy creates a new (zeroed) EgressGatewayPolicy struct with the TypeMetadata
    84  // initialized to the current version.
    85  func NewEgressGatewayPolicy() *EgressGatewayPolicy {
    86  	return &EgressGatewayPolicy{
    87  		TypeMeta: metav1.TypeMeta{
    88  			Kind:       KindEgressGatewayPolicy,
    89  			APIVersion: GroupVersionCurrent,
    90  		},
    91  	}
    92  }
    93  
    94  // +kubebuilder:validation:Enum=None;PreferNodeLocal
    95  type GatewayPreferenceType string
    96  
    97  const (
    98  	GatewayPreferenceNone      GatewayPreferenceType = "None"
    99  	GatewayPreferenceNodeLocal GatewayPreferenceType = "PreferNodeLocal"
   100  )