Skip to content

Commit

Permalink
fix: Use failStrategy FAILED_OPEN in all generated WasmPlugin resourc…
Browse files Browse the repository at this point in the history
…es (#363)
  • Loading branch information
CH3CHO authored Nov 5, 2024
1 parent 8dbeb49 commit f112a30
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import com.alibaba.higress.sdk.service.kubernetes.crd.mcp.V1McpBridge;
import com.alibaba.higress.sdk.service.kubernetes.crd.mcp.V1McpBridgeSpec;
import com.alibaba.higress.sdk.service.kubernetes.crd.mcp.V1RegistryConfig;
import com.alibaba.higress.sdk.service.kubernetes.crd.wasm.FailStrategy;
import com.alibaba.higress.sdk.service.kubernetes.crd.wasm.MatchRule;
import com.alibaba.higress.sdk.service.kubernetes.crd.wasm.PluginPhase;
import com.alibaba.higress.sdk.service.kubernetes.crd.wasm.V1alpha1WasmPlugin;
Expand Down Expand Up @@ -449,6 +450,7 @@ public V1alpha1WasmPlugin wasmPluginToCr(WasmPlugin plugin, Boolean internal) {
spec.setPhase(plugin.getPhase());
spec.setPriority(plugin.getPriority());
spec.setUrl(buildImageUrl(plugin.getImageRepository(), plugin.getImageVersion()));
setDefaultValues(spec);
cr.setSpec(spec);

return cr;
Expand Down Expand Up @@ -479,6 +481,7 @@ public void mergeWasmPluginSpec(V1alpha1WasmPlugin srcPlugin, V1alpha1WasmPlugin
dstSpec.getMatchRules().addAll(srcSpec.getMatchRules());
}
sortWasmPluginMatchRules(dstSpec.getMatchRules());
setDefaultValues(dstSpec);
}

public List<WasmPluginInstance> getWasmPluginInstancesFromCr(V1alpha1WasmPlugin plugin) {
Expand Down Expand Up @@ -727,6 +730,7 @@ public void setWasmPluginInstanceToCr(V1alpha1WasmPlugin cr, WasmPluginInstance
throw new IllegalArgumentException("Unsupported scope: " + scope);
}
sortWasmPluginMatchRules(matchRules);
setDefaultValues(spec);
}

public boolean removeWasmPluginInstanceFromCr(V1alpha1WasmPlugin cr, WasmPluginInstanceScope scope, String target) {
Expand Down Expand Up @@ -867,6 +871,10 @@ private static int compareMatchRules(MatchRule r1, MatchRule r2) {
return hasDomain1 ? compareStringLists(r1.getDomain(), r2.getDomain()) : 0;
}

private static void setDefaultValues(V1alpha1WasmPluginSpec spec) {
spec.setFailStrategy(FailStrategy.FAIL_OPEN.getName());
}

private static int compareStringLists(List<String> l1, List<String> l2) {
boolean empty1 = CollectionUtils.isEmpty(l1);
boolean empty2 = CollectionUtils.isEmpty(l2);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2022-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.higress.sdk.service.kubernetes.crd.wasm;

public enum FailStrategy {

/**
* A fatal error in the binary fetching or during the plugin execution causes all subsequent requests to fail with
* 5xx.
*/
FAIL_CLOSE("FAIL_CLOSE", 0),

/**
* Enables the fail open behavior for the Wasm plugin fatal errors to bypass the plugin execution. A fatal error can
* be a failure to fetch the remote binary, an exception, or abort() on the VM. This flag is not recommended for the
* authentication or the authorization plugins.
*/
FAIL_OPEN("FAIL_OPEN", 1);

private final String name;
private final int value;

FailStrategy(String name, int value) {
this.name = name;
this.value = value;
}

public String getName() {
return name;
}

public int getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public class V1alpha1WasmPluginSpec {
private String url;

private String verificationKey;

private String failStrategy;
}

0 comments on commit f112a30

Please sign in to comment.