Skip to content

Commit

Permalink
Merge pull request #16 from hango-io/release-v1.6.0
Browse files Browse the repository at this point in the history
Release v1.6.0
  • Loading branch information
trickMin authored Oct 18, 2023
2 parents 9bd9e5d + 2f8fdb3 commit 46940db
Show file tree
Hide file tree
Showing 157 changed files with 2,979 additions and 3,838 deletions.
8 changes: 3 additions & 5 deletions hango-api-plane-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ COPY hango-api-plane-server/setenv.sh $CATALINA_HOME/bin/
RUN rm -rf webapps/*
COPY hango-api-plane-server/target/*.war webapps/
RUN cd /usr/local/tomcat/webapps && \
mkdir ROOT && \
mv *.war ROOT/ROOT.war && \
cd ROOT && \
jar -xvf ROOT.war && \
rm -rf *.war
mv *.war ROOT.war && \
unzip ROOT.war -d ./ROOT && \
rm -f ROOT.war

ENTRYPOINT ["catalina.sh", "run"]
14 changes: 13 additions & 1 deletion hango-api-plane-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.3</version>
<version>2.12.7.1</version>
</dependency>
<dependency>
<groupId>com.hubspot.jackson</groupId>
Expand Down Expand Up @@ -204,6 +204,18 @@
<version>1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.7.12</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public McpOptions options() {
options.registerDescriptor(DestinationRuleOuterClass.getDescriptor().getMessageTypes());
options.registerDescriptor(GatewayOuterClass.getDescriptor().getMessageTypes());
options.registerDescriptor(PluginManagerOuterClass.getDescriptor().getMessageTypes());
options.registerDescriptor(GatewayPluginOuterClass.getDescriptor().getMessageTypes());
options.registerDescriptor(ServiceEntryOuterClass.getDescriptor().getMessageTypes());

if (!StringUtils.isEmpty(rlsAddresses)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ public class GlobalConfig {
@Value("${resourceNamespace:gateway-system}")
private String resourceNamespace;

@Value("${apiPlaneType}")
private String apiPlaneType;

@Value("${apiPlaneVersion}")
private String apiPlaneVersion;

@Value("${istioRev:gw-stable}")
private String istioRev;

Expand All @@ -36,27 +30,17 @@ public class GlobalConfig {
@Value("${projectCode:skiff.netease.com/project}")
private String projectCode;

//ingress controller标识,和istio保持一致
@Value("${ingressClass:hango}")
private String ingressClass;

//自定义插件代码挂载cm 名称
@Value("${pluginContentConfigName:hango-rider-plugin}")
private String pluginContentConfigName;

//自定义插件schema挂载cm 名称
@Value("${pluginSchemaConfigName:hango-plugin-schema}")
private String pluginSchemaConfigName;
@Value("${defaultSecretName:harbor-qingzhou}")
private String defaultSecretName;


private final String ALL = "all";

@Value("${ignorePlugins:#{null}}")
private String ignorePlugins;

public String getIgnorePlugins() {
return ignorePlugins;
}
@Value("${kubernetesSvcSuffix:.svc.cluster.local}")
private String kubernetesSvcSuffix;

private final String ALL = "all";

public Set<String> getIgnorePluginSet() {
return StringUtils.isEmpty(ignorePlugins) ? Collections.emptySet() : new HashSet<>(Arrays.asList(ignorePlugins.split(",")));
Expand All @@ -67,17 +51,11 @@ public String getResourceNamespace() {
return resourceNamespace;
}

public String getApiPlaneType() {
return apiPlaneType;
}

public String getIstioRev() {
return istioRev;
}

public String getApiPlaneVersion() {
return apiPlaneVersion;
}

public Integer getTelnetConnectTimeout() {
return telnetConnectTimeout;
Expand All @@ -98,16 +76,11 @@ public String getProjectCode() {
return projectCode;
}

public String getIngressClass() {
return ingressClass;
public String getDefaultSecretName() {
return defaultSecretName;
}

public String getPluginContentConfigName() {
return pluginContentConfigName;
public String getKubernetesSvcSuffix() {
return kubernetesSvcSuffix;
}

public String getPluginSchemaConfigName() {
return pluginSchemaConfigName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,6 @@ public IntegratedResourceOperator getOperator() {
return operator;
}

protected class EmptyResourceGenerator implements Function<String, HasMetadata> {

private HasMetadata hmd;

public EmptyResourceGenerator(HasMetadata hmd) {
this.hmd = hmd;
}

@Override
public HasMetadata apply(String s) {
if (NEVER_NULL.equals(s)) return hmd;
return str2HasMetadata(s);
}
}

protected class DynamicResourceGenerator implements Function<String, HasMetadata> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ public class EnvoyHttpClient {
* @return ip:19000
*/
private String getEnvoyUrl(String gateway) {
Pod envoyPod = getEnvoyPod(gateway);
return String.format("http://%s:19000", envoyPod.getStatus().getPodIP());
List<Service> envoyServiceList = getEnvoyServiceList(gateway);
if (CollectionUtils.isEmpty(envoyServiceList)) {
throw new ApiPlaneException(ExceptionConst.ENVOY_SERVICE_NON_EXIST);
}
return String.format("http://%s:19000", envoyServiceList.get(0).getSpec().getClusterIP());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import io.fabric8.kubernetes.api.model.HasMetadata;
import istio.networking.v1alpha3.VirtualServiceOuterClass;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.hango.cloud.core.GlobalConfig;
import org.hango.cloud.core.IstioModelEngine;
import org.hango.cloud.core.editor.EditorContext;
import org.hango.cloud.core.gateway.handler.*;
import org.hango.cloud.core.gateway.processor.DefaultModelProcessor;
import org.hango.cloud.core.gateway.processor.NeverReturnNullModelProcessor;
import org.hango.cloud.core.gateway.processor.RenderTwiceModelProcessor;
import org.hango.cloud.core.gateway.service.ResourceManager;
import org.hango.cloud.core.k8s.K8sResourcePack;
import org.hango.cloud.core.k8s.empty.DynamicGatewayPluginSupplier;
import org.hango.cloud.core.k8s.operator.IntegratedResourceOperator;
Expand All @@ -23,6 +22,7 @@
import org.hango.cloud.meta.*;
import org.hango.cloud.meta.dto.GrpcEnvoyFilterDTO;
import org.hango.cloud.meta.dto.IpSourceEnvoyFilterDTO;
import org.hango.cloud.meta.enums.PluginScopeTypeEnum;
import org.hango.cloud.service.PluginService;
import org.hango.cloud.util.Const;
import org.hango.cloud.util.HandlerUtil;
Expand All @@ -31,10 +31,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.*;
import java.util.stream.Collectors;
Expand All @@ -45,41 +42,22 @@ public class GatewayIstioModelEngine extends IstioModelEngine {

private static final Logger logger = LoggerFactory.getLogger(IstioModelEngine.class);

private IntegratedResourceOperator operator;
private TemplateTranslator templateTranslator;
private EditorContext editorContext;
private ResourceManager resourceManager;
private PluginService pluginService;
private GlobalConfig globalConfig;

@Autowired
public GatewayIstioModelEngine(IntegratedResourceOperator operator, TemplateTranslator templateTranslator, EditorContext editorContext,
ResourceManager resourceManager, PluginService pluginService, GlobalConfig globalConfig) {
public GatewayIstioModelEngine(IntegratedResourceOperator operator, TemplateTranslator templateTranslator,
PluginService pluginService, GlobalConfig globalConfig) {
super(operator);
this.operator = operator;
this.templateTranslator = templateTranslator;
this.editorContext = editorContext;
this.resourceManager = resourceManager;
this.pluginService = pluginService;
this.globalConfig = globalConfig;

this.defaultModelProcessor = new DefaultModelProcessor(templateTranslator);
this.renderTwiceModelProcessor = new RenderTwiceModelProcessor(templateTranslator);
this.neverNullRenderTwiceProcessor = new NeverReturnNullModelProcessor(this.renderTwiceModelProcessor, NEVER_NULL);
}

private DefaultModelProcessor defaultModelProcessor;
private RenderTwiceModelProcessor renderTwiceModelProcessor;
private NeverReturnNullModelProcessor neverNullRenderTwiceProcessor;

@Value(value = "${http10:#{null}}")
Boolean enableHttp10;

@Value(value = "${rateLimitConfigMapName:rate-limit-config}")
String rateLimitConfigMapName;

@Value(value = "${rateLimitNameSpace:gateway-system}")
String rateLimitNamespace;


private static final String API_GATEWAY = "gateway/api/gateway";
Expand Down Expand Up @@ -137,17 +115,30 @@ public List<K8sResourcePack> translate(API api, boolean simple) {
public List<K8sResourcePack> translate(GatewayPlugin plugin) {
logger.info("{}{} start translate k8s resource", LogConstant.TRANSLATE_LOG_NOTE, LogConstant.PLUGIN_LOG_NOTE);

// 打印插件配置信息
plugin.showPluginConfigsInLog(logger);

RawResourceContainer rawResourceContainer = new RawResourceContainer();
rawResourceContainer.add(renderPlugins(plugin.getPlugins()));
rawResourceContainer.add(pluginService.processPlugin(plugin.getPlugins(), plugin.getPluginScope()));

logger.info("{}{} render plugins ok, start to generate and add k8s resource",
LogConstant.TRANSLATE_LOG_NOTE, LogConstant.PLUGIN_LOG_NOTE);
return generateAndAddK8sResource(rawResourceContainer, plugin);
}

/**
* 转换GatewayPlugin数据为CRD资源
*
* @param plugin 网关插件实例(内含插件配置)
* @return k8s资源集合
*/
public List<K8sResourcePack> translate(BasePlugin plugin) {
List<FragmentHolder> holders = pluginService.processPlugin(Collections.singletonList(plugin.getPluginConfig()), PluginScopeTypeEnum.GATEWAY.getValue());

String pluginConfig = CollectionUtils.isEmpty(holders) ? StringUtils.EMPTY : holders.get(0).getGatewayPluginsFragment().getContent();
// 将插件配置转换为pluginManager setting
List<String> pluginManagers = defaultModelProcessor.process(PLUGIN_MANAGER, PluginOrder.of(plugin.getName(), pluginConfig), new PluginOrderDataHandler());

return generateK8sPack(pluginManagers);
}

/**
* 生成k8s资源并将其合并为k8s资源集合
*
Expand Down Expand Up @@ -191,7 +182,6 @@ private List<K8sResourcePack> configureSmartLimiter(RawResourceContainer rawReso

return resourcePacks;
}

/**
* 插件转换为GatewayPlugin CRD资源
*
Expand All @@ -209,7 +199,7 @@ private List<K8sResourcePack> configureEnvoyPlugin(RawResourceContainer rawResou

// 当插件传入为空时,生成空的GatewayPlugin,删除时使用
DynamicGatewayPluginSupplier dynamicGatewayPluginSupplier =
new DynamicGatewayPluginSupplier(plugin.getGateway(), plugin.getRouteId(), "%s-%s");
new DynamicGatewayPluginSupplier(plugin.getGateway(), plugin.getCode(), "%s-%s");

resourcePacks.addAll(generateK8sPack(rawGatewayPlugins,
new GatewayPluginNormalSubtracter(),
Expand Down Expand Up @@ -239,7 +229,7 @@ public List<K8sResourcePack> translate(Service service) {
*/
public List<K8sResourcePack> translate(IstioGateway istioGateway) {
List<K8sResourcePack> resources = new ArrayList<>();
List<String> rawGateways = defaultModelProcessor.process(API_GATEWAY, istioGateway, new PortalGatewayDataHandler(enableHttp10, globalConfig.getResourceNamespace()));
List<String> rawGateways = defaultModelProcessor.process(API_GATEWAY, istioGateway, new PortalGatewayDataHandler(globalConfig.getResourceNamespace()));
resources.addAll(generateK8sPack(rawGateways));
return resources;
}
Expand All @@ -258,19 +248,6 @@ public List<K8sResourcePack> translate(Secret secret) {
return resources;
}

private List<FragmentHolder> renderPlugins(List<String> pluginList) {

if (CollectionUtils.isEmpty(pluginList)) {
return Collections.emptyList();
}

List<String> plugins = pluginList.stream()
.filter(StringUtils::hasText)
.collect(Collectors.toList());

return pluginService.processPlugin(plugins, new ServiceInfo());
}

private HasMetadata adjust(HasMetadata rawVs) {
if (VIRTUAL_SERVICE.equalsIgnoreCase(rawVs.getKind())) {
// VS需要特殊处理,VS中有中断或重定向插件则将Route清空
Expand Down Expand Up @@ -300,6 +277,7 @@ private HasMetadata adjust(HasMetadata rawVs) {
.addAllExportTo(originalSpec.getExportToList())
.addAllVirtualCluster(originalSpec.getVirtualClusterList())
.addAllTcp(originalSpec.getTcpList())
.addAllUdp(originalSpec.getUdpList())
.addAllThrift(originalSpec.getThriftList())
.addAllTls(originalSpec.getTlsList())
.setPriority(originalSpec.getPriority())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

public class RawResourceContainer {

List<FragmentWrapper> gatewayPlugins = new ArrayList<>();
List<FragmentWrapper> smartLimiters = new ArrayList<>();
private List<FragmentWrapper> gatewayPlugins = new ArrayList<>();
private List<FragmentWrapper> smartLimiters = new ArrayList<>();

public void add(FragmentHolder holder) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.hango.cloud.core.template.TemplateParams;
import org.hango.cloud.k8s.K8sTypes;
import org.hango.cloud.meta.API;
import org.hango.cloud.meta.CRDMetaEnum;
import org.hango.cloud.meta.UriMatch;
import org.hango.cloud.meta.enums.CRDMetaEnum;
import org.hango.cloud.meta.enums.UriMatch;
import org.hango.cloud.meta.dto.DubboInfoDto;
import org.hango.cloud.util.CommonUtil;
import org.hango.cloud.util.HandlerUtil;
Expand Down Expand Up @@ -84,6 +84,7 @@ public TemplateParams handleApi(API api) {
.put(SERVICE_INFO_VIRTUAL_SERVICE_HOST_HEADERS, getOrDefault(hostHeaders, ".*"))
.put(VIRTUAL_SERVICE_REQUEST_HEADERS, api.getRequestOperation())
.put(VIRTUAL_SERVICE_RESP_EXCEPTION_CODE, api.getCustomDefaultRespCode())
.put(VIRTUAL_SERVICE_PROTOCOL, api.getProtocol().toLowerCase())
;

return handleApiMetaMap(api,tp);
Expand Down
Loading

0 comments on commit 46940db

Please sign in to comment.