Skip to content

Commit

Permalink
Merge branch 'refs/heads/v3.0-develop' into summer-ospp#12017-sync-3.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	console-ui/src/pages/ConfigurationManagement/ConfigurationManagement/ConfigurationManagement.js
  • Loading branch information
KomachiSion committed Nov 5, 2024
2 parents 663a718 + 94690fa commit 6ffeaac
Show file tree
Hide file tree
Showing 51 changed files with 3,425 additions and 351 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 1999-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.nacos.config.server.model.event;

public class IstioConfigChangeEvent extends ConfigDataChangeEvent {

public final String content;

public final String type;

public IstioConfigChangeEvent(String dataId, String group, long gmtModified, String content, String type) {
super(dataId, group, gmtModified);
this.content = content;
this.type = type;
}

public IstioConfigChangeEvent(boolean isBeta, String dataId, String group, String tenant, long gmtModified,
String content, String type) {
super(isBeta, dataId, group, tenant, gmtModified);
this.content = content;
this.type = type;
}

public IstioConfigChangeEvent(boolean isBeta, String dataId, String group, long gmtModified, String content,
String type) {
super(isBeta, dataId, group, gmtModified);
this.content = content;
this.type = type;
}

public IstioConfigChangeEvent(boolean isBeta, String dataId, String group, String tenant, String tag,
long gmtModified, String content, String type) {
super(isBeta, dataId, group, tenant, tag, gmtModified);
this.content = content;
this.type = type;
}

public IstioConfigChangeEvent(String dataId, String group, String tenant, boolean isBatch, long gmtModified,
String content, String type) {
super(dataId, group, tenant, isBatch, gmtModified);
this.content = content;
this.type = type;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
import com.alibaba.nacos.config.server.model.ConfigOperateResult;
import com.alibaba.nacos.config.server.model.ConfigRequestInfo;
import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent;
import com.alibaba.nacos.config.server.model.event.IstioConfigChangeEvent;
import com.alibaba.nacos.config.server.model.form.ConfigForm;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoTagPersistService;
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
import com.alibaba.nacos.config.server.utils.ConfigTagUtil;
import com.alibaba.nacos.config.server.utils.ParamUtils;
import com.alibaba.nacos.config.server.utils.TimeUtils;
import com.alibaba.nacos.sys.utils.InetUtils;
Expand Down Expand Up @@ -117,6 +119,12 @@ public Boolean publishConfig(ConfigForm configForm, ConfigRequestInfo configRequ
ConfigChangePublisher.notifyConfigChange(
new ConfigDataChangeEvent(false, configForm.getDataId(), configForm.getGroup(),
configForm.getNamespaceId(), configOperateResult.getLastModified()));
if (ConfigTagUtil.isIstio(configForm.getConfigTags())) {
ConfigChangePublisher.notifyConfigChange(
new IstioConfigChangeEvent(configForm.getDataId(), configForm.getGroup(),
configOperateResult.getLastModified(), configForm.getContent(),
ConfigTagUtil.getIstioType(configForm.getConfigTags())));
}
} else {
if (StringUtils.isNotBlank(configRequestInfo.getCasMd5())) {
configOperateResult = configInfoTagPersistService.insertOrUpdateTagCas(configInfo,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 1999-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.nacos.config.server.utils;

import java.util.Arrays;

public class ConfigTagUtil {

public static final String VIRTUAL_SERVICE = "virtual-service";

public static final String DESTINATION_RULE = "destination-rule";

private static final String TAGS_DELIMITER = ",";

private static final String HYPHEN = "-";

/**
* <p>Checks if config tags contains "virtual-service" or "destination-rule".</p>
* @param configTags the tags to check
* @return {@code true} if the config tags contains "virtual-service" or "destination-rule".
*/
public static boolean isIstio(String configTags) {
if (configTags == null) {
return false;
}
if (configTags.isEmpty()) {
return false;
}
return Arrays.stream(configTags.split(TAGS_DELIMITER))
.map(tag -> tag.trim().replaceAll(HYPHEN, ""))
.anyMatch(tag -> tag.equalsIgnoreCase(VIRTUAL_SERVICE.replaceAll(HYPHEN, ""))
|| tag.equalsIgnoreCase(DESTINATION_RULE.replaceAll(HYPHEN, "")));
}

/**
* <p>Gets the type of Istio from the config tags.</p>
* @param configTags the tags to check
* @return the type of Istio if it is found, {@code null} otherwise.
* @throws IllegalArgumentException if configTags is null.
*/
public static String getIstioType(String configTags) {
if (configTags == null) {
throw new IllegalArgumentException("configTags cannot be null.");
}

if (configTags.isEmpty()) {
return null;
}

return Arrays.stream(configTags.split(TAGS_DELIMITER))
.map(tag -> tag.trim().replaceAll(HYPHEN, ""))
.filter(tag -> tag.equalsIgnoreCase(VIRTUAL_SERVICE.replaceAll(HYPHEN, ""))
|| tag.equalsIgnoreCase(DESTINATION_RULE.replaceAll(HYPHEN, "")))
.findFirst()
.orElse(null);
}
}
4 changes: 4 additions & 0 deletions console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>nacos-prometheus</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>nacos-k8s-sync</artifactId>
</dependency>

<!-- log -->
<!-- log4j通过slf4j来代理 -->
Expand Down
6 changes: 6 additions & 0 deletions console/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ nacos.core.auth.plugin.nacos.token.secret.key=
### If turn on the MCP server:
nacos.istio.mcp.server.enabled=false

#*************** K8s Related Configurations ***************#
### If turn on the K8s sync:
nacos.k8s.sync.enabled=false

### If use the Java API from an application outside a kubernetes cluster
#nacos.k8s.sync.outsideCluster=false
#nacos.k8s.sync.kubeConfig=/.kube/config

###*************** Add from 1.3.0 ***************###

Expand Down
1 change: 0 additions & 1 deletion core/src/main/resources/META-INF/logback/nacos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@
<appender-ref ref="plugin-control-connection"/>
</logger>


<logger name="com.alibaba.nacos.core.remote.digest" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="remote-digest"/>
Expand Down
8 changes: 8 additions & 0 deletions distribution/conf/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ nacos.core.auth.plugin.nacos.token.secret.key=
### If turn on the MCP server:
nacos.istio.mcp.server.enabled=false

#*************** K8s Related Configurations ***************#
### If turn on the K8s sync:
nacos.k8s.sync.enabled=false

### If use the Java API from an application outside a kubernetes cluster
#nacos.k8s.sync.outsideCluster=false
#nacos.k8s.sync.kubeConfig=/.kube/config

#*************** Core Related Configurations ***************#

### set the WorkerID manually
Expand Down
8 changes: 8 additions & 0 deletions distribution/conf/application.properties.example
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ nacos.core.auth.enable.userAgentAuthWhite=false
### If turn on the MCP server:
nacos.istio.mcp.server.enabled=false

#*************** K8s Related Configurations ***************#
### If turn on the K8s sync:
nacos.k8s.sync.enabled=false

### If use the Java API from an application outside a kubernetes cluster
#nacos.k8s.sync.outsideCluster=false
#nacos.k8s.sync.kubeConfig=/.kube/config

#*************** Core Related Configurations ***************#

### set the WorkerID manually
Expand Down
22 changes: 22 additions & 0 deletions distribution/conf/nacos-logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,23 @@
</encoder>
</appender>

<appender name="k8s-sync-main"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/k8s-sync-main.log</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/k8s-sync-main.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>2GB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>7GB</totalSizeCap>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<encoder>
<Pattern>%date %level %msg%n%n</Pattern>
<charset>UTF-8</charset>
</encoder>
</appender>

<logger name="com.alibaba.nacos.address.main" additivity="false">
<level value="INFO"/>
<appender-ref ref="nacos-address"/>
Expand Down Expand Up @@ -716,6 +733,11 @@
<level value="DEBUG"/>
<appender-ref ref="core-auth"/>
</logger>

<logger name="com.alibaba.nacos.k8s.sync.main" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="k8s-sync-main"/>
</logger>

<logger name="com.alibaba.nacos.core.protocol.raft" additivity="false">
<level value="INFO"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public class ApiConstants {
*/
public static final String CLUSTER_TYPE = API_TYPE_PREFIX + "envoy.config.cluster.v3.Cluster";
public static final String ENDPOINT_TYPE = API_TYPE_PREFIX + "envoy.config.endpoint.v3.ClusterLoadAssignment";

public static final String LISTENER_TYPE = API_TYPE_PREFIX + "envoy.config.listener.v3.Listener";

public static final String ROUTE_TYPE = API_TYPE_PREFIX + "envoy.config.route.v3.RouteConfiguration";

}
15 changes: 12 additions & 3 deletions istio/src/main/java/com/alibaba/nacos/istio/api/ApiGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package com.alibaba.nacos.istio.api;

import com.alibaba.nacos.istio.common.ResourceSnapshot;
import com.alibaba.nacos.istio.model.PushRequest;
import io.envoyproxy.envoy.service.discovery.v3.Resource;

import java.util.List;

Expand All @@ -30,8 +31,16 @@ public interface ApiGenerator<T> {
/**
* Generate data based on resource snapshot.
*
* @param resourceSnapshot Resource snapshot
* @param pushRequest Push Request
* @return data
*/
List<T> generate(ResourceSnapshot resourceSnapshot);
List<T> generate(PushRequest pushRequest);

/**
* Delta generate data based on resource snapshot.
*
* @param pushRequest Push Request
* @return data
*/
List<Resource> deltaGenerate(PushRequest pushRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

import com.alibaba.nacos.istio.mcp.EmptyMcpGenerator;
import com.alibaba.nacos.istio.mcp.ServiceEntryMcpGenerator;
import com.alibaba.nacos.istio.xds.CdsGenerator;
import com.alibaba.nacos.istio.xds.EdsGenerator;
import com.alibaba.nacos.istio.xds.EmptyXdsGenerator;
import com.alibaba.nacos.istio.xds.LdsGenerator;
import com.alibaba.nacos.istio.xds.RdsGenerator;
import com.alibaba.nacos.istio.xds.ServiceEntryXdsGenerator;
import org.springframework.stereotype.Component;

Expand All @@ -41,6 +45,12 @@ public ApiGeneratorFactory() {
apiGeneratorMap.put(SERVICE_ENTRY_PROTO_PACKAGE, ServiceEntryXdsGenerator.getInstance());
// TODO Support other api generator

//xds
apiGeneratorMap.put(CLUSTER_TYPE, CdsGenerator.getInstance());
apiGeneratorMap.put(ENDPOINT_TYPE, EdsGenerator.getInstance());
apiGeneratorMap.put(LISTENER_TYPE, LdsGenerator.getInstance());
apiGeneratorMap.put(ROUTE_TYPE, RdsGenerator.getInstance());

// mcp
apiGeneratorMap.put(SERVICE_ENTRY_COLLECTION, ServiceEntryMcpGenerator.getInstance());
}
Expand Down
Loading

0 comments on commit 6ffeaac

Please sign in to comment.