Skip to content

Commit

Permalink
interface: use the annotation to support serviceExport weight
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiying-lin committed Jan 14, 2025
1 parent f98e10e commit 54d62ea
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 103 deletions.
2 changes: 0 additions & 2 deletions api/v1alpha1/internalserviceexport_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ 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
31 changes: 7 additions & 24 deletions api/v1alpha1/serviceexport_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,6 @@ 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 @@ -62,14 +41,18 @@ type ServiceExportStatus struct {
// +kubebuilder:printcolumn:JSONPath=`.metadata.creationTimestamp`,name="Age",type=date

// ServiceExport declares that the associated service should be exported to other clusters.
// The annotation "networking.fleet.azure.com/weight" specifies the proportion of requests forwarded to the cluster
// within a serviceImport.
// The actual value is the ceiling value of a number 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].
// Any invalid value will default to default value.
// +kubebuilder:validation:XValidation:rule="size(self.metadata.name) < 64",message="metadata.name max length is 63"
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
35 changes: 0 additions & 35 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,26 +115,6 @@ 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
31 changes: 9 additions & 22 deletions config/crd/bases/networking.fleet.azure.com_serviceexports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ spec:
name: v1alpha1
schema:
openAPIV3Schema:
description: ServiceExport declares that the associated service should be
exported to other clusters.
description: |-
ServiceExport declares that the associated service should be exported to other clusters.
The annotation "networking.fleet.azure.com/weight" specifies the proportion of requests forwarded to the cluster
within a serviceImport.
The actual value is the ceiling value of a number 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].
Any invalid value will default to default value.
properties:
apiVersion:
description: |-
Expand All @@ -51,26 +58,6 @@ 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
3 changes: 3 additions & 0 deletions pkg/common/objectmeta/objectmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (
// an exported object.
ExportedObjectAnnotationUniqueName = fleetNetworkingPrefix + "fleet-unique-name"

// ServiceExportAnnotationWeight is an annotation that marks the weight of the ServiceExport.
ServiceExportAnnotationWeight = fleetNetworkingPrefix + "weight"

// ServiceAnnotationAzureLoadBalancerInternal is an annotation that marks the Service as an internal load balancer by cloud-provider-azure.
ServiceAnnotationAzureLoadBalancerInternal = "service.beta.kubernetes.io/azure-load-balancer-internal"

Expand Down

0 comments on commit 54d62ea

Please sign in to comment.