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

feat: Refactor the configuration mechanism used by SDK #285

Merged
merged 3 commits into from
Feb 20, 2024
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
3 changes: 2 additions & 1 deletion backend/console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.alibaba.higress</groupId>
<groupId>io.higress.api</groupId>
<artifactId>higress-admin-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
Expand Down Expand Up @@ -57,6 +57,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* 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 config = HigressServiceConfig.builder().withIngressClassName(controllerIngressClassName)
.withControllerNamespace(controllerNamespace).withControllerServiceName(controllerServiceName)
.withControllerServiceHost(controllerServiceHost).withControllerServicePort(controllerServicePort)
.withControllerJwtPolicy(controllerJwtPolicy).withControllerAccessToken(controllerAccessToken).build();
serviceProvider = HigressServiceProvider.create(config);
}

@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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void initialize() {
}

List<String> capabilities = new ArrayList<>();
if (kubernetesClientService.checkIngressV1Supported()) {
if (kubernetesClientService.isIngressV1Supported()) {
capabilities.add(CapabilityKey.CONFIG_INGRESS_V1);
}
this.capabilities = capabilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@
*/
package com.alibaba.higress.console;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class HigressConsoleApplicationTests {

@Test
void contextLoads() {
}

}
122 changes: 121 additions & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.alibaba.higress</groupId>
<groupId>io.higress.api</groupId>
<artifactId>higress-admin-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>higress-admin-parent</name>
<description>Admin Project for Higress</description>
<url>http://higress.io</url>

<packaging>pom</packaging>

Expand All @@ -23,6 +24,31 @@
<module>console</module>
</modules>

<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<url>git@github.com:alibaba/higress.git</url>
<connection>scm:git@github.com:alibaba/higress.git</connection>
<developerConnection>scm:git@github.com:alibaba/higress.git</developerConnection>
</scm>

<developers>
<developer>
<name>johnlanni</name>
<email>zty98751@alibaba-inc.com</email>
</developer>
<developer>
<name>CH3CHO</name>
<email>ch3cho@qq.com</email>
</developer>
</developers>

<properties>
<java.version>17</java.version>

Expand All @@ -42,12 +68,16 @@
<git-commit-id-plugin.version>6.0.0</git-commit-id-plugin.version>
<license-plugin.version>4.1</license-plugin.version>
<checkstyle-plugin.version>3.2.1</checkstyle-plugin.version>
<maven-gpg-plugin.version>3.1.0</maven-gpg-plugin.version>
<central-publishing-maven-plugin.version>0.3.0</central-publishing-maven-plugin.version>

<plugin.inputEncoding>${project.build.sourceEncoding}</plugin.inputEncoding>
<plugin.outputEncoding>${project.build.sourceEncoding}</plugin.outputEncoding>

<app.build.version>1.2.1</app.build.version>
<app.build.dev>true</app.build.dev>

<delombok.output>${project.basedir}/target/delombok-sources</delombok.output>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -123,9 +153,74 @@
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>${git-commit-id-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>${central-publishing-maven-plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<compilerVersion>${maven.compiler.source}</compilerVersion>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>${lombok.version}.0</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<outputDirectory>${delombok.output}</outputDirectory>
<addOutputDirectory>false</addOutputDirectory>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<charset>UTF-8</charset>
<sourcepath>${delombok.output}</sourcepath>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
Expand Down Expand Up @@ -168,6 +263,31 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<tokenAuth>true</tokenAuth>
<excludeArtifacts>
<artifact>higress-console</artifact>
</excludeArtifacts>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Loading
Loading