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 @@
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()))

Check warning on line 36 in pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go#L36

Added line #L36 was not covered by tests
return
}
if gw.Spec.ExposeType == "" {
Expand All @@ -46,12 +46,12 @@
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()))

Check warning on line 49 in pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go#L49

Added line #L49 was not covered by tests
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()))

Check warning on line 54 in pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go#L54

Added line #L54 was not covered by tests
return
}
if oldGw.Spec.ExposeType == "" && newGw.Spec.ExposeType == "" {
Expand All @@ -64,7 +64,7 @@
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()))

Check warning on line 67 in pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go#L67

Added line #L67 was not covered by tests
return
}
if gw.Spec.ExposeType == "" {
Expand All @@ -83,7 +83,7 @@
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()))

Check warning on line 86 in pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go#L86

Added line #L86 was not covered by tests
return
}
if cm.Data == nil {
Expand All @@ -108,12 +108,12 @@
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()))

Check warning on line 111 in pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go#L111

Added line #L111 was not covered by tests
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()))

Check warning on line 116 in pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go#L116

Added line #L116 was not covered by tests
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 @@
"fmt"
"reflect"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -180,6 +181,7 @@
activeEp := r.electActiveEndpoint(nodeList, &gw)
r.recordEndpointEvent(&gw, gw.Status.ActiveEndpoints, activeEp)
gw.Status.ActiveEndpoints = activeEp
r.configEndpoints(ctx, &gw)

Check warning on line 184 in pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go#L184

Added line #L184 was not covered by tests
// 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 @@
}
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:

Check warning on line 380 in pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go#L369-L380

Added lines #L369 - L380 were not covered by tests
}
}
return

Check warning on line 383 in pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go#L383

Added line #L383 was not covered by tests
}
Loading
Loading