diff --git a/backend/console/src/main/java/com/alibaba/higress/console/config/SdkConfig.java b/backend/console/src/main/java/com/alibaba/higress/console/config/SdkConfig.java new file mode 100644 index 00000000..a3026048 --- /dev/null +++ b/backend/console/src/main/java/com/alibaba/higress/console/config/SdkConfig.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2022-2024 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.config; + +import java.io.IOException; + +import javax.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.alibaba.higress.console.constant.SystemConfigKey; +import com.alibaba.higress.sdk.config.HigressServiceConfig; +import com.alibaba.higress.sdk.constant.HigressConstants; +import com.alibaba.higress.sdk.service.DomainService; +import com.alibaba.higress.sdk.service.HigressServiceProvider; +import com.alibaba.higress.sdk.service.RouteService; +import com.alibaba.higress.sdk.service.ServiceService; +import com.alibaba.higress.sdk.service.ServiceSourceService; +import com.alibaba.higress.sdk.service.TlsCertificateService; +import com.alibaba.higress.sdk.service.WasmPluginInstanceService; +import com.alibaba.higress.sdk.service.WasmPluginService; +import com.alibaba.higress.sdk.service.kubernetes.KubernetesClientService; +import com.alibaba.higress.sdk.service.kubernetes.KubernetesModelConverter; + +@Configuration +public class SdkConfig { + + @Value("${" + SystemConfigKey.KUBE_CONFIG_KEY + ":}") + private String kubeConfig; + + @Value("${" + SystemConfigKey.CONTROLLER_SERVICE_NAME_KEY + ":" + HigressConstants.CONTROLLER_SERVICE_NAME_DEFAULT + + "}") + private String controllerServiceName = HigressConstants.CONTROLLER_SERVICE_NAME_DEFAULT; + + @Value("${" + SystemConfigKey.NS_KEY + ":" + HigressConstants.NS_DEFAULT + "}") + private String controllerNamespace = HigressConstants.NS_DEFAULT; + + @Value("${" + SystemConfigKey.CONTROLLER_INGRESS_CLASS_NAME_KEY + ":" + + HigressConstants.CONTROLLER_INGRESS_CLASS_NAME_DEFAULT + "}") + private String controllerIngressClassName = HigressConstants.CONTROLLER_INGRESS_CLASS_NAME_DEFAULT; + + @Value("${" + SystemConfigKey.CONTROLLER_SERVICE_HOST_KEY + ":" + HigressConstants.CONTROLLER_SERVICE_HOST_DEFAULT + + "}") + private String controllerServiceHost = HigressConstants.CONTROLLER_SERVICE_HOST_DEFAULT; + + @Value("${" + SystemConfigKey.CONTROLLER_SERVICE_PORT_KEY + ":" + HigressConstants.CONTROLLER_SERVICE_PORT_DEFAULT + + "}") + private int controllerServicePort = HigressConstants.CONTROLLER_SERVICE_PORT_DEFAULT; + + @Value("${" + SystemConfigKey.CONTROLLER_JWT_POLICY_KEY + ":" + HigressConstants.CONTROLLER_JWT_POLICY_DEFAULT + + "}") + private String controllerJwtPolicy = HigressConstants.CONTROLLER_JWT_POLICY_DEFAULT; + + @Value("${" + SystemConfigKey.CONTROLLER_ACCESS_TOKEN_KEY + ":}") + private String controllerAccessToken; + + private HigressServiceProvider serviceProvider; + + @PostConstruct + public void initialize() throws IOException { + HigressServiceConfig.Builder builder = KubernetesClientService.isInCluster() + ? HigressServiceConfig.fromInClusterConfig() : HigressServiceConfig.fromKubeConfig(kubeConfig); + builder.withIngressClassName(controllerIngressClassName).withControllerNamespace(controllerNamespace) + .withControllerServiceName(controllerServiceName).withControllerServiceHost(controllerServiceHost) + .withControllerServicePort(controllerServicePort).withControllerJwtPolicy(controllerJwtPolicy) + .withControllerAccessToken(controllerAccessToken); + serviceProvider = HigressServiceProvider.create(builder.build()); + } + + @Bean + public KubernetesClientService kubernetesClientService() { + return serviceProvider.kubernetesClientService(); + } + + @Bean + public KubernetesModelConverter kubernetesModelConverter() { + return serviceProvider.kubernetesModelConverter(); + } + + @Bean + public DomainService domainService() { + return serviceProvider.domainService(); + } + + @Bean + public RouteService routeService() { + return serviceProvider.routeService(); + } + + @Bean + public ServiceService serviceService() { + return serviceProvider.serviceService(); + } + + @Bean + public ServiceSourceService serviceSourceService() { + return serviceProvider.serviceSourceService(); + } + + @Bean + public TlsCertificateService tlsCertificateService() { + return serviceProvider.tlsCertificateService(); + } + + @Bean + public WasmPluginService wasmPluginService() { + return serviceProvider.wasmPluginService(); + } + + @Bean + public WasmPluginInstanceService wasmPluginInstanceService() { + return serviceProvider.wasmPluginInstanceService(); + } +} diff --git a/backend/console/src/main/java/com/alibaba/higress/console/constant/SystemConfigKey.java b/backend/console/src/main/java/com/alibaba/higress/console/constant/SystemConfigKey.java index 30864f8c..9f5a370a 100644 --- a/backend/console/src/main/java/com/alibaba/higress/console/constant/SystemConfigKey.java +++ b/backend/console/src/main/java/com/alibaba/higress/console/constant/SystemConfigKey.java @@ -22,6 +22,22 @@ public class SystemConfigKey { public static final boolean DEV_BUILD_DEFAULT = true; + public static final String NS_KEY = CONFIG_KEY_PREFIX + "ns"; + + public static final String KUBE_CONFIG_KEY = CONFIG_KEY_PREFIX + "kube-config"; + + public static final String CONTROLLER_ACCESS_TOKEN_KEY = CONFIG_KEY_PREFIX + "controller.access-token"; + + public static final String CONTROLLER_JWT_POLICY_KEY = CONFIG_KEY_PREFIX + "controller.jwt-policy"; + + public static final String CONTROLLER_SERVICE_PORT_KEY = CONFIG_KEY_PREFIX + "controller.service.port"; + + public static final String CONTROLLER_SERVICE_HOST_KEY = CONFIG_KEY_PREFIX + "controller.service.host"; + + public static final String CONTROLLER_INGRESS_CLASS_NAME_KEY = CONFIG_KEY_PREFIX + "controller.ingress-class-name"; + + public static final String CONTROLLER_SERVICE_NAME_KEY = CONFIG_KEY_PREFIX + "controller.service.name"; + public static final String CONFIG_MAP_NAME_KEY = CONFIG_KEY_PREFIX + "config-map.name"; public static final String CONFIG_MAP_NAME_KEY_DEFAULT = "higress-console"; diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/config/HigressServiceConfig.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/config/HigressServiceConfig.java new file mode 100644 index 00000000..a9fa23bd --- /dev/null +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/config/HigressServiceConfig.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2022-2024 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.config; + +import java.util.Optional; + +import org.apache.commons.lang3.StringUtils; + +import com.alibaba.higress.sdk.constant.HigressConstants; + +import lombok.Data; + +/** + * @author CH3CHO + */ +@Data +public class HigressServiceConfig { + + private final String kubeConfigPath; + private final String ingressClassName; + private final String controllerNamespace; + private final String controllerServiceName; + private final String controllerServiceHost; + private final Integer controllerServicePort; + private final String controllerJwtPolicy; + private final String controllerAccessToken; + + public static HigressServiceConfig.Builder fromInClusterConfig() { + return new Builder(); + } + + public static HigressServiceConfig.Builder fromKubeConfig(String filePath) { + Builder builder = new Builder(); + if (StringUtils.isNotEmpty(filePath)) { + builder.withKubeConfigPath(filePath); + } + return builder; + } + + public static final class Builder { + private String kubeConfigPath; + private String ingressClassName = HigressConstants.CONTROLLER_INGRESS_CLASS_NAME_DEFAULT; + private String controllerNamespace = HigressConstants.NS_DEFAULT; + private String controllerServiceName = HigressConstants.CONTROLLER_SERVICE_NAME_DEFAULT; + private String controllerServiceHost = HigressConstants.CONTROLLER_SERVICE_HOST_DEFAULT; + private Integer controllerServicePort = HigressConstants.CONTROLLER_SERVICE_PORT_DEFAULT; + private String controllerJwtPolicy = HigressConstants.CONTROLLER_JWT_POLICY_DEFAULT; + private String controllerAccessToken; + + private Builder() {} + + private Builder withKubeConfigPath(String kubeConfigPath) { + this.kubeConfigPath = kubeConfigPath; + return this; + } + + public Builder withIngressClassName(String ingressClassName) { + this.ingressClassName = ingressClassName; + return this; + } + + public Builder withControllerNamespace(String controllerNamespace) { + this.controllerNamespace = controllerNamespace; + return this; + } + + public Builder withControllerServiceName(String controllerServiceName) { + this.controllerServiceName = controllerServiceName; + return this; + } + + public Builder withControllerServiceHost(String controllerServiceHost) { + this.controllerServiceHost = controllerServiceHost; + return this; + } + + public Builder withControllerServicePort(Integer controllerServicePort) { + this.controllerServicePort = controllerServicePort; + return this; + } + + public Builder withControllerJwtPolicy(String controllerJwtPolicy) { + this.controllerJwtPolicy = controllerJwtPolicy; + return this; + } + + public Builder withControllerAccessToken(String controllerAccessToken) { + this.controllerAccessToken = controllerAccessToken; + return this; + } + + public HigressServiceConfig build() { + return new HigressServiceConfig(kubeConfigPath, + StringUtils.firstNonEmpty(ingressClassName, HigressConstants.CONTROLLER_INGRESS_CLASS_NAME_DEFAULT), + StringUtils.firstNonEmpty(controllerNamespace, HigressConstants.NS_DEFAULT), + StringUtils.firstNonEmpty(controllerServiceName, HigressConstants.CONTROLLER_SERVICE_NAME_DEFAULT), + StringUtils.firstNonEmpty(controllerServiceHost, HigressConstants.CONTROLLER_SERVICE_HOST_DEFAULT), + Optional.ofNullable(controllerServicePort).orElse(HigressConstants.CONTROLLER_SERVICE_PORT_DEFAULT), + StringUtils.firstNonEmpty(controllerJwtPolicy, HigressConstants.CONTROLLER_JWT_POLICY_DEFAULT), + controllerAccessToken); + } + } +} diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/constant/ConfigKey.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/constant/ConfigKey.java deleted file mode 100644 index 54e13e89..00000000 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/constant/ConfigKey.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.constant; - -import java.nio.file.Paths; - -public class ConfigKey { - public static final String KUBE_CONFIG_DEFAULT_PATH = - Paths.get(System.getProperty("user.home"), "/.kube/config").toString(); - public static final String NS_DEFAULT = "higress-system"; - public static final String PROTECTED_NSES = "kube-system" + Separators.LIST_CONFIG_SEPARATOR + NS_DEFAULT; - public static final String CONTROLLER_SERVICE_NAME_DEFAULT = "higress-controller"; - public static final String CONTROLLER_INGRESS_CLASS_NAME_DEFAULT = "higress"; - public static final String CONTROLLER_SERVICE_HOST_DEFAULT = "localhost"; - public static final int CONTROLLER_SERVICE_PORT_DEFAULT = 15014; - public static final String CONTROLLER_JWT_POLICY_DEFAULT = KubernetesConstants.JwtPolicy.THIRD_PARTY_JWT; - private static final String CONFIG_KEY_PREFIX = "higress-console."; - public static final String CONTROLLER_ACCESS_TOKEN_KEY = CONFIG_KEY_PREFIX + "controller.access-token"; - public static final String CONTROLLER_JWT_POLICY_KEY = CONFIG_KEY_PREFIX + "controller.jwt-policy"; - public static final String CONTROLLER_SERVICE_PORT_KEY = CONFIG_KEY_PREFIX + "controller.service.port"; - public static final String CONTROLLER_SERVICE_HOST_KEY = CONFIG_KEY_PREFIX + "controller.service.host"; - public static final String CONTROLLER_INGRESS_CLASS_NAME_KEY = CONFIG_KEY_PREFIX + "controller.ingress-class-name"; - public static final String CONTROLLER_SERVICE_NAME_KEY = CONFIG_KEY_PREFIX + "controller.service.name"; - public static final String PROTECTED_NSES_KEY = CONFIG_KEY_PREFIX + "protected-ns-list"; - public static final String NS_KEY = CONFIG_KEY_PREFIX + "ns"; - public static final String KUBE_CONFIG_KEY = CONFIG_KEY_PREFIX + "kube-config"; -} diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/constant/HigressConstants.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/constant/HigressConstants.java new file mode 100644 index 00000000..892441ed --- /dev/null +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/constant/HigressConstants.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022-2024 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.constant; + +public class HigressConstants { + public static final String NS_DEFAULT = "higress-system"; + public static final String CONTROLLER_SERVICE_NAME_DEFAULT = "higress-controller"; + public static final String CONTROLLER_INGRESS_CLASS_NAME_DEFAULT = "higress"; + public static final String CONTROLLER_SERVICE_HOST_DEFAULT = "localhost"; + public static final int CONTROLLER_SERVICE_PORT_DEFAULT = 15014; + public static final String CONTROLLER_JWT_POLICY_DEFAULT = KubernetesConstants.JwtPolicy.THIRD_PARTY_JWT; +} diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/constant/KubernetesConstants.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/constant/KubernetesConstants.java index b45f631c..7a6e9b85 100644 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/constant/KubernetesConstants.java +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/constant/KubernetesConstants.java @@ -14,6 +14,8 @@ public class KubernetesConstants { + public static final String KUBE_SYSTEM_NS = "kube-system"; + public static final String K8S_CERT = "cert"; public static final String K8S_ENABLE_HTTPS = "enableHttps"; diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/DomainServiceImpl.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/DomainServiceImpl.java index 00010a89..65f164a9 100644 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/DomainServiceImpl.java +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/DomainServiceImpl.java @@ -15,8 +15,6 @@ import java.util.List; import java.util.Optional; -import javax.annotation.Resource; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpStatus; @@ -39,20 +37,21 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -@org.springframework.stereotype.Service -public class DomainServiceImpl implements DomainService { - - @Resource - private KubernetesClientService kubernetesClientService; - - @Resource - private KubernetesModelConverter kubernetesModelConverter; - - @Resource - private RouteService routeService; - - @Resource - private WasmPluginInstanceService wasmPluginInstanceService; +class DomainServiceImpl implements DomainService { + + private final KubernetesClientService kubernetesClientService; + private final KubernetesModelConverter kubernetesModelConverter; + private final RouteService routeService; + private final WasmPluginInstanceService wasmPluginInstanceService; + + public DomainServiceImpl(KubernetesClientService kubernetesClientService, + KubernetesModelConverter kubernetesModelConverter, RouteService routeService, + WasmPluginInstanceService wasmPluginInstanceService) { + this.kubernetesClientService = kubernetesClientService; + this.kubernetesModelConverter = kubernetesModelConverter; + this.routeService = routeService; + this.wasmPluginInstanceService = wasmPluginInstanceService; + } @Override public Domain add(Domain domain) { diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/HigressServiceProvider.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/HigressServiceProvider.java new file mode 100644 index 00000000..41a26367 --- /dev/null +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/HigressServiceProvider.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022-2024 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.service; + +import java.io.IOException; + +import com.alibaba.higress.sdk.config.HigressServiceConfig; +import com.alibaba.higress.sdk.service.kubernetes.KubernetesClientService; +import com.alibaba.higress.sdk.service.kubernetes.KubernetesModelConverter; + +/** + * @author CH3CHO + */ +public interface HigressServiceProvider { + + static HigressServiceProvider create(HigressServiceConfig config) throws IOException { + return new HigressServiceProviderImpl(config); + } + + KubernetesClientService kubernetesClientService(); + + KubernetesModelConverter kubernetesModelConverter(); + + DomainService domainService(); + + RouteService routeService(); + + ServiceService serviceService(); + + ServiceSourceService serviceSourceService(); + + TlsCertificateService tlsCertificateService(); + + WasmPluginService wasmPluginService(); + + WasmPluginInstanceService wasmPluginInstanceService(); +} diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/HigressServiceProviderImpl.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/HigressServiceProviderImpl.java new file mode 100644 index 00000000..0c8aa6e1 --- /dev/null +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/HigressServiceProviderImpl.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2022-2024 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.service; + +import com.alibaba.higress.sdk.config.HigressServiceConfig; +import com.alibaba.higress.sdk.service.kubernetes.KubernetesClientService; +import com.alibaba.higress.sdk.service.kubernetes.KubernetesModelConverter; + +import java.io.IOException; + +/** + * @author CH3CHO + */ +class HigressServiceProviderImpl implements HigressServiceProvider { + + private final KubernetesClientService kubernetesClientService; + private final KubernetesModelConverter kubernetesModelConverter; + private final DomainService domainService; + private final RouteService routeService; + private final ServiceService serviceService; + private final ServiceSourceService serviceSourceService; + private final TlsCertificateService tlsCertificateService; + private final WasmPluginService wasmPluginService; + private final WasmPluginInstanceService wasmPluginInstanceService; + + HigressServiceProviderImpl(HigressServiceConfig config) throws IOException { + kubernetesClientService = new KubernetesClientService(config); + kubernetesModelConverter = new KubernetesModelConverter(kubernetesClientService); + serviceService = new ServiceServiceImpl(kubernetesClientService); + serviceSourceService = new ServiceSourceServiceImpl(kubernetesClientService, kubernetesModelConverter); + tlsCertificateService = new TlsCertificateServiceImpl(kubernetesClientService, kubernetesModelConverter); + wasmPluginService = new WasmPluginServiceImpl(kubernetesClientService, kubernetesModelConverter); + wasmPluginInstanceService = + new WasmPluginInstanceServiceImpl(wasmPluginService, kubernetesClientService, kubernetesModelConverter); + routeService = + new RouteServiceImpl(kubernetesClientService, kubernetesModelConverter, wasmPluginInstanceService); + domainService = new DomainServiceImpl(kubernetesClientService, kubernetesModelConverter, routeService, + wasmPluginInstanceService); + } + + @Override + public KubernetesClientService kubernetesClientService() { + return kubernetesClientService; + } + + @Override + public KubernetesModelConverter kubernetesModelConverter() { + return kubernetesModelConverter; + } + + @Override + public DomainService domainService() { + return domainService; + } + + @Override + public RouteService routeService() { + return routeService; + } + + @Override + public ServiceService serviceService() { + return serviceService; + } + + @Override + public ServiceSourceService serviceSourceService() { + return serviceSourceService; + } + + @Override + public TlsCertificateService tlsCertificateService() { + return tlsCertificateService; + } + + @Override + public WasmPluginService wasmPluginService() { + return wasmPluginService; + } + + @Override + public WasmPluginInstanceService wasmPluginInstanceService() { + return wasmPluginInstanceService; + } +} diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/RouteServiceImpl.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/RouteServiceImpl.java index fc0bf4a3..72a21b6d 100644 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/RouteServiceImpl.java +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/RouteServiceImpl.java @@ -15,12 +15,9 @@ import java.util.Collections; import java.util.List; -import javax.annotation.Resource; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; import com.alibaba.higress.sdk.exception.BusinessException; import com.alibaba.higress.sdk.exception.ResourceConflictException; @@ -33,26 +30,19 @@ import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.models.V1Ingress; +import lombok.extern.slf4j.Slf4j; -@Service -public class RouteServiceImpl implements RouteService { +@Slf4j +class RouteServiceImpl implements RouteService { - private KubernetesClientService kubernetesClientService; - private KubernetesModelConverter kubernetesModelConverter; - private WasmPluginInstanceService wasmPluginInstanceService; + private final KubernetesClientService kubernetesClientService; + private final KubernetesModelConverter kubernetesModelConverter; + private final WasmPluginInstanceService wasmPluginInstanceService; - @Resource - public void setKubernetesClientService(KubernetesClientService kubernetesClientService) { + public RouteServiceImpl(KubernetesClientService kubernetesClientService, + KubernetesModelConverter kubernetesModelConverter, WasmPluginInstanceService wasmPluginInstanceService) { this.kubernetesClientService = kubernetesClientService; - } - - @Resource - public void setKubernetesModelConverter(KubernetesModelConverter kubernetesModelConverter) { this.kubernetesModelConverter = kubernetesModelConverter; - } - - @Resource - public void setWasmPluginInstanceService(WasmPluginInstanceService wasmPluginInstanceService) { this.wasmPluginInstanceService = wasmPluginInstanceService; } diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ServiceServiceImpl.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ServiceServiceImpl.java index 80bcded4..62442d7b 100644 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ServiceServiceImpl.java +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ServiceServiceImpl.java @@ -20,8 +20,6 @@ import java.util.Map; import java.util.Set; -import javax.annotation.Resource; - import org.apache.commons.collections4.CollectionUtils; import com.alibaba.higress.sdk.constant.CommonKey; @@ -38,11 +36,13 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -@org.springframework.stereotype.Service -public class ServiceServiceImpl implements ServiceService { +class ServiceServiceImpl implements ServiceService { + + private final KubernetesClientService kubernetesClientService; - @Resource - private KubernetesClientService kubernetesClientService; + public ServiceServiceImpl(KubernetesClientService kubernetesClientService) { + this.kubernetesClientService = kubernetesClientService; + } @Override public PaginatedResult list(CommonPageQuery query) { @@ -89,7 +89,8 @@ public PaginatedResult list(CommonPageQuery query) { } } - services.sort(Comparator.comparing(Service::getNamespace).thenComparing(Service::getName).thenComparing(Service::getPort)); + services.sort(Comparator.comparing(Service::getNamespace).thenComparing(Service::getName) + .thenComparing(Service::getPort)); return PaginatedResult.createFromFullList(services, query); } catch (Exception e) { diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ServiceSourceServiceImpl.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ServiceSourceServiceImpl.java index 72e908b0..cd8b4229 100644 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ServiceSourceServiceImpl.java +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ServiceSourceServiceImpl.java @@ -21,13 +21,10 @@ import java.util.Optional; import java.util.stream.Collectors; -import javax.annotation.Resource; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; import com.alibaba.higress.sdk.exception.BusinessException; import com.alibaba.higress.sdk.exception.ResourceConflictException; @@ -45,22 +42,19 @@ import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.models.V1ObjectMeta; import io.kubernetes.client.openapi.models.V1Secret; +import lombok.extern.slf4j.Slf4j; -@Service -public class ServiceSourceServiceImpl implements ServiceSourceService { +@Slf4j +class ServiceSourceServiceImpl implements ServiceSourceService { private static final int SECRET_NAME_ATTEMPTS = 5; - private KubernetesClientService kubernetesClientService; - private KubernetesModelConverter kubernetesModelConverter; + private final KubernetesClientService kubernetesClientService; + private final KubernetesModelConverter kubernetesModelConverter; - @Resource - public void setKubernetesClientService(KubernetesClientService kubernetesClientService) { + public ServiceSourceServiceImpl(KubernetesClientService kubernetesClientService, + KubernetesModelConverter kubernetesModelConverter) { this.kubernetesClientService = kubernetesClientService; - } - - @Resource - public void setKubernetesModelConverter(KubernetesModelConverter kubernetesModelConverter) { this.kubernetesModelConverter = kubernetesModelConverter; } diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/TlsCertificateServiceImpl.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/TlsCertificateServiceImpl.java index 4e342337..10c9249d 100644 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/TlsCertificateServiceImpl.java +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/TlsCertificateServiceImpl.java @@ -15,11 +15,8 @@ import java.util.Collections; import java.util.List; -import javax.annotation.Resource; - import org.apache.commons.collections4.CollectionUtils; import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; import com.alibaba.higress.sdk.constant.KubernetesConstants; import com.alibaba.higress.sdk.exception.BusinessException; @@ -32,20 +29,17 @@ import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.models.V1Secret; +import lombok.extern.slf4j.Slf4j; -@Service -public class TlsCertificateServiceImpl implements TlsCertificateService { +@Slf4j +class TlsCertificateServiceImpl implements TlsCertificateService { - private KubernetesClientService kubernetesClientService; - private KubernetesModelConverter kubernetesModelConverter; + private final KubernetesClientService kubernetesClientService; + private final KubernetesModelConverter kubernetesModelConverter; - @Resource - public void setKubernetesClientService(KubernetesClientService kubernetesClientService) { + public TlsCertificateServiceImpl(KubernetesClientService kubernetesClientService, + KubernetesModelConverter kubernetesModelConverter) { this.kubernetesClientService = kubernetesClientService; - } - - @Resource - public void setKubernetesModelConverter(KubernetesModelConverter kubernetesModelConverter) { this.kubernetesModelConverter = kubernetesModelConverter; } diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/WasmPluginInstanceServiceImpl.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/WasmPluginInstanceServiceImpl.java index 4620e50e..d2ff3987 100644 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/WasmPluginInstanceServiceImpl.java +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/WasmPluginInstanceServiceImpl.java @@ -19,13 +19,10 @@ import java.util.Map; import java.util.Objects; -import javax.annotation.Resource; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.openapi4j.core.util.TreeUtil; import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; import com.alibaba.higress.sdk.exception.BusinessException; import com.alibaba.higress.sdk.exception.ResourceConflictException; @@ -39,26 +36,19 @@ import com.alibaba.higress.sdk.service.kubernetes.crd.wasm.V1alpha1WasmPlugin; import io.kubernetes.client.openapi.ApiException; +import lombok.extern.slf4j.Slf4j; -@Service -public class WasmPluginInstanceServiceImpl implements WasmPluginInstanceService { +@Slf4j +class WasmPluginInstanceServiceImpl implements WasmPluginInstanceService { - private WasmPluginService wasmPluginService; - private KubernetesClientService kubernetesClientService; - private KubernetesModelConverter kubernetesModelConverter; + private final WasmPluginService wasmPluginService; + private final KubernetesClientService kubernetesClientService; + private final KubernetesModelConverter kubernetesModelConverter; - @Resource - public void setWasmPluginService(WasmPluginService wasmPluginService) { + public WasmPluginInstanceServiceImpl(WasmPluginService wasmPluginService, + KubernetesClientService kubernetesClientService, KubernetesModelConverter kubernetesModelConverter) { this.wasmPluginService = wasmPluginService; - } - - @Resource - public void setKubernetesClientService(KubernetesClientService kubernetesClientService) { this.kubernetesClientService = kubernetesClientService; - } - - @Resource - public void setKubernetesModelConverter(KubernetesModelConverter kubernetesModelConverter) { this.kubernetesModelConverter = kubernetesModelConverter; } diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/WasmPluginServiceImpl.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/WasmPluginServiceImpl.java index e5cb5b00..0b676da9 100644 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/WasmPluginServiceImpl.java +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/WasmPluginServiceImpl.java @@ -33,7 +33,6 @@ import java.util.regex.Pattern; import javax.annotation.PostConstruct; -import javax.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -42,7 +41,6 @@ import org.openapi4j.core.util.TreeUtil; import org.openapi4j.parser.model.v3.Schema; import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; import com.alibaba.higress.sdk.constant.Separators; import com.alibaba.higress.sdk.exception.BusinessException; @@ -72,8 +70,7 @@ * @author CH3CHO */ @Slf4j -@Service -public class WasmPluginServiceImpl implements WasmPluginService { +class WasmPluginServiceImpl implements WasmPluginService { private static final String PLUGINS_RESOURCE_FOLDER = "plugins/"; private static final String PLUGINS_PROPERTIES_FILE = PLUGINS_RESOURCE_FOLDER + "plugins.properties"; @@ -95,17 +92,13 @@ public class WasmPluginServiceImpl implements WasmPluginService { private volatile List builtInPlugins = Collections.emptyList(); - private KubernetesClientService kubernetesClientService; + private final KubernetesClientService kubernetesClientService; - private KubernetesModelConverter kubernetesModelConverter; + private final KubernetesModelConverter kubernetesModelConverter; - @Resource - public void setKubernetesClientService(KubernetesClientService kubernetesClientService) { + public WasmPluginServiceImpl(KubernetesClientService kubernetesClientService, + KubernetesModelConverter kubernetesModelConverter) { this.kubernetesClientService = kubernetesClientService; - } - - @Resource - public void setKubernetesModelConverter(KubernetesModelConverter kubernetesModelConverter) { this.kubernetesModelConverter = kubernetesModelConverter; } diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/kubernetes/KubernetesClientService.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/kubernetes/KubernetesClientService.java index 7dd194b5..0604b8b9 100644 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/kubernetes/KubernetesClientService.java +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/kubernetes/KubernetesClientService.java @@ -20,29 +20,25 @@ import java.io.FileReader; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.Set; - -import javax.annotation.PostConstruct; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; -import com.alibaba.higress.sdk.constant.ConfigKey; +import com.alibaba.higress.sdk.config.HigressServiceConfig; +import com.alibaba.higress.sdk.constant.HigressConstants; import com.alibaba.higress.sdk.constant.KubernetesConstants; import com.alibaba.higress.sdk.constant.KubernetesConstants.Label; import com.alibaba.higress.sdk.constant.Separators; @@ -79,10 +75,12 @@ import okhttp3.Response; @Slf4j -@org.springframework.stereotype.Service public class KubernetesClientService { - private static final String POD_SERVICE_ACCOUNT_TOKEN_FILE_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token"; + private static final String KUBE_CONFIG_DEFAULT_PATH = + Paths.get(System.getProperty("user.home"), "/.kube/config").toString(); + private static final String POD_SERVICE_ACCOUNT_TOKEN_FILE_PATH = + "/var/run/secrets/kubernetes.io/serviceaccount/token"; private static final String CONTROLLER_ACCESS_TOKEN_FILE_PATH = "/var/run/secrets/access-token/token"; private static final String DEFAULT_LABEL_SELECTORS = buildLabelSelector(KubernetesConstants.Label.RESOURCE_DEFINER_KEY, Label.RESOURCE_DEFINER_VALUE); @@ -93,46 +91,45 @@ public class KubernetesClientService { private Boolean inCluster; - @Value("${" + ConfigKey.KUBE_CONFIG_KEY + ":}") - private String kubeConfig; - - @Value("${" + ConfigKey.CONTROLLER_SERVICE_NAME_KEY + ":" + ConfigKey.CONTROLLER_SERVICE_NAME_DEFAULT + "}") - private String controllerServiceName = ConfigKey.CONTROLLER_SERVICE_NAME_DEFAULT; + private final String kubeConfig; - @Value("${" + ConfigKey.NS_KEY + ":" + ConfigKey.NS_DEFAULT + "}") - private String controllerNamespace = ConfigKey.NS_DEFAULT; + private final String controllerServiceName; - @Value("#{'${" + ConfigKey.PROTECTED_NSES_KEY + ":" + ConfigKey.PROTECTED_NSES + "}'.split('" - + Separators.LIST_CONFIG_SEPARATOR + "')}") - private Set protectedNses = - new HashSet<>(Arrays.asList(ConfigKey.PROTECTED_NSES.split(Separators.LIST_CONFIG_SEPARATOR))); + private final String controllerNamespace; - @Value("${" + ConfigKey.CONTROLLER_INGRESS_CLASS_NAME_KEY + ":" + ConfigKey.CONTROLLER_INGRESS_CLASS_NAME_DEFAULT - + "}") - private String controllerIngressClassName = ConfigKey.CONTROLLER_INGRESS_CLASS_NAME_DEFAULT; + private final String controllerIngressClassName; - @Value("${" + ConfigKey.CONTROLLER_SERVICE_HOST_KEY + ":" + ConfigKey.CONTROLLER_SERVICE_HOST_DEFAULT + "}") - private String controllerServiceHost = ConfigKey.CONTROLLER_SERVICE_HOST_DEFAULT; + private final String controllerServiceHost; - @Value("${" + ConfigKey.CONTROLLER_SERVICE_PORT_KEY + ":" + ConfigKey.CONTROLLER_SERVICE_PORT_DEFAULT + "}") - private int controllerServicePort = ConfigKey.CONTROLLER_SERVICE_PORT_DEFAULT; + private final int controllerServicePort; - @Value("${" + ConfigKey.CONTROLLER_JWT_POLICY_KEY + ":" + ConfigKey.CONTROLLER_JWT_POLICY_DEFAULT + "}") - private String controllerJwtPolicy = ConfigKey.CONTROLLER_JWT_POLICY_DEFAULT; + private final String controllerJwtPolicy; - @Value("${" + ConfigKey.CONTROLLER_ACCESS_TOKEN_KEY + ":}") private String controllerAccessToken; private boolean ingressV1Supported; - @PostConstruct - public void init() throws IOException { - if (checkInCluster()) { + public KubernetesClientService(HigressServiceConfig config) throws IOException { + validateConfig(config); + + this.kubeConfig = config.getKubeConfigPath(); + this.controllerNamespace = config.getControllerNamespace(); + this.controllerServiceName = config.getControllerServiceName(); + this.controllerServiceHost = config.getControllerServiceHost(); + this.controllerServicePort = config.getControllerServicePort(); + this.controllerIngressClassName = config.getIngressClassName(); + this.controllerJwtPolicy = config.getControllerJwtPolicy(); + this.controllerAccessToken = config.getControllerAccessToken(); + this.inCluster = isInCluster(); + + if (inCluster) { client = ClientBuilder.cluster().build(); + if (StringUtils.isEmpty(controllerAccessToken)) { + controllerAccessToken = readTokenFromFile(); + } log.info("init KubernetesClientService InCluster"); } else { - String kubeConfigPath = - !Strings.isNullOrEmpty(kubeConfig) ? kubeConfig : ConfigKey.KUBE_CONFIG_DEFAULT_PATH; + String kubeConfigPath = !Strings.isNullOrEmpty(kubeConfig) ? kubeConfig : KUBE_CONFIG_DEFAULT_PATH; try (FileReader reader = new FileReader(kubeConfigPath)) { client = ClientBuilder.kubeconfig(KubeConfig.loadKubeConfig(reader)).build(); } @@ -162,34 +159,15 @@ public boolean checkHigress() throws ApiException { CoreV1Api api = new CoreV1Api(client); V1NamespaceList list = api.listNamespace(null, null, null, null, null, null, null, null, null, null); for (V1Namespace item : list.getItems()) { - if (item.getMetadata() != null && ConfigKey.NS_DEFAULT.equals(item.getMetadata().getName())) { + if (item.getMetadata() != null && HigressConstants.NS_DEFAULT.equals(item.getMetadata().getName())) { return true; } } return false; } - public String checkControllerService() { - // try { - // Configuration.setDefaultApiClient(client); - // CoreV1Api api = new CoreV1Api(); - // V1ServiceList list = api.listServiceForAllNamespaces(null, null, null, null, null, null, null, null, null, - // null); - // for (V1Service item : list.getItems()) { - // if (controllerServiceName.equals(item.getMetadata().getName())) { - // log.info("Get Higress Controller name {}, namespace {}", item.getMetadata().getName(), - // item.getMetadata().getNamespace()); - // return item.getMetadata().getName() + "." + item.getMetadata().getNamespace(); - // } - // } - // } catch (Exception e) { - // log.error("checkControllerService fail use default ", e); - // } - return inCluster ? controllerServiceName + "." + controllerNamespace : controllerServiceHost; - } - public boolean isNamespaceProtected(String namespace) { - return controllerNamespace.equals(namespace) || protectedNses.contains(namespace); + return KubernetesConstants.KUBE_SYSTEM_NS.equals(namespace) || controllerNamespace.equals(namespace); } public List gatewayServiceList() throws IOException { @@ -220,11 +198,8 @@ public Map> gatewayServiceEndpoint() thr return null; } - public boolean checkInCluster() { - if (inCluster == null) { - inCluster = new File(POD_SERVICE_ACCOUNT_TOKEN_FILE_PATH).exists(); - } - return inCluster; + public static boolean isInCluster() { + return new File(POD_SERVICE_ACCOUNT_TOKEN_FILE_PATH).exists(); } public List listIngress() { @@ -546,11 +521,11 @@ private void checkResponseStatus(V1Status status) { // TODO: Throw exception accordingly. } - private Request buildControllerRequest(String path) throws IOException { - String serviceUrl = checkControllerService(); - String url = "http://" + serviceUrl + ":" + controllerServicePort + path; + private Request buildControllerRequest(String path) { + String serviceHost = inCluster ? controllerServiceName + "." + controllerNamespace : controllerServiceHost; + String url = "http://" + serviceHost + ":" + controllerServicePort + path; Request.Builder builder = new Request.Builder().url(url); - String token = checkInCluster() ? readTokenFromFile() : getTokenFromConfiguration(); + String token = controllerAccessToken; if (!Strings.isNullOrEmpty(token)) { builder.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token); } @@ -565,10 +540,6 @@ private String readTokenFromFile() throws IOException { return FileUtils.readFileToString(new File(fileName), Charset.defaultCharset()); } - private String getTokenFromConfiguration() { - return controllerAccessToken; - } - private void renderDefaultLabels(KubernetesObject object) { KubernetesUtil.setLabel(object, Label.RESOURCE_DEFINER_KEY, Label.RESOURCE_DEFINER_VALUE); } @@ -579,4 +550,27 @@ private static List sortKubernetesObjects(List 65535) { + throw new IllegalArgumentException("controllerServicePort is invalid"); + } + if (StringUtils.isEmpty(config.getControllerJwtPolicy())) { + throw new IllegalArgumentException("controllerJwtPolicy is required"); + } + } } diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/kubernetes/KubernetesModelConverter.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/kubernetes/KubernetesModelConverter.java index 3cc2082b..b978e530 100644 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/kubernetes/KubernetesModelConverter.java +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/kubernetes/KubernetesModelConverter.java @@ -96,7 +96,6 @@ * @author CH3CHO */ @Slf4j -@org.springframework.stereotype.Service public class KubernetesModelConverter { private static final Splitter LINE_SPLITTER = Splitter.on('\n').trimResults().omitEmptyStrings(); @@ -105,7 +104,7 @@ public class KubernetesModelConverter { private static final Set SUPPORTED_ANNOTATIONS; private static final Integer DEFAULT_WEIGHT = 100; - private KubernetesClientService kubernetesClientService; + private final KubernetesClientService kubernetesClientService; static { V1TypedLocalObjectReference mcpBridgeReference = new V1TypedLocalObjectReference(); @@ -134,8 +133,7 @@ public class KubernetesModelConverter { SUPPORTED_ANNOTATIONS = Collections.unmodifiableSet(supportedAnnotations); } - @Resource - public void setKubernetesClientService(KubernetesClientService kubernetesClientService) { + public KubernetesModelConverter(KubernetesClientService kubernetesClientService) { this.kubernetesClientService = kubernetesClientService; } diff --git a/backend/sdk/src/test/java/com/alibaba/higress/sdk/service/WasmPluginServiceTest.java b/backend/sdk/src/test/java/com/alibaba/higress/sdk/service/WasmPluginServiceTest.java index b1c216ff..7a940099 100644 --- a/backend/sdk/src/test/java/com/alibaba/higress/sdk/service/WasmPluginServiceTest.java +++ b/backend/sdk/src/test/java/com/alibaba/higress/sdk/service/WasmPluginServiceTest.java @@ -17,6 +17,7 @@ import java.util.Collections; +import com.alibaba.higress.sdk.service.kubernetes.KubernetesModelConverter; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -32,10 +33,10 @@ public class WasmPluginServiceTest { @BeforeEach public void setUp() throws Exception { - service = new WasmPluginServiceImpl(); KubernetesClientService kubernetesClientService = mock(KubernetesClientService.class); when(kubernetesClientService.listWasmPlugin()).thenReturn(Collections.emptyList()); - service.setKubernetesClientService(kubernetesClientService); + KubernetesModelConverter kubernetesModelConverter = mock(KubernetesModelConverter.class); + service = new WasmPluginServiceImpl(kubernetesClientService, kubernetesModelConverter); service.initialize(); } diff --git a/backend/sdk/src/test/java/com/alibaba/higress/sdk/service/kubernetes/KubernetesClientServiceTest.java b/backend/sdk/src/test/java/com/alibaba/higress/sdk/service/kubernetes/KubernetesClientServiceTest.java deleted file mode 100644 index 2ca8857d..00000000 --- a/backend/sdk/src/test/java/com/alibaba/higress/sdk/service/kubernetes/KubernetesClientServiceTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.service.kubernetes; - -import java.io.IOException; -import java.util.List; - -import org.junit.jupiter.api.Test; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.serializer.SerializerFeature; - -import io.kubernetes.client.openapi.models.V1Ingress; - -public class KubernetesClientServiceTest { - - @Test - public void checkControllerService() throws IOException { - KubernetesClientService kubernetesClientService = new KubernetesClientService(); - kubernetesClientService.init(); - System.out.println(kubernetesClientService.checkControllerService()); - } - - @Test - public void ingressTest() throws IOException { - KubernetesClientService kubernetesClientService = new KubernetesClientService(); - kubernetesClientService.init(); - List result = kubernetesClientService.listIngress(); - - System.out.println(JSON.toJSONString(result, SerializerFeature.PrettyFormat)); - } - -} diff --git a/backend/style/higress_checkstyle.xml b/backend/style/higress_checkstyle.xml index 97aafc5d..23c3223f 100644 --- a/backend/style/higress_checkstyle.xml +++ b/backend/style/higress_checkstyle.xml @@ -24,17 +24,17 @@ - + - + - +