Skip to content

Commit

Permalink
add MultiClusterService API
Browse files Browse the repository at this point in the history
Signed-off-by: changzhen <changzhen5@huawei.com>
  • Loading branch information
XiShanYongYe-Chang committed Jun 27, 2023
1 parent 58f6f14 commit 71530fa
Show file tree
Hide file tree
Showing 16 changed files with 1,160 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
name: multiclusterservices.networking.karmada.io
spec:
group: networking.karmada.io
names:
categories:
- karmada-io
kind: MultiClusterService
listKind: MultiClusterServiceList
plural: multiclusterservices
shortNames:
- mcs
singular: multiclusterservice
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: MultiClusterService is a named abstraction of multi-cluster software
service. The name field of MultiClusterService is the same as that of Service
name. Services with the same name in different clusters are regarded as
the same service and are associated with the same MultiClusterService. MultiClusterService
can control the exposure of services to outside multiple clusters, and also
enable service discovery between clusters.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Spec is the desired state of the MultiClusterService.
properties:
ports:
description: Ports is the list of ports that are exposed by this MultiClusterService.
No specified port will be filtered out during the service exposure
and discovery process. All ports in the referencing service will
be exposed by default.
items:
description: ExposurePort describes which port will be exposed.
properties:
name:
description: Name is the name of the port that needs to be exposed
within the service. The port name must be the same as that
defined in the service.
type: string
port:
description: Port specifies the exposed service port.
format: int32
type: integer
type: object
type: array
range:
description: Range specifies the ranges where the referencing service
should be exposed. Only valid and optional in case of Types contains
CrossCluster. If not set and Types contains CrossCluster, all clusters
will be selected, that means the referencing service will be exposed
across all registered clusters.
properties:
clusterNames:
description: ClusterNames is the list of clusters to be selected.
items:
type: string
type: array
type: object
types:
description: Types specifies how to expose the service referencing
by this MultiClusterService.
items:
description: ExposureType describes how to expose the service.
type: string
type: array
required:
- types
type: object
status:
description: Status is the current state of the MultiClusterService.
properties:
conditions:
description: Current service state
items:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
\n type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
// +listType=map // +listMapKey=type Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
transitioned from one status to another. This should be when
the underlying condition changed. If that is not known, then
using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: message is a human readable message indicating
details about the transition. This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: observedGeneration represents the .metadata.generation
that the condition was set based upon. For instance, if .metadata.generation
is currently 12, but the .status.conditions[x].observedGeneration
is 9, the condition is out of date with respect to the current
state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: reason contains a programmatic identifier indicating
the reason for the condition's last transition. Producers
of specific condition types may define expected values and
meanings for this field, and whether the values are considered
a guaranteed API. The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
--- Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
loadBalancer:
description: LoadBalancer contains the current status of the load-balancer,
if one is present.
properties:
ingress:
description: Ingress is a list containing ingress points for the
load-balancer. Traffic intended for the service should be sent
to these ingress points.
items:
description: 'LoadBalancerIngress represents the status of a
load-balancer ingress point: traffic intended for the service
should be sent to an ingress point.'
properties:
hostname:
description: Hostname is set for load-balancer ingress points
that are DNS based (typically AWS load-balancers)
type: string
ip:
description: IP is set for load-balancer ingress points
that are IP based (typically GCE or OpenStack load-balancers)
type: string
ports:
description: Ports is a list of records of service ports
If used, every port defined in the service should have
an entry in it
items:
properties:
error:
description: 'Error is to record the problem with
the service port The format of the error shall comply
with the following rules: - built-in error values
shall be specified in this file and those shall
use CamelCase names - cloud provider specific error
values must have names that comply with the format
foo.example.com/CamelCase. --- The regex it matches
is (dns1123SubdomainFmt/)?(qualifiedNameFmt)'
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
port:
description: Port is the port number of the service
port of which status is recorded here
format: int32
type: integer
protocol:
default: TCP
description: 'Protocol is the protocol of the service
port of which status is recorded here The supported
values are: "TCP", "UDP", "SCTP"'
type: string
required:
- port
- protocol
type: object
type: array
x-kubernetes-list-type: atomic
type: object
type: array
type: object
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
1 change: 1 addition & 0 deletions charts/karmada/_crds/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ resources:
- bases/config.karmada.io_resourceinterpretercustomizations.yaml
- bases/config.karmada.io_resourceinterpreterwebhookconfigurations.yaml
- bases/networking.karmada.io_multiclusteringresses.yaml
- bases/networking.karmada.io_multiclusterservices.yaml
- bases/autoscaling.karmada.io_federatedhpas.yaml

patchesStrategicMerge:
Expand Down
97 changes: 97 additions & 0 deletions pkg/apis/networking/v1alpha1/service_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=mcs,categories={karmada-io}

// MultiClusterService is a named abstraction of multi-cluster software service.
// The name field of MultiClusterService is the same as that of Service name.
// Services with the same name in different clusters are regarded as the same
// service and are associated with the same MultiClusterService.
// MultiClusterService can control the exposure of services to outside multiple
// clusters, and also enable service discovery between clusters.
type MultiClusterService struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec is the desired state of the MultiClusterService.
Spec MultiClusterServiceSpec `json:"spec,omitempty"`

// Status is the current state of the MultiClusterService.
// +optional
Status corev1.ServiceStatus `json:"status,omitempty"`
}

// MultiClusterServiceSpec is the desired state of the MultiClusterService.
type MultiClusterServiceSpec struct {
// Types specifies how to expose the service referencing by this
// MultiClusterService.
// +required
Types []ExposureType `json:"types"`

// Ports is the list of ports that are exposed by this MultiClusterService.
// No specified port will be filtered out during the service
// exposure and discovery process.
// All ports in the referencing service will be exposed by default.
// +optional
Ports []ExposurePort `json:"ports,omitempty"`

// Range specifies the ranges where the referencing service should
// be exposed.
// Only valid and optional in case of Types contains CrossCluster.
// If not set and Types contains CrossCluster, all clusters will
// be selected, that means the referencing service will be exposed
// across all registered clusters.
// +optional
Range ExposureRange `json:"range,omitempty"`
}

// ExposureType describes how to expose the service.
type ExposureType string

const (
// ExposureTypeCrossCluster means a service will be accessible across clusters.
ExposureTypeCrossCluster ExposureType = "CrossCluster"

// ExposureTypeLoadBalancer means a service will be exposed via an external
// load balancer.
ExposureTypeLoadBalancer ExposureType = "LoadBalancer"
)

// ExposurePort describes which port will be exposed.
type ExposurePort struct {
// Name is the name of the port that needs to be exposed within the service.
// The port name must be the same as that defined in the service.
// +optional
Name string `json:"name,omitempty"`

// Port specifies the exposed service port.
// +optional
Port int32 `json:"port,omitempty"`
}

// ExposureRange describes a list of clusters where the service is exposed.
// Now supports selecting cluster by name, leave the room for extend more methods
// such as using label selector.
type ExposureRange struct {
// ClusterNames is the list of clusters to be selected.
// +optional
ClusterNames []string `json:"clusterNames,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// MultiClusterServiceList is a collection of MultiClusterService.
type MultiClusterServiceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

// Items is the list of MultiClusterService.
Items []MultiClusterService `json:"items"`
}
Loading

0 comments on commit 71530fa

Please sign in to comment.