Skip to content

Commit

Permalink
【GLCC】Higress Console 支持 Gateway API (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
iendi authored Jan 7, 2025
1 parent d234655 commit c555854
Show file tree
Hide file tree
Showing 118 changed files with 10,516 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import javax.annotation.PostConstruct;

import com.alibaba.higress.sdk.service.OpenAPIService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -36,6 +37,7 @@
import com.alibaba.higress.sdk.service.consumer.ConsumerService;
import com.alibaba.higress.sdk.service.kubernetes.KubernetesClientService;
import com.alibaba.higress.sdk.service.kubernetes.KubernetesModelConverter;
import com.alibaba.higress.sdk.service.HigressConfigService;

@Configuration
public class SdkConfig {
Expand Down Expand Up @@ -129,6 +131,15 @@ public WasmPluginInstanceService wasmPluginInstanceService() {
return serviceProvider.wasmPluginInstanceService();
}

@Bean
public OpenAPIService openApiService() {
return serviceProvider.openApiService();
}

@Bean
public HigressConfigService higressConfigService() {
return serviceProvider.higressConfigService();
}
@Bean
public ConsumerService consumerService() {
return serviceProvider.consumerService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.alibaba.higress.sdk.service.RouteService;

@RestController("DomainsController")
@RequestMapping("/v1/domains")
@RequestMapping("/v2/domains")
@Validated
public class DomainsController {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2022-2023 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.higress.console.controller;

import com.alibaba.higress.sdk.service.HigressConfigService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController("HigressController")
@RequestMapping("/v1/workmode")
@Validated
public class HigressConfigController {
@Resource
HigressConfigService higressConfigService;

@GetMapping
public Boolean getWorkMode() {
return higressConfigService.getWorkMode();
}

@PutMapping
public Boolean updateWorkMode(@RequestParam Boolean mode) {
return higressConfigService.putWorkMode(mode);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2022-2023 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.higress.console.controller;

import com.alibaba.higress.console.controller.dto.Response;
import com.alibaba.higress.console.controller.util.ControllerUtil;
import com.alibaba.higress.sdk.model.OpenAPISpecification;
import com.alibaba.higress.sdk.service.OpenAPIService;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController("OpenAPIController")
@RequestMapping("/v1/openapi")
@Validated
public class OpenAPIController {
@Resource
private OpenAPIService openApiService;

@PostMapping
public ResponseEntity<Response<OpenAPISpecification>> add(@RequestBody OpenAPISpecification oas) {
return ControllerUtil.buildResponseEntity(openApiService.add(oas));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ private void initDefaultRoutes() {
Domain domain = new Domain();
domain.setName(HigressConstants.DEFAULT_DOMAIN);
domain.setEnableHttps(Domain.EnableHttps.ON);
domain.setCertIdentifier(DEFAULT_TLS_CERTIFICATE_NAME);
Map<Integer, String> portAndCert = new HashMap<>();
portAndCert.put(443, DEFAULT_TLS_CERTIFICATE_NAME);
domain.setPortAndCertMap(portAndCert);
domainService.add(domain);
} catch (ResourceConflictException e) {
// Ignore it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public class HigressConstants {
public static final String INTERNAL_RESOURCE_NAME_SUFFIX = ".internal";
public static final String FALLBACK_ROUTE_NAME_SUFFIX = ".fallback";
public static final String FALLBACK_FROM_HEADER = "x-higress-fallback-from";
public static final String DEFAULT_CONFIG = "higress-config";
public static final String PORT_CONFIG = "higress-ports";
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public class KubernetesConstants {
public static final String SECRET_TLS_KEY_FIELD = "tls.key";
public static final String YAML_SEPARATOR = "---\n";

public static class WorkMode {
public static final String KEY = "workMode";
public static final String GATEWAY = "gateway";
public static final String INGRESS = "ingress";
}



public static class Annotation {
public static final String KEY_PREFIX = "higress.io/";
public static final String NGINX_INGRESS_KEY_PREFIX = "nginx.ingress.kubernetes.io/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public class Separators {
public static final String UNDERSCORE = "_";

public static final String COLON = ":";

public static final String SLASH = "/";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

@Data
@Builder
@NoArgsConstructor
Expand All @@ -30,12 +32,13 @@ public static class EnableHttps {
public static final String ON = "on";
public static final String FORCE = "force";
}
private Boolean isIngressMode;

private String name;

private String version;

private String enableHttps;

private String certIdentifier;
private Map<Integer, String> portAndCertMap;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2022-2023 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.higress.sdk.model;

import com.alibaba.higress.sdk.model.openapi.OpenAPIComponents;
import com.alibaba.higress.sdk.model.openapi.OpenAPIInfo;
import com.alibaba.higress.sdk.model.openapi.OpenAPIPathDescription;
import com.alibaba.higress.sdk.model.openapi.OpenAPIServer;
import com.alibaba.higress.sdk.model.openapi.OpenAPITag;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("OpenAPI")
public class OpenAPISpecification {
private String openapi;
private OpenAPIInfo info;
private List<OpenAPIServer> servers;
private Map<String, OpenAPIPathDescription> paths;
private List<OpenAPIComponents> components;
private List<OpenAPITag> tags;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class Route implements VersionedDto {

private String name;

private Boolean isIngressMode;

private String version;

private List<String> domains;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2022-2023 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.higress.sdk.model.openapi;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OpenAPIComponents {
private Map<String, OpenAPISchema> schemas;
private Map<String, OpenAPIResponse> responses;
private Map<String, OpenAPIParameter> parameters;
private Map<String, OpenAPIRequestBody> requestBodies;
private Map<String, Object> extensions;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2022-2023 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.higress.sdk.model.openapi;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OpenAPIContactDetails {
private String name;
private String url;
private String email;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2022-2023 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.higress.sdk.model.openapi;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OpenAPIEncoding {
private String contentType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2022-2023 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.higress.sdk.model.openapi;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OpenAPIExternalDocs {
private String description;
private String url;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2022-2023 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.higress.sdk.model.openapi;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OpenAPIInfo {
private String title;
private String description;
private OpenAPIContactDetails contact;
private OpenAPILicense license;
private String version;
}
Loading

0 comments on commit c555854

Please sign in to comment.