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

【GLCC】Higress Console 支持 Gateway API #371

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

iendi
Copy link

@iendi iendi commented Nov 20, 2024

Ⅰ. Describe what this PR did

本 PR 是GLCC活动#1042的实现,实现了资源管理、路由配置、前端适配以及单元测试等核心功能。具体包括:完成 CRD 模型创建与初始化、域名到网关的映射配置、支持多端口证书配置、路由策略与插件适配,以及前端的工作模式切换与域名路由功能适配。同时,单元测试覆盖率达到 92%,确保了配置转换逻辑的正确性。

Ⅱ. 整体进度

功能 进度 任务
资源定义及初始化 ✅已完成 [√]CRD Model的创建(gatewayclass, gateway, httproute, refrencegrant)
[√]启动console时,初始化gtw class,读取网关模式
域名->gateway ✅已完成 [√]gateway资源的 增删查改列 操作
[√]修改域名定义,支持不同端口配置不同证书
[√]增加域名端口时,同时修改higress-gateway的service的ports字段 #896
路由->httproute ✅已完成 [√ ]httproute资源的 增删查改列 操作
[√]重写、重定向等策略的适配
[√]域名级插件适配
[√]路由级插件适配
前端适配 ✅已完成 [√ ]支持工作模式切换
[√]域名部分适配
[√]路由部分适配
单元测试 ✅已完成 [√]验证配置转换逻辑的单元测试用例,覆盖率不低于 80%
openapi导入 ✅已完成 [√]支持openapi导入,生成对应的domain和route
[√]支持openapi导入时指定域名级或路由级插件

Ⅲ. 结果

工作模式配置

允许用户自行设置使用ingress或者是gatewayapi的工作模式,入口在右上角-个人信息-工作模式配置
image

当工作模式切换后,新建域名或者路由时,默认采用的都是当前的工作模式

域名

规则如下

  • 不允许重复的端口
    image

  • ingress模式下,只允许选择80端口(HTTP)和443端口(HTTPS)
    image

  • 当同时有80端口(HTTP)和443端口(HTTPS)启动时,显示是否强制HTTPS选项
    image

路由

当路由为httproute时,允许选择后端服务的权重:
image

路由显示时,会根据权重显示流量分配的百分比:
image

特殊情况处理
考虑到下面两个特殊情况:

  1. 路由为 httproute 且选择的域名为 ingress 类型
  2. 路由为 ingress 且选择的域名为 gatewayapi 类型

处理方法如下:

①路由为 httproute,选择的域名为 ingress 类型

  • 创建一个对应的 Gateway CR。

  • 将 ConfigMap 中该域名的工作模式由 ingress 类型改为 gateway 类型。

路由为 ingress,选择的域名为 gatewayapi 类型

  • 判断域名是否开启了 80 端口(HTTP):

    • 如果未开启80端口,抛出错误。image
    • 如果同时也开启了 443 端口(HTTPS),设置 ingress 的相关证书信息。
  • 更新gatewayapi 类型的域名时 :

    • 若绑定了ingress类型的路由,不允许删除 80 端口(HTTP)。image

Ⅳ. 备注

目前Route中有些注解httproute cr中并未有对应的参数进行转换,因此我先在httproute中直接添加相应注解,如下表所示

annotation 功能
higress.io/ignore-path-case 路径中忽略大小写
higress.io/cors-expose-headers 跨域访问
higress.io/enable-proxy-next-upstream 重试
higress.io/ssl-redirect 强制转https

@johnlanni
Copy link
Contributor

@iendi 有一些文件冲突了,麻烦更新一下

@iendi
Copy link
Author

iendi commented Dec 18, 2024

@iendi 有一些文件冲突了,麻烦更新一下

冲突已解决

throw new BusinessException("Error occurs when adding a new domain.", e);
}
return kubernetesModelConverter.configMap2Domain(newDomainConfigMap);
DomainStrategy strategy = getStrategy(domain);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether it is possible to make a unified context judgment between controller and service instead of coupling to business service for policy pattern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or abstract a layer of Service Proxy layer is also fine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this design feasible?

  1. create DomainServiceProxy

    @Service
    public class DomainServiceProxy {
        private final IngressDomainService ingressDomainService;
        private final GatewayDomainService gatewayDomainService;
    
        public DomainServiceProxy(IngressDomainService ingressDomainService, 
                                GatewayDomainService gatewayDomainService) {
            this.ingressDomainService = ingressDomainService;
            this.gatewayDomainService = gatewayDomainService;
        }
    
        public Domain add(Domain domain) {
            return getDomainService(domain.getIsIngressMode()).add(domain);
        }
    
        private DomainService getDomainService(boolean isIngressMode) {
            return isIngressMode ? ingressDomainService : gatewayDomainService;
        }
    }
  2. Split DomainServiceImpl into IngressDomainServiceImpl and GatewayDomainServiceImpl based on business logic.

    @Service
    public class IngressDomainServiceImpl implements DomainService {
        // implementation for Ingress
    }
    @Service
    public class GatewayDomainService implements DomainService {
        // implementation for Gateway
    }
  3. Controller:

    public class DomainsController {
    
        @Resource
        private DomainServiceProxy domainServiceProxy; 
    
        @PostMapping
        public ResponseEntity<Response<Domain>> add(@RequestBody Domain domain) {
            return ControllerUtil.buildResponseEntity(domainServiceProxy.add(domain));
        }
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This optimization can be submitted in a separate PR later

iendi and others added 2 commits December 31, 2024 12:05
…ated GatewayName naming convention, added @OverRide annotations, and implemented NPE checks for improved reliability.
@johnlanni
Copy link
Contributor

@iendi Please fix the CI

@iendi iendi requested a review from johnlanni January 3, 2025 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants