Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new gateway version v1beta1 #1641

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions charts/yurt-manager/crds/raven.openyurt.io_gateways.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,201 @@ spec:
type: object
type: object
served: true
storage: false
subresources:
status: {}
- name: v1beta1
schema:
openAPIV3Schema:
description: Gateway is the Schema for the gateways API
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: GatewaySpec defines the desired state of Gateway
properties:
endpoints:
description: Endpoints are a list of available Endpoint.
items:
description: Endpoint stores all essential data for establishing
the VPN tunnel and Proxy
properties:
config:
additionalProperties:
type: string
description: Config is a map to record config for the raven
agent of node
type: object
nodeName:
description: NodeName is the Node hosting this endpoint.
type: string
port:
description: Port is the exposed port of the node
type: integer
publicIP:
description: PublicIP is the exposed IP of the node
type: string
type:
description: Type is the service type of the node, proxy or
tunnel
type: string
underNAT:
description: UnderNAT indicates whether node is under NAT
type: boolean
required:
- nodeName
- type
type: object
type: array
exposeType:
description: ExposeType determines how the Gateway is exposed.
type: string
nodeSelector:
description: NodeSelector is a label query over nodes that managed
by the gateway. The nodes in the same gateway should share same
layer 3 network.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: A label selector requirement is a selector that
contains values, a key, and an operator that relates the key
and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship to
a set of values. Valid operators are In, NotIn, Exists
and DoesNotExist.
type: string
values:
description: values is an array of string values. If the
operator is In or NotIn, the values array must be non-empty.
If the operator is Exists or DoesNotExist, the values
array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs. A single
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
type: object
type: object
proxyConfig:
description: ProxyConfig determine the l7 proxy configuration
properties:
Replicas:
description: Replicas is the number of gateway active endpoints
that enabled proxy
type: integer
proxyHTTPPort:
description: ProxyHTTPPort is the proxy http port of the cross-domain
request
type: string
proxyHTTPSPort:
description: ProxyHTTPSPort is the proxy https port of the cross-domain
request
type: string
required:
- Replicas
type: object
tunnelConfig:
description: TunnelConfig determine the l3 tunnel configuration
properties:
Replicas:
description: Replicas is the number of gateway active endpoints
that enabled tunnel
type: integer
required:
- Replicas
type: object
type: object
status:
description: GatewayStatus defines the observed state of Gateway
properties:
activeEndpoints:
description: ActiveEndpoints is the reference of the active endpoint.
items:
description: Endpoint stores all essential data for establishing
the VPN tunnel and Proxy
properties:
config:
additionalProperties:
type: string
description: Config is a map to record config for the raven
agent of node
type: object
nodeName:
description: NodeName is the Node hosting this endpoint.
type: string
port:
description: Port is the exposed port of the node
type: integer
publicIP:
description: PublicIP is the exposed IP of the node
type: string
type:
description: Type is the service type of the node, proxy or
tunnel
type: string
underNAT:
description: UnderNAT indicates whether node is under NAT
type: boolean
required:
- nodeName
- type
type: object
type: array
nodes:
description: Nodes contains all information of nodes managed by Gateway.
items:
description: NodeInfo stores information of node managed by Gateway.
properties:
nodeName:
description: NodeName is the Node host name.
type: string
privateIP:
description: PrivateIP is the node private ip address
type: string
subnets:
description: Subnets is the pod ip range of the node
items:
type: string
type: array
required:
- nodeName
- privateIP
- subnets
type: object
type: array
type: object
type: object
served: true
storage: true
subresources:
status: {}
Expand Down
12 changes: 6 additions & 6 deletions charts/yurt-manager/templates/yurt-manager-auto-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,14 @@ webhooks:
service:
name: yurt-manager-webhook-service
namespace: {{ .Release.Namespace }}
path: /mutate-raven-openyurt-io-v1alpha1-gateway
path: /mutate-raven-openyurt-io-v1beta1-gateway
failurePolicy: Fail
name: mutate.raven.v1alpha1.gateway.openyurt.io
name: mutate.gateway.v1beta1.raven.openyurt.io
rules:
- apiGroups:
- raven.openyurt.io
apiVersions:
- v1alpha1
- v1beta1
operations:
- CREATE
- UPDATE
Expand Down Expand Up @@ -574,14 +574,14 @@ webhooks:
service:
name: yurt-manager-webhook-service
namespace: {{ .Release.Namespace }}
path: /validate-raven-openyurt-io-v1alpha1-gateway
path: /validate-raven-openyurt-io-v1beta1-gateway
failurePolicy: Fail
name: validate.raven.v1alpha1.gateway.openyurt.io
name: validate.gateway.v1beta1.raven.openyurt.io
rules:
- apiGroups:
- raven.openyurt.io
apiVersions:
- v1alpha1
- v1beta1
operations:
- CREATE
- UPDATE
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/addtoscheme_raven_v1beta1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2023 The OpenYurt Authors.

Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package apis

