Skip to content

Commit

Permalink
interfaces: update traffic manager APIs to support splitting weight
Browse files Browse the repository at this point in the history
behind serviceImport
  • Loading branch information
zhiying-lin committed Dec 19, 2024
1 parent 5465567 commit e183b0d
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 31 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/internalserviceexport_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
// InternalServiceExportSpec specifies the spec of an exported Service; at this stage only the ports of an
// exported Service are sync'd.
type InternalServiceExportSpec struct {
// ServiceExportSpec contains the spec of the ServiceExport.
ServiceExportSpec *ServiceExportSpec `json:"serviceExportSpec,omitempty"`
// A list of ports exposed by the exported Service.
// +listType=atomic
Ports []ServicePort `json:"ports"`
Expand Down
24 changes: 24 additions & 0 deletions api/v1alpha1/serviceexport_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// ExportedAnnotationsWeight is the key for the weight annotation as an exportedAnnotation on a ServiceExport.
ExportedAnnotationsWeight = "weight"
)

// ServiceExportSpec describes an exported service extra information.
type ServiceExportSpec struct {
// exportedLabels describes the labels exported.
// +optional
ExportedLabels map[string]string `json:"exportedLabels,omitempty"`
// exportedAnnotations describes the annotations exported.
// Possible Annotations: "weight".
// "weight" specifies the proportion of requests forwarded to the cluster within a serviceImport.
// This is computed as weight/(sum of all weights in the serviceImport).
// If weight is set to 0, no traffic should be forwarded for this entry. If unspecified, weight defaults to 1.
// The value should be in the range [0, 1000].
//
// +optional
ExportedAnnotations map[string]string `json:"exportedAnnotations,omitempty"`
}

// ServiceExportConditionType identifies a specific condition on a ServiceExport.
type ServiceExportConditionType string

Expand Down Expand Up @@ -45,6 +66,9 @@ type ServiceExport struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// spec defines the behavior of a ServiceExport.
// +optional
Spec ServiceExportSpec `json:"spec,omitempty"`
// +optional
Status ServiceExportStatus `json:"status,omitempty"`
}
Expand Down
38 changes: 30 additions & 8 deletions api/v1alpha1/trafficmanagerbackend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ type TrafficManagerBackendSpec struct {
Backend TrafficManagerBackendRef `json:"backend"`

// The total weight of endpoints behind the serviceImport when using the 'Weighted' traffic routing method.
// Possible values are from 1 to 1000.
// By default, the routing method is 'Weighted', so that it is required for now.
// Possible values are from 0 to 1000.
// By default, the routing method is 'Weighted'.
// If weight is set to 0, all the endpoints behind the serviceImport will be removed from the profile.
// The actual weight of each endpoint is the ceiling value of a number computed as weight/(sum of all weights behind the serviceImport)
// * weight of serviceExport.
// For example, if the weight is 500 and there are two serviceExports from cluster-1 (weight: 100) and cluster-2 (weight: 200)
// behind serviceImport.
// As a result, two endpoints will be created.
// The weight of endpoint from cluster-1 is 100/(100+200)*500 = 167, and the weight of the cluster-2 is 200/(100+200)*500 = 334.
// There may be slight deviations from the exact proportions defined in the serviceExports due to ceiling calculations.
// +optional
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=1000
// For example, if there are two clusters exporting the service via public ip, each public ip will be configured
// as "Weight"/2.
// +kubebuilder:default=1
Weight *int64 `json:"weight,omitempty"`
}

Expand All @@ -75,18 +82,33 @@ type TrafficManagerEndpointStatus struct {
// +required
Name string `json:"name"`

// ResourceID is the fully qualified Azure resource Id for the resource.
// Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficManagerProfiles/{profileName}/azureEndpoints/{name}
ResourceID string `json:"resourceID,omitempty"`

// The weight of this endpoint when using the 'Weighted' traffic routing method.
// Possible values are from 1 to 1000.
// Possible values are from 0 to 1000.
// +optional
Weight *int64 `json:"weight,omitempty"`

// The fully-qualified DNS name or IP address of the endpoint.
// +optional
Target *string `json:"target,omitempty"`

// Cluster is where the endpoint is exported from.
// From is where the endpoint is exported from.
// +optional
From *FromCluster `json:"from,omitempty"`
}

// FromCluster contains service configuration mapped to a specific source cluster.
type FromCluster struct {
// ClusterStatus describes the source cluster status.
ClusterStatus `json:",inline"`

// Weight defines the weight configured in the serviceExport from the source cluster.
// Possible values are from 0 to 1000.
// +optional
Cluster *ClusterStatus `json:"cluster,omitempty"`
Weight *int64 `json:"weight,omitempty"`
}

