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

Extension kubernetes registry #1395

Merged
merged 1 commit into from
Mar 25, 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
6 changes: 6 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@
<artifactId>sofa-rpc-registry-polaris</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-registry-kubernetes</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-remoting-bolt</artifactId>
Expand Down Expand Up @@ -545,6 +550,7 @@
<include>com.alipay.sofa:sofa-rpc-registry-multicast</include>
<include>com.alipay.sofa:sofa-rpc-registry-sofa</include>
<include>com.alipay.sofa:sofa-rpc-registry-polaris</include>
<include>com.alipay.sofa:sofa-rpc-registry-kubernetes</include>
<include>com.alipay.sofa:sofa-rpc-remoting-bolt</include>
<include>com.alipay.sofa:sofa-rpc-remoting-http</include>
<include>com.alipay.sofa:sofa-rpc-remoting-resteasy</include>
Expand Down
15 changes: 15 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
<!-- Build args -->
<module.install.skip>true</module.install.skip>
<module.deploy.skip>true</module.deploy.skip>
<!-- Fabric8 for Kubernetes -->
<fabric8_kubernetes_version>6.9.2</fabric8_kubernetes_version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -514,6 +516,19 @@
<version>${grpc.version}</version>
</dependency>

<!-- Fabric8 for Kubernetes -->
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>${fabric8_kubernetes_version}</version>
wangchengming666 marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-server-mock</artifactId>
<scope>test</scope>
<version>${fabric8_kubernetes_version}</version>
</dependency>

<!-- Test libs -->
<dependency>
<groupId>org.apache.curator</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,36 @@ public String getParameter(String key) {
return parameters == null ? null : parameters.get(key);
}

/**
* Gets parameter or default.
*
* @param key the key
* @return the value
*/
public String getParameter(String key, String defaultValue) {
return getParameter(key) == null ? defaultValue : getParameter(key);
}

/**
* Gets parameter or default.
*
* @param key the key
* @return the value
*/
public int getParameter(String key, int defaultValue) {
return getParameter(key) == null ? defaultValue : Integer.parseInt(parameters.get(key));
Comment on lines +417 to +418
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the getParameter method that returns an int, there's a potential NumberFormatException if the parameter value is not a valid integer. This could lead to runtime exceptions when invalid data is present.

Add error handling for parsing integers to prevent NumberFormatException.

+ try {
+     return getParameter(key) == null ? defaultValue : Integer.parseInt(parameters.get(key));
+ } catch (NumberFormatException e) {
+     LOGGER.warn("Invalid integer parameter value for key: " + key, e);
+     return defaultValue;
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
public int getParameter(String key, int defaultValue) {
return getParameter(key) == null ? defaultValue : Integer.parseInt(parameters.get(key));
public int getParameter(String key, int defaultValue) {
try {
return getParameter(key) == null ? defaultValue : Integer.parseInt(parameters.get(key));
} catch (NumberFormatException e) {
LOGGER.warn("Invalid integer parameter value for key: " + key, e);
return defaultValue;
}

}

/**
* Gets parameter or default.
*
* @param key the key
* @return the value
*/
public boolean getParameter(String key, boolean defaultValue) {
return getParameter(key) == null ? defaultValue : Boolean.parseBoolean(parameters.get(key));
}
Comment on lines +401 to +429
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added getParameter overloaded methods provide a convenient way to retrieve parameters with default values. However, there's a potential performance issue with the string-based getParameter method due to calling getParameter(key) twice.

Optimize the string-based getParameter method to avoid redundant map lookups.

- return getParameter(key) == null ? defaultValue : getParameter(key);
+ String value = getParameter(key);
+ return value == null ? defaultValue : value;

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
/**
* Gets parameter or default.
*
* @param key the key
* @return the value
*/
public String getParameter(String key, String defaultValue) {
return getParameter(key) == null ? defaultValue : getParameter(key);
}
/**
* Gets parameter or default.
*
* @param key the key
* @return the value
*/
public int getParameter(String key, int defaultValue) {
return getParameter(key) == null ? defaultValue : Integer.parseInt(parameters.get(key));
}
/**
* Gets parameter or default.
*
* @param key the key
* @return the value
*/
public boolean getParameter(String key, boolean defaultValue) {
return getParameter(key) == null ? defaultValue : Boolean.parseBoolean(parameters.get(key));
}
/**
* Gets parameter or default.
*
* @param key the key
* @return the value
*/
public String getParameter(String key, String defaultValue) {
String value = getParameter(key);
return value == null ? defaultValue : value;
}
/**
* Gets parameter or default.
*
* @param key the key
* @return the value
*/
public int getParameter(String key, int defaultValue) {
return getParameter(key) == null ? defaultValue : Integer.parseInt(parameters.get(key));
}
/**
* Gets parameter or default.
*
* @param key the key
* @return the value
*/
public boolean getParameter(String key, boolean defaultValue) {
return getParameter(key) == null ? defaultValue : Boolean.parseBoolean(parameters.get(key));
}


@Override
public String toString() {
return "RegistryConfig{" +
Expand Down
1 change: 1 addition & 0 deletions registry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>registry-multicast</module>
<module>registry-sofa</module>
<module>registry-polaris</module>
<module>registry-kubernetes</module>
</modules>

<dependencyManagement>
Expand Down
39 changes: 39 additions & 0 deletions registry/registry-kubernetes/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-registry</artifactId>
<version>${revision}</version>
</parent>

<artifactId>sofa-rpc-registry-kubernetes</artifactId>

<dependencies>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-log</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-api</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-codec-api</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-server-mock</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Loading
Loading