import (
version "github.com/openyurtio/openyurt/pkg/apis/raven/v1beta1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, version.SchemeBuilder.AddToScheme)
}
2 changes: 1 addition & 1 deletion pkg/apis/apps/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion pkg/apis/apps/v1beta1/zz_generated.deepcopy.go

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

94 changes: 86 additions & 8 deletions pkg/apis/raven/v1alpha1/gateway_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ limitations under the License.

package v1alpha1

import (
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/conversion"

"github.com/openyurtio/openyurt/pkg/apis/raven/v1beta1"
)

/*
Implementing the hub method is pretty easy -- we just have to add an empty
method called Hub() to serve as a
Expand All @@ -31,15 +38,86 @@ method called Hub() to serve as a
// NOTE !!!!!!! @kadisi
// If this version is not storageversion, you need to implement the ConvertTo and ConvertFrom methods

// need import "sigs.k8s.io/controller-runtime/pkg/conversion"
//func (src *Gateway) ConvertTo(dstRaw conversion.Hub) error {
// return nil
//}
func (src *Gateway) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta1.Gateway)
dst.ObjectMeta = src.ObjectMeta
if src.Spec.NodeSelector != nil {
dst.Spec.NodeSelector = src.Spec.NodeSelector
}
dst.Spec.ExposeType = string(src.Spec.ExposeType)
dst.Spec.TunnelConfig.Replicas = 1
dst.Spec.ProxyConfig.Replicas = 1
for _, eps := range src.Spec.Endpoints {
dst.Spec.Endpoints = append(dst.Spec.Endpoints, v1beta1.Endpoint{
NodeName: eps.NodeName,
PublicIP: eps.PublicIP,
UnderNAT: eps.UnderNAT,
Config: eps.Config,
Type: v1beta1.Tunnel,
Port: v1beta1.DefaultTunnelServerExposedPort,
})
}
for _, node := range src.Status.Nodes {
dst.Status.Nodes = append(dst.Status.Nodes, v1beta1.NodeInfo{
NodeName: node.NodeName,
PrivateIP: node.PrivateIP,
Subnets: node.Subnets,
})
}
if src.Status.ActiveEndpoint != nil {
dst.Status.ActiveEndpoints = []*v1beta1.Endpoint{
{
NodeName: src.Status.ActiveEndpoint.NodeName,
PublicIP: src.Status.ActiveEndpoint.PublicIP,
UnderNAT: src.Status.ActiveEndpoint.UnderNAT,
Config: src.Status.ActiveEndpoint.Config,
Type: v1beta1.Tunnel,
Port: v1beta1.DefaultTunnelServerExposedPort,
},
}
}

klog.Infof("convert from v1alpha1 to v1beta1 for %s", dst.Name)
return nil
}

// NOTE !!!!!!! @kadisi
// If this version is not storageversion, you need to implement the ConvertTo and ConvertFrom methods

// need import "sigs.k8s.io/controller-runtime/pkg/conversion"
//func (dst *Gateway) ConvertFrom(srcRaw conversion.Hub) error {
// return nil
//}
func (dst *Gateway) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta1.Gateway)
dst.ObjectMeta = src.ObjectMeta
dst.Spec.NodeSelector = src.Spec.NodeSelector
dst.Spec.ExposeType = ExposeType(src.Spec.ExposeType)
for _, eps := range src.Spec.Endpoints {
dst.Spec.Endpoints = append(dst.Spec.Endpoints, Endpoint{
NodeName: eps.NodeName,
PublicIP: eps.PublicIP,
UnderNAT: eps.UnderNAT,
Config: eps.Config,
})
}
for _, node := range src.Status.Nodes {
dst.Status.Nodes = append(dst.Status.Nodes, NodeInfo{
NodeName: node.NodeName,
PrivateIP: node.PrivateIP,
Subnets: node.Subnets,
})
}
if src.Status.ActiveEndpoints == nil {
klog.Infof("convert from v1beta1 to v1alpha1 for %s", dst.Name)
return nil
}
if len(src.Status.ActiveEndpoints) < 1 {
dst.Status.ActiveEndpoint = nil
} else {
dst.Status.ActiveEndpoint = &Endpoint{
NodeName: src.Status.ActiveEndpoints[0].NodeName,
PublicIP: src.Status.ActiveEndpoints[0].PublicIP,
UnderNAT: src.Status.ActiveEndpoints[0].UnderNAT,
Config: src.Status.ActiveEndpoints[0].Config,
}
}
klog.Infof("convert from v1beta1 to v1alpha1 for %s", dst.Name)
return nil
}
Loading
Loading