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 public service controller for manage loadbalancer service #1685

Merged
merged 1 commit into from
Sep 1, 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
2 changes: 2 additions & 0 deletions pkg/yurtmanager/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/raven/dns"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/raven/gatewayinternalservice"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/raven/gatewaypickup"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/raven/gatewaypublicservice"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/servicetopology"
servicetopologyendpoints "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/servicetopology/endpoints"
servicetopologyendpointslice "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/servicetopology/endpointslice"
Expand Down Expand Up @@ -68,6 +69,7 @@ func init() {
controllerAddFuncs[raven.GatewayPickupControllerName] = []AddControllerFn{gatewaypickup.Add}
controllerAddFuncs[raven.GatewayDNSControllerName] = []AddControllerFn{dns.Add}
controllerAddFuncs[raven.GatewayInternalServiceController] = []AddControllerFn{gatewayinternalservice.Add}
controllerAddFuncs[raven.GatewayPublicServiceController] = []AddControllerFn{gatewaypublicservice.Add}
}

// If you want to add additional RBAC, enter it here !!! @kadisi
Expand Down
2 changes: 1 addition & 1 deletion pkg/yurtmanager/controller/raven/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var (
)

const (
ControllerName = "gateway"
GatewayPickupControllerName = "raven-gateway-pickup"
GatewayInternalServiceController = "raven-gateway-internal-service"
GatewayPublicServiceController = "raven-gateway-public-service"
GatewayDNSControllerName = "raven-dns"
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type EnqueueRequestForGatewayEvent struct{}
func (h *EnqueueRequestForGatewayEvent) Create(e event.CreateEvent, q workqueue.RateLimitingInterface) {
gw, ok := e.Object.(*ravenv1beta1.Gateway)
if !ok {
klog.Error(Format("fail to assert runtime Object to v1alpha1.Gateway"))
klog.Error(Format("fail to assert runtime Object %s/%s to v1beta1.Gateway", e.Object.GetNamespace(), e.Object.GetName()))
return
}
if gw.Spec.ExposeType == "" {
Expand All @@ -46,12 +46,12 @@ func (h *EnqueueRequestForGatewayEvent) Create(e event.CreateEvent, q workqueue.
func (h *EnqueueRequestForGatewayEvent) Update(e event.UpdateEvent, q workqueue.RateLimitingInterface) {
newGw, ok := e.ObjectNew.(*ravenv1beta1.Gateway)
if !ok {
klog.Error(Format("fail to assert runtime Object to v1alpha1.Gateway"))
klog.Error(Format("fail to assert runtime Object %s/%s to v1beta1.Gateway", e.ObjectNew.GetNamespace(), e.ObjectNew.GetName()))
return
}
oldGw, ok := e.ObjectOld.(*ravenv1beta1.Gateway)
if !ok {
klog.Error(Format("fail to assert runtime Object to v1alpha1.Gateway"))
klog.Error(Format("fail to assert runtime Object %s/%s to v1beta1.Gateway", e.ObjectOld.GetNamespace(), e.ObjectOld.GetName()))
return
}
if oldGw.Spec.ExposeType == "" && newGw.Spec.ExposeType == "" {
Expand All @@ -64,7 +64,7 @@ func (h *EnqueueRequestForGatewayEvent) Update(e event.UpdateEvent, q workqueue.
func (h *EnqueueRequestForGatewayEvent) Delete(e event.DeleteEvent, q workqueue.RateLimitingInterface) {
gw, ok := e.Object.(*ravenv1beta1.Gateway)
if !ok {
klog.Error(Format("fail to assert runtime Object to v1alpha1.Gateway"))
klog.Error(Format("fail to assert runtime Object %s/%s to v1beta1.Gateway", e.Object.GetNamespace(), e.Object.GetName()))
return
}
if gw.Spec.ExposeType == "" {
Expand All @@ -83,7 +83,7 @@ type EnqueueRequestForConfigEvent struct{}
func (h *EnqueueRequestForConfigEvent) Create(e event.CreateEvent, q workqueue.RateLimitingInterface) {
cm, ok := e.Object.(*corev1.ConfigMap)
if !ok {
klog.Error(Format("fail to assert runtime Object to corev1.Configmap"))
klog.Error(Format("fail to assert runtime Object %s/%s to v1.Configmap", e.Object.GetNamespace(), e.Object.GetName()))
return
}
if cm.Data == nil {
Expand All @@ -108,12 +108,12 @@ func (h *EnqueueRequestForConfigEvent) Create(e event.CreateEvent, q workqueue.R
func (h *EnqueueRequestForConfigEvent) Update(e event.UpdateEvent, q workqueue.RateLimitingInterface) {
newCm, ok := e.ObjectNew.(*corev1.ConfigMap)
if !ok {
klog.Error(Format("fail to assert runtime Object to corev1.Configmap"))
klog.Error(Format("fail to assert runtime Object %s/%s to v1.Configmap", e.ObjectNew.GetNamespace(), e.ObjectNew.GetName()))
return
}
oldCm, ok := e.ObjectOld.(*corev1.ConfigMap)
if !ok {
klog.Error(Format("fail to assert runtime Object to corev1.Configmap"))
klog.Error(Format("fail to assert runtime Object %s/%s to v1.Configmap", e.ObjectOld.GetNamespace(), e.ObjectOld.GetName()))
return
}
_, newInsecurePort, newErr := net.SplitHostPort(newCm.Data[utils.ProxyServerInsecurePortKey])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"reflect"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -180,6 +181,7 @@ func (r *ReconcileGateway) Reconcile(ctx context.Context, req reconcile.Request)
activeEp := r.electActiveEndpoint(nodeList, &gw)
r.recordEndpointEvent(&gw, gw.Status.ActiveEndpoints, activeEp)
gw.Status.ActiveEndpoints = activeEp
r.configEndpoints(ctx, &gw)
// 2. get nodeInfo list of nodes managed by the Gateway
var nodes []ravenv1beta1.NodeInfo
for _, v := range nodeList.Items {
Expand Down Expand Up @@ -363,3 +365,20 @@ func getActiveEndpointsInfo(eps []*ravenv1beta1.Endpoint) (map[string][]string,
}
return infos, len(infos[ActiveEndpointsName])
}

func (r *ReconcileGateway) configEndpoints(ctx context.Context, gw *ravenv1beta1.Gateway) {
enableProxy, enableTunnel := utils.CheckServer(ctx, r.Client)
for idx, val := range gw.Status.ActiveEndpoints {
if gw.Status.ActiveEndpoints[idx].Config == nil {
gw.Status.ActiveEndpoints[idx].Config = make(map[string]string)
}
switch val.Type {
case ravenv1beta1.Proxy:
gw.Status.ActiveEndpoints[idx].Config[utils.RavenEnableProxy] = strconv.FormatBool(enableProxy)
case ravenv1beta1.Tunnel:
gw.Status.ActiveEndpoints[idx].Config[utils.RavenEnableTunnel] = strconv.FormatBool(enableTunnel)
default:
}
}
return
}
Loading