Commit 22dfaef9 authored by k8s-merge-robot's avatar k8s-merge-robot

Merge pull request #24943 from XiaoningDing/federation-copy-server-address-by-client-cidr

Automatic merge from submit-queue copy ServerAddressByClientCIDR to federation types #24016 copy ServerAddressByClientCIDR to federation types update generated files [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/.github/PULL_REQUEST_TEMPLATE.md?pixel)]()
parents c10d12b7 4e6e51dc
...@@ -35,6 +35,7 @@ func init() { ...@@ -35,6 +35,7 @@ func init() {
DeepCopy_federation_ClusterMeta, DeepCopy_federation_ClusterMeta,
DeepCopy_federation_ClusterSpec, DeepCopy_federation_ClusterSpec,
DeepCopy_federation_ClusterStatus, DeepCopy_federation_ClusterStatus,
DeepCopy_federation_ServerAddressByClientCIDR,
); err != nil { ); err != nil {
// if one of the deep copy functions is malformed, detect it immediately. // if one of the deep copy functions is malformed, detect it immediately.
panic(err) panic(err)
...@@ -100,9 +101,9 @@ func DeepCopy_federation_ClusterMeta(in ClusterMeta, out *ClusterMeta, c *conver ...@@ -100,9 +101,9 @@ func DeepCopy_federation_ClusterMeta(in ClusterMeta, out *ClusterMeta, c *conver
func DeepCopy_federation_ClusterSpec(in ClusterSpec, out *ClusterSpec, c *conversion.Cloner) error { func DeepCopy_federation_ClusterSpec(in ClusterSpec, out *ClusterSpec, c *conversion.Cloner) error {
if in.ServerAddressByClientCIDRs != nil { if in.ServerAddressByClientCIDRs != nil {
in, out := in.ServerAddressByClientCIDRs, &out.ServerAddressByClientCIDRs in, out := in.ServerAddressByClientCIDRs, &out.ServerAddressByClientCIDRs
*out = make([]unversioned.ServerAddressByClientCIDR, len(in)) *out = make([]ServerAddressByClientCIDR, len(in))
for i := range in { for i := range in {
if err := unversioned.DeepCopy_unversioned_ServerAddressByClientCIDR(in[i], &(*out)[i], c); err != nil { if err := DeepCopy_federation_ServerAddressByClientCIDR(in[i], &(*out)[i], c); err != nil {
return err return err
} }
} }
...@@ -156,3 +157,9 @@ func DeepCopy_federation_ClusterStatus(in ClusterStatus, out *ClusterStatus, c * ...@@ -156,3 +157,9 @@ func DeepCopy_federation_ClusterStatus(in ClusterStatus, out *ClusterStatus, c *
} }
return nil return nil
} }
func DeepCopy_federation_ServerAddressByClientCIDR(in ServerAddressByClientCIDR, out *ServerAddressByClientCIDR, c *conversion.Cloner) error {
out.ClientCIDR = in.ClientCIDR
out.ServerAddress = in.ServerAddress
return nil
}
...@@ -21,13 +21,22 @@ import ( ...@@ -21,13 +21,22 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/unversioned"
) )
// ServerAddressByClientCIDR helps the client to determine the server address that they should use, depending on the clientCIDR that they match.
type ServerAddressByClientCIDR struct {
// The CIDR with which clients can match their IP to figure out the server address that they should use.
ClientCIDR string `json:"clientCIDR" protobuf:"bytes,1,opt,name=clientCIDR"`
// Address of this server, suitable for a client that matches the above CIDR.
// This can be a hostname, hostname:port, IP or IP:port.
ServerAddress string `json:"serverAddress" protobuf:"bytes,2,opt,name=serverAddress"`
}
// ClusterSpec describes the attributes of a kubernetes cluster. // ClusterSpec describes the attributes of a kubernetes cluster.
type ClusterSpec struct { type ClusterSpec struct {
// A map of client CIDR to server address. // A map of client CIDR to server address.
// This is to help clients reach servers in the most network-efficient way possible. // This is to help clients reach servers in the most network-efficient way possible.
// Clients can use the appropriate server address as per the CIDR that they match. // Clients can use the appropriate server address as per the CIDR that they match.
// In case of multiple matches, clients should use the longest matching CIDR. // In case of multiple matches, clients should use the longest matching CIDR.
ServerAddressByClientCIDRs []unversioned.ServerAddressByClientCIDR `json:"serverAddressByClientCIDRs" patchStrategy:"merge" patchMergeKey:"clientCIDR"` ServerAddressByClientCIDRs []ServerAddressByClientCIDR `json:"serverAddressByClientCIDRs" patchStrategy:"merge" patchMergeKey:"clientCIDR"`
// the type (e.g. bearer token, client certificate etc) and data of the credential used to access cluster. // the type (e.g. bearer token, client certificate etc) and data of the credential used to access cluster.
// It’s used for system routines (not behalf of users) // It’s used for system routines (not behalf of users)
// TODO: string may not enough, https://github.com/kubernetes/kubernetes/pull/23847#discussion_r59301275 // TODO: string may not enough, https://github.com/kubernetes/kubernetes/pull/23847#discussion_r59301275
......
...@@ -24,7 +24,6 @@ import ( ...@@ -24,7 +24,6 @@ import (
federation "k8s.io/kubernetes/federation/apis/federation" federation "k8s.io/kubernetes/federation/apis/federation"
api "k8s.io/kubernetes/pkg/api" api "k8s.io/kubernetes/pkg/api"
resource "k8s.io/kubernetes/pkg/api/resource" resource "k8s.io/kubernetes/pkg/api/resource"
unversioned "k8s.io/kubernetes/pkg/api/unversioned"
v1 "k8s.io/kubernetes/pkg/api/v1" v1 "k8s.io/kubernetes/pkg/api/v1"
conversion "k8s.io/kubernetes/pkg/conversion" conversion "k8s.io/kubernetes/pkg/conversion"
) )
...@@ -43,6 +42,8 @@ func init() { ...@@ -43,6 +42,8 @@ func init() {
Convert_federation_ClusterSpec_To_v1alpha1_ClusterSpec, Convert_federation_ClusterSpec_To_v1alpha1_ClusterSpec,
Convert_v1alpha1_ClusterStatus_To_federation_ClusterStatus, Convert_v1alpha1_ClusterStatus_To_federation_ClusterStatus,
Convert_federation_ClusterStatus_To_v1alpha1_ClusterStatus, Convert_federation_ClusterStatus_To_v1alpha1_ClusterStatus,
Convert_v1alpha1_ServerAddressByClientCIDR_To_federation_ServerAddressByClientCIDR,
Convert_federation_ServerAddressByClientCIDR_To_v1alpha1_ServerAddressByClientCIDR,
); err != nil { ); err != nil {
// if one of the conversion functions is malformed, detect it immediately. // if one of the conversion functions is malformed, detect it immediately.
panic(err) panic(err)
...@@ -198,10 +199,9 @@ func Convert_federation_ClusterMeta_To_v1alpha1_ClusterMeta(in *federation.Clust ...@@ -198,10 +199,9 @@ func Convert_federation_ClusterMeta_To_v1alpha1_ClusterMeta(in *federation.Clust
func autoConvert_v1alpha1_ClusterSpec_To_federation_ClusterSpec(in *ClusterSpec, out *federation.ClusterSpec, s conversion.Scope) error { func autoConvert_v1alpha1_ClusterSpec_To_federation_ClusterSpec(in *ClusterSpec, out *federation.ClusterSpec, s conversion.Scope) error {
if in.ServerAddressByClientCIDRs != nil { if in.ServerAddressByClientCIDRs != nil {
in, out := &in.ServerAddressByClientCIDRs, &out.ServerAddressByClientCIDRs in, out := &in.ServerAddressByClientCIDRs, &out.ServerAddressByClientCIDRs
*out = make([]unversioned.ServerAddressByClientCIDR, len(*in)) *out = make([]federation.ServerAddressByClientCIDR, len(*in))
for i := range *in { for i := range *in {
// TODO: Inefficient conversion - can we improve it? if err := Convert_v1alpha1_ServerAddressByClientCIDR_To_federation_ServerAddressByClientCIDR(&(*in)[i], &(*out)[i], s); err != nil {
if err := s.Convert(&(*in)[i], &(*out)[i], 0); err != nil {
return err return err
} }
} }
...@@ -219,10 +219,9 @@ func Convert_v1alpha1_ClusterSpec_To_federation_ClusterSpec(in *ClusterSpec, out ...@@ -219,10 +219,9 @@ func Convert_v1alpha1_ClusterSpec_To_federation_ClusterSpec(in *ClusterSpec, out
func autoConvert_federation_ClusterSpec_To_v1alpha1_ClusterSpec(in *federation.ClusterSpec, out *ClusterSpec, s conversion.Scope) error { func autoConvert_federation_ClusterSpec_To_v1alpha1_ClusterSpec(in *federation.ClusterSpec, out *ClusterSpec, s conversion.Scope) error {
if in.ServerAddressByClientCIDRs != nil { if in.ServerAddressByClientCIDRs != nil {
in, out := &in.ServerAddressByClientCIDRs, &out.ServerAddressByClientCIDRs in, out := &in.ServerAddressByClientCIDRs, &out.ServerAddressByClientCIDRs
*out = make([]unversioned.ServerAddressByClientCIDR, len(*in)) *out = make([]ServerAddressByClientCIDR, len(*in))
for i := range *in { for i := range *in {
// TODO: Inefficient conversion - can we improve it? if err := Convert_federation_ServerAddressByClientCIDR_To_v1alpha1_ServerAddressByClientCIDR(&(*in)[i], &(*out)[i], s); err != nil {
if err := s.Convert(&(*in)[i], &(*out)[i], 0); err != nil {
return err return err
} }
} }
...@@ -312,3 +311,23 @@ func autoConvert_federation_ClusterStatus_To_v1alpha1_ClusterStatus(in *federati ...@@ -312,3 +311,23 @@ func autoConvert_federation_ClusterStatus_To_v1alpha1_ClusterStatus(in *federati
func Convert_federation_ClusterStatus_To_v1alpha1_ClusterStatus(in *federation.ClusterStatus, out *ClusterStatus, s conversion.Scope) error { func Convert_federation_ClusterStatus_To_v1alpha1_ClusterStatus(in *federation.ClusterStatus, out *ClusterStatus, s conversion.Scope) error {
return autoConvert_federation_ClusterStatus_To_v1alpha1_ClusterStatus(in, out, s) return autoConvert_federation_ClusterStatus_To_v1alpha1_ClusterStatus(in, out, s)
} }
func autoConvert_v1alpha1_ServerAddressByClientCIDR_To_federation_ServerAddressByClientCIDR(in *ServerAddressByClientCIDR, out *federation.ServerAddressByClientCIDR, s conversion.Scope) error {
out.ClientCIDR = in.ClientCIDR
out.ServerAddress = in.ServerAddress
return nil
}
func Convert_v1alpha1_ServerAddressByClientCIDR_To_federation_ServerAddressByClientCIDR(in *ServerAddressByClientCIDR, out *federation.ServerAddressByClientCIDR, s conversion.Scope) error {
return autoConvert_v1alpha1_ServerAddressByClientCIDR_To_federation_ServerAddressByClientCIDR(in, out, s)
}
func autoConvert_federation_ServerAddressByClientCIDR_To_v1alpha1_ServerAddressByClientCIDR(in *federation.ServerAddressByClientCIDR, out *ServerAddressByClientCIDR, s conversion.Scope) error {
out.ClientCIDR = in.ClientCIDR
out.ServerAddress = in.ServerAddress
return nil
}
func Convert_federation_ServerAddressByClientCIDR_To_v1alpha1_ServerAddressByClientCIDR(in *federation.ServerAddressByClientCIDR, out *ServerAddressByClientCIDR, s conversion.Scope) error {
return autoConvert_federation_ServerAddressByClientCIDR_To_v1alpha1_ServerAddressByClientCIDR(in, out, s)
}
...@@ -36,6 +36,7 @@ func init() { ...@@ -36,6 +36,7 @@ func init() {
DeepCopy_v1alpha1_ClusterMeta, DeepCopy_v1alpha1_ClusterMeta,
DeepCopy_v1alpha1_ClusterSpec, DeepCopy_v1alpha1_ClusterSpec,
DeepCopy_v1alpha1_ClusterStatus, DeepCopy_v1alpha1_ClusterStatus,
DeepCopy_v1alpha1_ServerAddressByClientCIDR,
); err != nil { ); err != nil {
// if one of the deep copy functions is malformed, detect it immediately. // if one of the deep copy functions is malformed, detect it immediately.
panic(err) panic(err)
...@@ -101,9 +102,9 @@ func DeepCopy_v1alpha1_ClusterMeta(in ClusterMeta, out *ClusterMeta, c *conversi ...@@ -101,9 +102,9 @@ func DeepCopy_v1alpha1_ClusterMeta(in ClusterMeta, out *ClusterMeta, c *conversi
func DeepCopy_v1alpha1_ClusterSpec(in ClusterSpec, out *ClusterSpec, c *conversion.Cloner) error { func DeepCopy_v1alpha1_ClusterSpec(in ClusterSpec, out *ClusterSpec, c *conversion.Cloner) error {
if in.ServerAddressByClientCIDRs != nil { if in.ServerAddressByClientCIDRs != nil {
in, out := in.ServerAddressByClientCIDRs, &out.ServerAddressByClientCIDRs in, out := in.ServerAddressByClientCIDRs, &out.ServerAddressByClientCIDRs
*out = make([]unversioned.ServerAddressByClientCIDR, len(in)) *out = make([]ServerAddressByClientCIDR, len(in))
for i := range in { for i := range in {
if err := unversioned.DeepCopy_unversioned_ServerAddressByClientCIDR(in[i], &(*out)[i], c); err != nil { if err := DeepCopy_v1alpha1_ServerAddressByClientCIDR(in[i], &(*out)[i], c); err != nil {
return err return err
} }
} }
...@@ -157,3 +158,9 @@ func DeepCopy_v1alpha1_ClusterStatus(in ClusterStatus, out *ClusterStatus, c *co ...@@ -157,3 +158,9 @@ func DeepCopy_v1alpha1_ClusterStatus(in ClusterStatus, out *ClusterStatus, c *co
} }
return nil return nil
} }
func DeepCopy_v1alpha1_ServerAddressByClientCIDR(in ServerAddressByClientCIDR, out *ServerAddressByClientCIDR, c *conversion.Cloner) error {
out.ClientCIDR = in.ClientCIDR
out.ServerAddress = in.ServerAddress
return nil
}
...@@ -31,6 +31,7 @@ limitations under the License. ...@@ -31,6 +31,7 @@ limitations under the License.
ClusterMeta ClusterMeta
ClusterSpec ClusterSpec
ClusterStatus ClusterStatus
ServerAddressByClientCIDR
*/ */
package v1alpha1 package v1alpha1
...@@ -39,7 +40,7 @@ import fmt "fmt" ...@@ -39,7 +40,7 @@ import fmt "fmt"
import math "math" import math "math"
import k8s_io_kubernetes_pkg_api_resource "k8s.io/kubernetes/pkg/api/resource" import k8s_io_kubernetes_pkg_api_resource "k8s.io/kubernetes/pkg/api/resource"
import k8s_io_kubernetes_pkg_api_unversioned "k8s.io/kubernetes/pkg/api/unversioned"
import k8s_io_kubernetes_pkg_api_v1 "k8s.io/kubernetes/pkg/api/v1" import k8s_io_kubernetes_pkg_api_v1 "k8s.io/kubernetes/pkg/api/v1"
import io "io" import io "io"
...@@ -73,6 +74,10 @@ func (m *ClusterStatus) Reset() { *m = ClusterStatus{} } ...@@ -73,6 +74,10 @@ func (m *ClusterStatus) Reset() { *m = ClusterStatus{} }
func (m *ClusterStatus) String() string { return proto.CompactTextString(m) } func (m *ClusterStatus) String() string { return proto.CompactTextString(m) }
func (*ClusterStatus) ProtoMessage() {} func (*ClusterStatus) ProtoMessage() {}
func (m *ServerAddressByClientCIDR) Reset() { *m = ServerAddressByClientCIDR{} }
func (m *ServerAddressByClientCIDR) String() string { return proto.CompactTextString(m) }
func (*ServerAddressByClientCIDR) ProtoMessage() {}
func init() { func init() {
proto.RegisterType((*Cluster)(nil), "k8s.io.kubernetes.federation.apis.federation.v1alpha1.Cluster") proto.RegisterType((*Cluster)(nil), "k8s.io.kubernetes.federation.apis.federation.v1alpha1.Cluster")
proto.RegisterType((*ClusterCondition)(nil), "k8s.io.kubernetes.federation.apis.federation.v1alpha1.ClusterCondition") proto.RegisterType((*ClusterCondition)(nil), "k8s.io.kubernetes.federation.apis.federation.v1alpha1.ClusterCondition")
...@@ -80,6 +85,7 @@ func init() { ...@@ -80,6 +85,7 @@ func init() {
proto.RegisterType((*ClusterMeta)(nil), "k8s.io.kubernetes.federation.apis.federation.v1alpha1.ClusterMeta") proto.RegisterType((*ClusterMeta)(nil), "k8s.io.kubernetes.federation.apis.federation.v1alpha1.ClusterMeta")
proto.RegisterType((*ClusterSpec)(nil), "k8s.io.kubernetes.federation.apis.federation.v1alpha1.ClusterSpec") proto.RegisterType((*ClusterSpec)(nil), "k8s.io.kubernetes.federation.apis.federation.v1alpha1.ClusterSpec")
proto.RegisterType((*ClusterStatus)(nil), "k8s.io.kubernetes.federation.apis.federation.v1alpha1.ClusterStatus") proto.RegisterType((*ClusterStatus)(nil), "k8s.io.kubernetes.federation.apis.federation.v1alpha1.ClusterStatus")
proto.RegisterType((*ServerAddressByClientCIDR)(nil), "k8s.io.kubernetes.federation.apis.federation.v1alpha1.ServerAddressByClientCIDR")
} }
func (m *Cluster) Marshal() (data []byte, err error) { func (m *Cluster) Marshal() (data []byte, err error) {
size := m.Size() size := m.Size()
...@@ -349,6 +355,32 @@ func (m *ClusterStatus) MarshalTo(data []byte) (int, error) { ...@@ -349,6 +355,32 @@ func (m *ClusterStatus) MarshalTo(data []byte) (int, error) {
return i, nil return i, nil
} }
func (m *ServerAddressByClientCIDR) Marshal() (data []byte, err error) {
size := m.Size()
data = make([]byte, size)
n, err := m.MarshalTo(data)
if err != nil {
return nil, err
}
return data[:n], nil
}
func (m *ServerAddressByClientCIDR) MarshalTo(data []byte) (int, error) {
var i int
_ = i
var l int
_ = l
data[i] = 0xa
i++
i = encodeVarintGenerated(data, i, uint64(len(m.ClientCIDR)))
i += copy(data[i:], m.ClientCIDR)
data[i] = 0x12
i++
i = encodeVarintGenerated(data, i, uint64(len(m.ServerAddress)))
i += copy(data[i:], m.ServerAddress)
return i, nil
}
func encodeFixed64Generated(data []byte, offset int, v uint64) int { func encodeFixed64Generated(data []byte, offset int, v uint64) int {
data[offset] = uint8(v) data[offset] = uint8(v)
data[offset+1] = uint8(v >> 8) data[offset+1] = uint8(v >> 8)
...@@ -474,6 +506,16 @@ func (m *ClusterStatus) Size() (n int) { ...@@ -474,6 +506,16 @@ func (m *ClusterStatus) Size() (n int) {
return n return n
} }
func (m *ServerAddressByClientCIDR) Size() (n int) {
var l int
_ = l
l = len(m.ClientCIDR)
n += 1 + l + sovGenerated(uint64(l))
l = len(m.ServerAddress)
n += 1 + l + sovGenerated(uint64(l))
return n
}
func sovGenerated(x uint64) (n int) { func sovGenerated(x uint64) (n int) {
for { for {
n++ n++
...@@ -1098,7 +1140,7 @@ func (m *ClusterSpec) Unmarshal(data []byte) error { ...@@ -1098,7 +1140,7 @@ func (m *ClusterSpec) Unmarshal(data []byte) error {
if postIndex > l { if postIndex > l {
return io.ErrUnexpectedEOF return io.ErrUnexpectedEOF
} }
m.ServerAddressByClientCIDRs = append(m.ServerAddressByClientCIDRs, k8s_io_kubernetes_pkg_api_unversioned.ServerAddressByClientCIDR{}) m.ServerAddressByClientCIDRs = append(m.ServerAddressByClientCIDRs, ServerAddressByClientCIDR{})
if err := m.ServerAddressByClientCIDRs[len(m.ServerAddressByClientCIDRs)-1].Unmarshal(data[iNdEx:postIndex]); err != nil { if err := m.ServerAddressByClientCIDRs[len(m.ServerAddressByClientCIDRs)-1].Unmarshal(data[iNdEx:postIndex]); err != nil {
return err return err
} }
...@@ -1496,6 +1538,114 @@ func (m *ClusterStatus) Unmarshal(data []byte) error { ...@@ -1496,6 +1538,114 @@ func (m *ClusterStatus) Unmarshal(data []byte) error {
} }
return nil return nil
} }
func (m *ServerAddressByClientCIDR) Unmarshal(data []byte) error {
l := len(data)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenerated
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ServerAddressByClientCIDR: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ServerAddressByClientCIDR: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ClientCIDR", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenerated
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthGenerated
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ClientCIDR = string(data[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ServerAddress", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenerated
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthGenerated
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ServerAddress = string(data[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipGenerated(data[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthGenerated
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipGenerated(data []byte) (n int, err error) { func skipGenerated(data []byte) (n int, err error) {
l := len(data) l := len(data)
iNdEx := 0 iNdEx := 0
......
...@@ -85,7 +85,7 @@ message ClusterSpec { ...@@ -85,7 +85,7 @@ message ClusterSpec {
// This is to help clients reach servers in the most network-efficient way possible. // This is to help clients reach servers in the most network-efficient way possible.
// Clients can use the appropriate server address as per the CIDR that they match. // Clients can use the appropriate server address as per the CIDR that they match.
// In case of multiple matches, clients should use the longest matching CIDR. // In case of multiple matches, clients should use the longest matching CIDR.
repeated k8s.io.kubernetes.pkg.api.unversioned.ServerAddressByClientCIDR serverAddressByClientCIDRs = 1; repeated ServerAddressByClientCIDR serverAddressByClientCIDRs = 1;
// the type (e.g. bearer token, client certificate etc) and data of the credential used to access cluster. // the type (e.g. bearer token, client certificate etc) and data of the credential used to access cluster.
// It’s used for system routines (not behalf of users) // It’s used for system routines (not behalf of users)
...@@ -107,3 +107,13 @@ message ClusterStatus { ...@@ -107,3 +107,13 @@ message ClusterStatus {
optional ClusterMeta clusterMeta = 4; optional ClusterMeta clusterMeta = 4;
} }
// ServerAddressByClientCIDR helps the client to determine the server address that they should use, depending on the clientCIDR that they match.
message ServerAddressByClientCIDR {
// The CIDR with which clients can match their IP to figure out the server address that they should use.
optional string clientCIDR = 1;
// Address of this server, suitable for a client that matches the above CIDR.
// This can be a hostname, hostname:port, IP or IP:port.
optional string serverAddress = 2;
}
...@@ -21,13 +21,22 @@ import ( ...@@ -21,13 +21,22 @@ import (
"k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/api/v1"
) )
// ServerAddressByClientCIDR helps the client to determine the server address that they should use, depending on the clientCIDR that they match.
type ServerAddressByClientCIDR struct {
// The CIDR with which clients can match their IP to figure out the server address that they should use.
ClientCIDR string `json:"clientCIDR" protobuf:"bytes,1,opt,name=clientCIDR"`
// Address of this server, suitable for a client that matches the above CIDR.
// This can be a hostname, hostname:port, IP or IP:port.
ServerAddress string `json:"serverAddress" protobuf:"bytes,2,opt,name=serverAddress"`
}
// ClusterSpec describes the attributes of a kubernetes cluster. // ClusterSpec describes the attributes of a kubernetes cluster.
type ClusterSpec struct { type ClusterSpec struct {
// A map of client CIDR to server address. // A map of client CIDR to server address.
// This is to help clients reach servers in the most network-efficient way possible. // This is to help clients reach servers in the most network-efficient way possible.
// Clients can use the appropriate server address as per the CIDR that they match. // Clients can use the appropriate server address as per the CIDR that they match.
// In case of multiple matches, clients should use the longest matching CIDR. // In case of multiple matches, clients should use the longest matching CIDR.
ServerAddressByClientCIDRs []unversioned.ServerAddressByClientCIDR `json:"serverAddressByClientCIDRs" patchStrategy:"merge" patchMergeKey:"clientCIDR" protobuf:"bytes,1,rep,name=serverAddressByClientCIDRs"` ServerAddressByClientCIDRs []ServerAddressByClientCIDR `json:"serverAddressByClientCIDRs" patchStrategy:"merge" patchMergeKey:"clientCIDR" protobuf:"bytes,1,rep,name=serverAddressByClientCIDRs"`
// the type (e.g. bearer token, client certificate etc) and data of the credential used to access cluster. // the type (e.g. bearer token, client certificate etc) and data of the credential used to access cluster.
// It’s used for system routines (not behalf of users) // It’s used for system routines (not behalf of users)
// TODO: string may not enough, https://github.com/kubernetes/kubernetes/pull/23847#discussion_r59301275 // TODO: string may not enough, https://github.com/kubernetes/kubernetes/pull/23847#discussion_r59301275
......
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"k8s.io/kubernetes/federation/apis/federation" "k8s.io/kubernetes/federation/apis/federation"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
) )
func TestValidateCluster(t *testing.T) { func TestValidateCluster(t *testing.T) {
...@@ -29,7 +28,7 @@ func TestValidateCluster(t *testing.T) { ...@@ -29,7 +28,7 @@ func TestValidateCluster(t *testing.T) {
{ {
ObjectMeta: api.ObjectMeta{Name: "cluster-s"}, ObjectMeta: api.ObjectMeta{Name: "cluster-s"},
Spec: federation.ClusterSpec{ Spec: federation.ClusterSpec{
ServerAddressByClientCIDRs: []unversioned.ServerAddressByClientCIDR{ ServerAddressByClientCIDRs: []federation.ServerAddressByClientCIDR{
{ {
ClientCIDR: "0.0.0.0/0", ClientCIDR: "0.0.0.0/0",
ServerAddress: "localhost:8888", ServerAddress: "localhost:8888",
...@@ -52,7 +51,7 @@ func TestValidateCluster(t *testing.T) { ...@@ -52,7 +51,7 @@ func TestValidateCluster(t *testing.T) {
"empty cluster addresses": { "empty cluster addresses": {
ObjectMeta: api.ObjectMeta{Name: "cluster-f"}, ObjectMeta: api.ObjectMeta{Name: "cluster-f"},
Spec: federation.ClusterSpec{ Spec: federation.ClusterSpec{
ServerAddressByClientCIDRs: []unversioned.ServerAddressByClientCIDR{}, ServerAddressByClientCIDRs: []federation.ServerAddressByClientCIDR{},
}}, }},
"invalid_label": { "invalid_label": {
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
...@@ -81,7 +80,7 @@ func TestValidateClusterUpdate(t *testing.T) { ...@@ -81,7 +80,7 @@ func TestValidateClusterUpdate(t *testing.T) {
old: federation.Cluster{ old: federation.Cluster{
ObjectMeta: api.ObjectMeta{Name: "cluster-s"}, ObjectMeta: api.ObjectMeta{Name: "cluster-s"},
Spec: federation.ClusterSpec{ Spec: federation.ClusterSpec{
ServerAddressByClientCIDRs: []unversioned.ServerAddressByClientCIDR{ ServerAddressByClientCIDRs: []federation.ServerAddressByClientCIDR{
{ {
ClientCIDR: "0.0.0.0/0", ClientCIDR: "0.0.0.0/0",
ServerAddress: "localhost:8888", ServerAddress: "localhost:8888",
...@@ -92,7 +91,7 @@ func TestValidateClusterUpdate(t *testing.T) { ...@@ -92,7 +91,7 @@ func TestValidateClusterUpdate(t *testing.T) {
update: federation.Cluster{ update: federation.Cluster{
ObjectMeta: api.ObjectMeta{Name: "cluster-s"}, ObjectMeta: api.ObjectMeta{Name: "cluster-s"},
Spec: federation.ClusterSpec{ Spec: federation.ClusterSpec{
ServerAddressByClientCIDRs: []unversioned.ServerAddressByClientCIDR{ ServerAddressByClientCIDRs: []federation.ServerAddressByClientCIDR{
{ {
ClientCIDR: "0.0.0.0/0", ClientCIDR: "0.0.0.0/0",
ServerAddress: "localhost:8888", ServerAddress: "localhost:8888",
...@@ -116,7 +115,7 @@ func TestValidateClusterUpdate(t *testing.T) { ...@@ -116,7 +115,7 @@ func TestValidateClusterUpdate(t *testing.T) {
old: federation.Cluster{ old: federation.Cluster{
ObjectMeta: api.ObjectMeta{Name: "cluster-s"}, ObjectMeta: api.ObjectMeta{Name: "cluster-s"},
Spec: federation.ClusterSpec{ Spec: federation.ClusterSpec{
ServerAddressByClientCIDRs: []unversioned.ServerAddressByClientCIDR{ ServerAddressByClientCIDRs: []federation.ServerAddressByClientCIDR{
{ {
ClientCIDR: "0.0.0.0/0", ClientCIDR: "0.0.0.0/0",
ServerAddress: "localhost:8888", ServerAddress: "localhost:8888",
...@@ -127,7 +126,7 @@ func TestValidateClusterUpdate(t *testing.T) { ...@@ -127,7 +126,7 @@ func TestValidateClusterUpdate(t *testing.T) {
update: federation.Cluster{ update: federation.Cluster{
ObjectMeta: api.ObjectMeta{Name: "cluster-newname"}, ObjectMeta: api.ObjectMeta{Name: "cluster-newname"},
Spec: federation.ClusterSpec{ Spec: federation.ClusterSpec{
ServerAddressByClientCIDRs: []unversioned.ServerAddressByClientCIDR{ ServerAddressByClientCIDRs: []federation.ServerAddressByClientCIDR{
{ {
ClientCIDR: "0.0.0.0/0", ClientCIDR: "0.0.0.0/0",
ServerAddress: "localhost:8888", ServerAddress: "localhost:8888",
...@@ -155,7 +154,7 @@ func TestValidateClusterStatusUpdate(t *testing.T) { ...@@ -155,7 +154,7 @@ func TestValidateClusterStatusUpdate(t *testing.T) {
old: federation.Cluster{ old: federation.Cluster{
ObjectMeta: api.ObjectMeta{Name: "cluster-s"}, ObjectMeta: api.ObjectMeta{Name: "cluster-s"},
Spec: federation.ClusterSpec{ Spec: federation.ClusterSpec{
ServerAddressByClientCIDRs: []unversioned.ServerAddressByClientCIDR{ ServerAddressByClientCIDRs: []federation.ServerAddressByClientCIDR{
{ {
ClientCIDR: "0.0.0.0/0", ClientCIDR: "0.0.0.0/0",
ServerAddress: "localhost:8888", ServerAddress: "localhost:8888",
...@@ -171,7 +170,7 @@ func TestValidateClusterStatusUpdate(t *testing.T) { ...@@ -171,7 +170,7 @@ func TestValidateClusterStatusUpdate(t *testing.T) {
update: federation.Cluster{ update: federation.Cluster{
ObjectMeta: api.ObjectMeta{Name: "cluster-s"}, ObjectMeta: api.ObjectMeta{Name: "cluster-s"},
Spec: federation.ClusterSpec{ Spec: federation.ClusterSpec{
ServerAddressByClientCIDRs: []unversioned.ServerAddressByClientCIDR{ ServerAddressByClientCIDRs: []federation.ServerAddressByClientCIDR{
{ {
ClientCIDR: "0.0.0.0/0", ClientCIDR: "0.0.0.0/0",
ServerAddress: "localhost:8888", ServerAddress: "localhost:8888",
......
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"k8s.io/kubernetes/federation/apis/federation" "k8s.io/kubernetes/federation/apis/federation"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/registry/generic" "k8s.io/kubernetes/pkg/registry/generic"
...@@ -49,7 +48,7 @@ func validNewCluster() *federation.Cluster { ...@@ -49,7 +48,7 @@ func validNewCluster() *federation.Cluster {
}, },
}, },
Spec: federation.ClusterSpec{ Spec: federation.ClusterSpec{
ServerAddressByClientCIDRs: []unversioned.ServerAddressByClientCIDR{ ServerAddressByClientCIDRs: []federation.ServerAddressByClientCIDR{
{ {
ClientCIDR: "0.0.0.0/0", ClientCIDR: "0.0.0.0/0",
ServerAddress: "localhost:8888", ServerAddress: "localhost:8888",
......
...@@ -23,7 +23,6 @@ import ( ...@@ -23,7 +23,6 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi" "k8s.io/kubernetes/pkg/api/testapi"
apitesting "k8s.io/kubernetes/pkg/api/testing" apitesting "k8s.io/kubernetes/pkg/api/testing"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/labels"
"reflect" "reflect"
...@@ -39,7 +38,7 @@ func validNewCluster() *federation.Cluster { ...@@ -39,7 +38,7 @@ func validNewCluster() *federation.Cluster {
}, },
}, },
Spec: federation.ClusterSpec{ Spec: federation.ClusterSpec{
ServerAddressByClientCIDRs: []unversioned.ServerAddressByClientCIDR{ ServerAddressByClientCIDRs: []federation.ServerAddressByClientCIDR{
{ {
ClientCIDR: "0.0.0.0/0", ClientCIDR: "0.0.0.0/0",
ServerAddress: "localhost:8888", ServerAddress: "localhost:8888",
......
...@@ -105,12 +105,6 @@ func DeepCopy_unversioned_ListMeta(in ListMeta, out *ListMeta, c *conversion.Clo ...@@ -105,12 +105,6 @@ func DeepCopy_unversioned_ListMeta(in ListMeta, out *ListMeta, c *conversion.Clo
return nil return nil
} }
func DeepCopy_unversioned_ServerAddressByClientCIDR(in ServerAddressByClientCIDR, out *ServerAddressByClientCIDR, c *conversion.Cloner) error {
out.ClientCIDR = in.ClientCIDR
out.ServerAddress = in.ServerAddress
return nil
}
func DeepCopy_unversioned_Time(in Time, out *Time, c *conversion.Cloner) error { func DeepCopy_unversioned_Time(in Time, out *Time, c *conversion.Cloner) error {
if newVal, err := c.DeepCopy(in.Time); err != nil { if newVal, err := c.DeepCopy(in.Time); err != nil {
return err return err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment