Skip to content

Commit e625b7c

Browse files
authored
feat: add pluginImageRegistry and pluginImageNamespace config for built-in plugins (higress-group#666)
1 parent 955d548 commit e625b7c

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

backend/sdk/src/main/java/com/alibaba/higress/sdk/model/wasmplugin/WasmPluginServiceConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
public class WasmPluginServiceConfig {
2424
private static final String CUSTOM_IMAGE_URL_PATTERN_ENV = "HIGRESS_ADMIN_WASM_PLUGIN_CUSTOM_IMAGE_URL_PATTERN";
2525
private static final String CUSTOM_IMAGE_URL_PATTERN_PROPERTY = "higress-admin.wasmplugin.custom-image-url-pattern";
26+
private static final String PLUGIN_IMAGE_REGISTRY_ENV = "HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_REGISTRY";
27+
private static final String PLUGIN_IMAGE_REGISTRY_PROPERTY = "higress-admin.wasmplugin.plugin-image-registry";
28+
private static final String PLUGIN_IMAGE_NAMESPACE_ENV = "HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_NAMESPACE";
29+
private static final String PLUGIN_IMAGE_NAMESPACE_PROPERTY = "higress-admin.wasmplugin.plugin-image-namespace";
2630
private static final String CUSTOM_IMAGE_PULL_SECRET_ENV = "HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_PULL_SECRET";
2731
private static final String CUSTOM_IMAGE_PULL_POLICY_ENV = "HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_PULL_POLICY";
2832
private static final String CUSTOM_IMAGE_PULL_SECRET_PROPERTY = "higress-admin.wasmplugin.custom-image-pull-secret";
@@ -32,6 +36,10 @@ public static WasmPluginServiceConfig buildFromEnv() {
3236
WasmPluginServiceConfig result = new WasmPluginServiceConfig();
3337
result.customImageUrlPattern =
3438
EnvReadUtil.loadCustomConfFromEnv(CUSTOM_IMAGE_URL_PATTERN_PROPERTY, CUSTOM_IMAGE_URL_PATTERN_ENV);
39+
result.pluginImageRegistry =
40+
EnvReadUtil.loadCustomConfFromEnv(PLUGIN_IMAGE_REGISTRY_PROPERTY, PLUGIN_IMAGE_REGISTRY_ENV);
41+
result.pluginImageNamespace =
42+
EnvReadUtil.loadCustomConfFromEnv(PLUGIN_IMAGE_NAMESPACE_PROPERTY, PLUGIN_IMAGE_NAMESPACE_ENV);
3543
result.imagePullSecret =
3644
EnvReadUtil.loadCustomConfFromEnv(CUSTOM_IMAGE_PULL_SECRET_PROPERTY, CUSTOM_IMAGE_PULL_SECRET_ENV);
3745
result.imagePullPolicy =
@@ -40,6 +48,8 @@ public static WasmPluginServiceConfig buildFromEnv() {
4048
}
4149

4250
private String customImageUrlPattern;
51+
private String pluginImageRegistry;
52+
private String pluginImageNamespace;
4353
private String imagePullSecret;
4454
private String imagePullPolicy;
4555
}

backend/sdk/src/main/java/com/alibaba/higress/sdk/service/WasmPluginServiceImpl.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class WasmPluginServiceImpl implements WasmPluginService {
9696

9797
private static final String NAME_PLACEHOLDER = "${name}";
9898
private static final String VERSION_PLACEHOLDER = "${version}";
99+
private static final String OCI_PROTOCOL = "oci://";
100+
private static final String DEFAULT_IMAGE_REGISTRY = "higress-registry.cn-hangzhou.cr.aliyuncs.com";
101+
private static final String DEFAULT_IMAGE_NAMESPACE = "plugins";
99102

100103
private volatile List<PluginCacheItem> builtInPlugins = Collections.emptyList();
101104

@@ -125,6 +128,8 @@ public void initialize() {
125128
final List<PluginCacheItem> plugins = new ArrayList<>(properties.size());
126129

127130
final String customImageUrlPattern = wasmPluginServiceConfig.getCustomImageUrlPattern();
131+
final String pluginImageRegistry = wasmPluginServiceConfig.getPluginImageRegistry();
132+
final String pluginImageNamespace = wasmPluginServiceConfig.getPluginImageNamespace();
128133
final String imagePullSecret = wasmPluginServiceConfig.getImagePullSecret();
129134
final String imagePullPolicy = wasmPluginServiceConfig.getImagePullPolicy();
130135

@@ -152,8 +157,8 @@ public void initialize() {
152157
ex);
153158
}
154159

155-
cacheItem.imageUrl = StringUtils.isBlank(customImageUrlPattern) ? imageUrl
156-
: formatImageUrl(customImageUrlPattern, cacheItem.plugin.getInfo());
160+
cacheItem.imageUrl = buildPluginImageUrl(imageUrl, customImageUrlPattern, pluginImageRegistry,
161+
pluginImageNamespace, cacheItem.plugin.getInfo());
157162
cacheItem.imagePullSecret = imagePullSecret;
158163
cacheItem.imagePullPolicy = imagePullPolicy;
159164

@@ -185,6 +190,46 @@ private static String formatImageUrl(String pattern, PluginInfo pluginInfo) {
185190
.replace(VERSION_PLACEHOLDER, pluginInfo.getVersion());
186191
}
187192

193+
private static String buildPluginImageUrl(String defaultUrl, String customPattern, String registry,
194+
String namespace, PluginInfo pluginInfo) {
195+
// Priority: customPattern > registry/namespace > defaultUrl
196+
if (StringUtils.isNotBlank(customPattern)) {
197+
return formatImageUrl(customPattern, pluginInfo);
198+
}
199+
200+
if (StringUtils.isBlank(registry) && StringUtils.isBlank(namespace)) {
201+
return defaultUrl;
202+
}
203+
204+
// Replace registry and/or namespace in the default URL
205+
// URL format: oci://registry/namespace/plugin-name:version
206+
if (!defaultUrl.startsWith(OCI_PROTOCOL)) {
207+
return defaultUrl;
208+
}
209+
210+
String urlWithoutProtocol = defaultUrl.substring(OCI_PROTOCOL.length());
211+
String targetRegistry = StringUtils.isNotBlank(registry) ? registry : DEFAULT_IMAGE_REGISTRY;
212+
String targetNamespace = StringUtils.isNotBlank(namespace) ? namespace : DEFAULT_IMAGE_NAMESPACE;
213+
214+
// Find the first slash to locate registry end
215+
int firstSlash = urlWithoutProtocol.indexOf('/');
216+
if (firstSlash == -1) {
217+
return defaultUrl;
218+
}
219+
220+
// Find the second slash to locate namespace end
221+
int secondSlash = urlWithoutProtocol.indexOf('/', firstSlash + 1);
222+
if (secondSlash == -1) {
223+
return defaultUrl;
224+
}
225+
226+
// Extract the plugin name and version part (after second slash)
227+
String pluginPath = urlWithoutProtocol.substring(secondSlash + 1);
228+
229+
// Rebuild the URL with new registry and namespace
230+
return OCI_PROTOCOL + targetRegistry + "/" + targetNamespace + "/" + pluginPath;
231+
}
232+
188233
private void fillPluginConfigExample(Plugin plugin, String content) {
189234
String example;
190235
try {

helm/templates/deployment.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{{- $o11y := merge (dict) .Values.o11y .Values.global.o11y }}
2+
{{- $pluginImageRegistry := .Values.pluginServer.imageRegistry | default .Values.global.hub }}
3+
{{- $pluginImageNamespace := .Values.pluginServer.imageNamespace | default .Values.global.pluginNamespace }}
24
apiVersion: apps/v1
35
kind: Deployment
46
metadata:
@@ -74,6 +76,20 @@ spec:
7476
- name: HIGRESS_ADMIN_WASM_PLUGIN_CUSTOM_IMAGE_URL_PATTERN
7577
value: "{{ .Values.pluginServer.urlPattern }}"
7678
{{- end }}
79+
{{- if and .Values.pluginServer.imageRegistry (not (hasKey .Values.podEnvs "HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_REGISTRY")) }}
80+
- name: HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_REGISTRY
81+
value: "{{ .Values.pluginServer.imageRegistry }}"
82+
{{- else if and $pluginImageRegistry (not (hasKey .Values.podEnvs "HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_REGISTRY")) }}
83+
- name: HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_REGISTRY
84+
value: "{{ $pluginImageRegistry }}"
85+
{{- end }}
86+
{{- if and .Values.pluginServer.imageNamespace (not (hasKey .Values.podEnvs "HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_NAMESPACE")) }}
87+
- name: HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_NAMESPACE
88+
value: "{{ .Values.pluginServer.imageNamespace }}"
89+
{{- else if and $pluginImageNamespace (not (hasKey .Values.podEnvs "HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_NAMESPACE")) }}
90+
- name: HIGRESS_ADMIN_WASM_PLUGIN_IMAGE_NAMESPACE
91+
value: "{{ $pluginImageNamespace }}"
92+
{{- end }}
7793
{{- if .Values.podEnvs }}
7894
{{- range $key, $val := .Values.podEnvs }}
7995
- name: {{ $key }}

helm/values.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ global:
99
# cluster domain. Default value is "cluster.local".
1010
clusterDomain: "cluster.local"
1111

12+
# -- Default hub (registry) for Higress images, passed from parent chart.
13+
# Used for plugin image registry when pluginServer.imageRegistry is not set.
14+
hub: ""
15+
# -- Plugin image namespace for built-in plugins, passed from parent chart.
16+
# Used when pluginServer.imageNamespace is not set. Default is "plugins".
17+
pluginNamespace: ""
18+
1219
# Observability (o11y) configurations
1320
o11y:
1421
enabled: false
@@ -130,3 +137,9 @@ pvc:
130137

131138
pluginServer:
132139
urlPattern: "http://higress-plugin-server.higress-system.svc/plugins/${name}/${version}/plugin.wasm"
140+
# -- Plugin image registry for built-in plugins. If set, will override the default registry in plugins.properties.
141+
# Example: "my-registry.example.com"
142+
imageRegistry: ""
143+
# -- Plugin image namespace for built-in plugins. If set, will override the default namespace in plugins.properties.
144+
# Default namespace is "plugins". Example: "my-plugins"
145+
imageNamespace: ""

0 commit comments

Comments
 (0)