This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
serviceimport_types.go
192 lines (165 loc) · 6.37 KB
/
serviceimport_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
* MIT License
*
* Copyright (c) since 2021, flomesh.io Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package v1alpha1
import (
"fmt"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
)
// ServiceImportType designates the type of a ServiceImport
type ServiceImportType string
const (
// ClusterSetIP are only accessible via the ClusterSet IP.
ClusterSetIP ServiceImportType = "ClusterSetIP"
// Headless services allow backend pods to be addressed directly.
Headless ServiceImportType = "Headless"
)
// ServiceImportSpec describes an imported service and the information necessary to consume it.
type ServiceImportSpec struct {
// +listType=atomic
Ports []ServicePort `json:"ports"`
// ip will be used as the VIP for this service when type is ClusterSetIP.
// +kubebuilder:validation:MaxItems:=1
// +optional
IPs []string `json:"ips,omitempty"`
// type defines the type of this service.
// Must be ClusterSetIP or Headless.
// +kubebuilder:validation:Enum=ClusterSetIP;Headless
// +optional
Type ServiceImportType `json:"type"`
// Supports "ClientIP" and "None". Used to maintain session affinity.
// Enable client IP based session affinity.
// Must be ClientIP or None.
// Defaults to None.
// Ignored when type is Headless
// More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies
// +optional
SessionAffinity v1.ServiceAffinity `json:"sessionAffinity,omitempty"`
// sessionAffinityConfig contains session affinity configuration.
// +optional
SessionAffinityConfig *v1.SessionAffinityConfig `json:"sessionAffinityConfig,omitempty"`
// +optional
// The ServiceAccount associated with this service
ServiceAccountName string `json:"serviceAccountName,omitempty"`
}
// ServicePort represents the port on which the service is exposed
type ServicePort struct {
// The name of this port within the service. This must be a DNS_LABEL.
// All ports within a ServiceSpec must have unique names. When considering
// the endpoints for a Service, this must match the 'name' field in the
// EndpointPort.
// Optional if only one ServicePort is defined on this service.
// +optional
Name string `json:"name,omitempty"`
// The IP protocol for this port. Supports "TCP", "UDP", and "SCTP".
// Default is TCP.
// +optional
Protocol v1.Protocol `json:"protocol,omitempty"`
// The application protocol for this port.
// This field follows standard Kubernetes label syntax.
// Un-prefixed names are reserved for IANA standard service names (as per
// RFC-6335 and http://www.iana.org/assignments/service-names).
// Non-standard protocols should use prefixed names such as
// mycompany.com/my-custom-protocol.
// Field can be enabled with ServiceAppProtocol feature gate.
// +optional
AppProtocol *string `json:"appProtocol,omitempty"`
// The port that will be exposed by this service.
Port int32 `json:"port"`
// The address of accessing the service
Endpoints []Endpoint `json:"endpoints"`
}
func (p *ServicePort) String() string {
if p == nil {
return "nil"
}
s := strings.Join([]string{`&ServicePort{`,
`Name:` + fmt.Sprintf("%v", p.Name) + `,`,
`Protocol:` + fmt.Sprintf("%v", p.Protocol) + `,`,
`Port:` + fmt.Sprintf("%v", p.Port) + `,`,
`}`,
}, "")
return s
}
type Endpoint struct {
Target Target `json:"target"`
ClusterKey string `json:"clusterKey"`
}
type Target struct {
Host string `json:"host"`
IP string `json:"ip"`
Port int32 `json:"port"`
Path string `json:"path"`
}
// ServiceImportStatus describes derived state of an imported service.
type ServiceImportStatus struct {
// clusters is the list of exporting clusters from which this service
// was derived.
// +optional
// +patchStrategy=merge
// +patchMergeKey=cluster
// +listType=map
// +listMapKey=cluster
Clusters []ClusterStatus `json:"clusters,omitempty"`
}
// ClusterStatus contains service configuration mapped to a specific source cluster
type ClusterStatus struct {
// cluster is the name of the exporting cluster. Must be a valid RFC-1123 DNS
// label.
Cluster string `json:"cluster"`
// in-cluster service, it's the cluster IPs
// otherwise, it's the url of accessing that service in remote cluster
// for example, http(s)://[Ingress IP/domain name]:[port]/[path]
Addresses []string `json:"addresses,omitempty"`
}
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=simp,scope=Namespaced
// +kubebuilder:printcolumn:name="Age",type="date",priority=0,JSONPath=".metadata.creationTimestamp"
// ServiceImport is the Schema for the ServiceImports API
type ServiceImport struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ServiceImportSpec `json:"spec,omitempty"`
Status ServiceImportStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ServiceImportList contains a list of ServiceImport
type ServiceImportList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata.
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
// List of endpoint slices
// +listType=set
Items []ServiceImport `json:"items"`
}
func init() {
SchemeBuilder.Register(&ServiceImport{}, &ServiceImportList{})
}