type TrafficManagerBackendStatus struct {
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/trafficmanagerprofile_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ type TrafficManagerProfileStatus struct {
// +optional
DNSName *string `json:"dnsName,omitempty"`

// ResourceID is the fully qualified Azure resource Id for the resource.
// Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficManagerProfiles/{resourceName}
ResourceID string `json:"resourceID,omitempty"`

// Current profile status.
// +optional
// +patchMergeKey=type
Expand Down
66 changes: 61 additions & 5 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ spec:
type: object
type: array
x-kubernetes-list-type: atomic
serviceExportSpec:
description: ServiceExportSpec contains the spec of the ServiceExport.
properties:
exportedAnnotations:
additionalProperties:
type: string
description: |-
exportedAnnotations describes the annotations exported.
Possible Annotations: "weight".
"weight" specifies the proportion of requests forwarded to the cluster within a serviceImport.
This is computed as weight/(sum of all weights in the serviceImport).
If weight is set to 0, no traffic should be forwarded for this entry. If unspecified, weight defaults to 1.
The value should be in the range [0, 1000].
type: object
exportedLabels:
additionalProperties:
type: string
description: exportedLabels describes the labels exported.
type: object
type: object
serviceReference:
description: The reference to the source Service.
properties:
Expand Down
20 changes: 20 additions & 0 deletions config/crd/bases/networking.fleet.azure.com_serviceexports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ spec:
type: string
metadata:
type: object
spec:
description: spec defines the behavior of a ServiceExport.
properties:
exportedAnnotations:
additionalProperties:
type: string
description: |-
exportedAnnotations describes the annotations exported.
Possible Annotations: "weight".
"weight" specifies the proportion of requests forwarded to the cluster within a serviceImport.
This is computed as weight/(sum of all weights in the serviceImport).
If weight is set to 0, no traffic should be forwarded for this entry. If unspecified, weight defaults to 1.
The value should be in the range [0, 1000].
type: object
exportedLabels:
additionalProperties:
type: string
description: exportedLabels describes the labels exported.
type: object
type: object
status:
description: ServiceExportStatus contains the current status of an export.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,22 @@ spec:
- message: spec.profile is immutable
rule: self == oldSelf
weight:
default: 1
description: |-
The total weight of endpoints behind the serviceImport when using the 'Weighted' traffic routing method.
Possible values are from 1 to 1000.
By default, the routing method is 'Weighted', so that it is required for now.
For example, if there are two clusters exporting the service via public ip, each public ip will be configured
as "Weight"/2.
Possible values are from 0 to 1000.
By default, the routing method is 'Weighted'.
If weight is set to 0, all the endpoints behind the serviceImport will be removed from the profile.
The actual weight of each endpoint is the ceiling value of a number computed as weight/(sum of all weights behind the serviceImport)
* weight of serviceExport.
For example, if the weight is 500 and there are two serviceExports from cluster-1 (weight: 100) and cluster-2 (weight: 200)
behind serviceImport.
As a result, two endpoints will be created.
The weight of endpoint from cluster-1 is 100/(100+200)*500 = 167, and the weight of the cluster-2 is 200/(100+200)*500 = 334.
There may be slight deviations from the exact proportions defined in the serviceExports due to ceiling calculations.
format: int64
maximum: 1000
minimum: 1
minimum: 0
type: integer
required:
- backend
Expand Down Expand Up @@ -172,27 +179,38 @@ spec:
TrafficManagerEndpointStatus is the status of Azure Traffic Manager endpoint which is successfully accepted under the traffic
manager Profile.
properties:
cluster:
description: Cluster is where the endpoint is exported from.
from:
description: From is where the endpoint is exported from.
properties:
cluster:
description: cluster is the name of the exporting cluster.
Must be a valid RFC-1123 DNS label.
type: string
weight:
description: |-
Weight defines the weight configured in the serviceExport from the source cluster.
Possible values are from 0 to 1000.
format: int64
type: integer
required:
- cluster
type: object
name:
description: Name of the endpoint.
type: string
resourceID:
description: |-
ResourceID is the fully qualified Azure resource Id for the resource.
Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficManagerProfiles/{profileName}/azureEndpoints/{name}
type: string
target:
description: The fully-qualified DNS name or IP address of the
endpoint.
type: string
weight:
description: |-
The weight of this endpoint when using the 'Weighted' traffic routing method.
Possible values are from 1 to 1000.
Possible values are from 0 to 1000.
format: int64
type: integer
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ spec:
domain name (FQDN) of the profile.
For example, "<TrafficManagerProfileNamespace>-<TrafficManagerProfileName>.trafficmanager.net"
type: string
resourceID:
description: |-
ResourceID is the fully qualified Azure resource Id for the resource.
Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficManagerProfiles/{resourceName}
type: string
type: object
required:
- spec
Expand Down
Loading

0 comments on commit e183b0d

Please sign in to comment.