From 734cf3ab8f48141270cf95f4c1309b084bf9b650 Mon Sep 17 00:00:00 2001 From: changzhen Date: Tue, 5 Sep 2023 17:15:41 +0800 Subject: [PATCH] fix depndencies lua scrpit bug Signed-off-by: changzhen --- .../config.karmada.io_resourceinterpretercustomizations.yaml | 2 +- .../config/v1alpha1/resourceinterpretercustomization_types.go | 2 +- pkg/generated/openapi/zz_generated.openapi.go | 2 +- .../customized/declarative/luavm/lua_test.go | 2 +- pkg/util/interpreter/rule.go | 2 +- pkg/util/interpreter/rule_test.go | 2 +- pkg/webhook/resourceinterpretercustomization/helper_test.go | 2 +- test/e2e/resourceinterpreter_test.go | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/charts/karmada/_crds/bases/config/config.karmada.io_resourceinterpretercustomizations.yaml b/charts/karmada/_crds/bases/config/config.karmada.io_resourceinterpretercustomizations.yaml index ed0b54000..c46fd1fab 100644 --- a/charts/karmada/_crds/bases/config/config.karmada.io_resourceinterpretercustomizations.yaml +++ b/charts/karmada/_crds/bases/config/config.karmada.io_resourceinterpretercustomizations.yaml @@ -52,7 +52,7 @@ spec: to interpret the dependencies of a specific resource. The script should implement a function as follows: luaScript: > function GetDependencies(desiredObj) dependencies = {} - if desiredObj.spec.serviceAccountName ~= \"\" and desiredObj.spec.serviceAccountName + if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= \"default\" then dependency = {} dependency.apiVersion = \"v1\" dependency.kind = \"ServiceAccount\" dependency.name = desiredObj.spec.serviceAccountName dependency.namespace diff --git a/pkg/apis/config/v1alpha1/resourceinterpretercustomization_types.go b/pkg/apis/config/v1alpha1/resourceinterpretercustomization_types.go index 786a38e44..0c26eec44 100644 --- a/pkg/apis/config/v1alpha1/resourceinterpretercustomization_types.go +++ b/pkg/apis/config/v1alpha1/resourceinterpretercustomization_types.go @@ -275,7 +275,7 @@ type DependencyInterpretation struct { // luaScript: > // function GetDependencies(desiredObj) // dependencies = {} - // if desiredObj.spec.serviceAccountName ~= "" and desiredObj.spec.serviceAccountName ~= "default" then + // if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= "default" then // dependency = {} // dependency.apiVersion = "v1" // dependency.kind = "ServiceAccount" diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 53ffbf391..f16ba1537 100755 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -1781,7 +1781,7 @@ func schema_pkg_apis_config_v1alpha1_DependencyInterpretation(ref common.Referen Properties: map[string]spec.Schema{ "luaScript": { SchemaProps: spec.SchemaProps{ - Description: "LuaScript holds the Lua script that is used to interpret the dependencies of a specific resource. The script should implement a function as follows:\n luaScript: >\n function GetDependencies(desiredObj)\n dependencies = {}\n if desiredObj.spec.serviceAccountName ~= \"\" and desiredObj.spec.serviceAccountName ~= \"default\" then\n dependency = {}\n dependency.apiVersion = \"v1\"\n dependency.kind = \"ServiceAccount\"\n dependency.name = desiredObj.spec.serviceAccountName\n dependency.namespace = desiredObj.namespace\n dependencies[1] = {}\n dependencies[1] = dependency\n end\n return dependencies\n end\n\nThe content of the LuaScript needs to be a whole function including both declaration and implementation.\n\nThe parameters will be supplied by the system:\n - desiredObj: the object represents the configuration to be applied\n to the member cluster.\n\nThe returned value should be expressed by a slice of DependentObjectReference.", + Description: "LuaScript holds the Lua script that is used to interpret the dependencies of a specific resource. The script should implement a function as follows:\n luaScript: >\n function GetDependencies(desiredObj)\n dependencies = {}\n if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= \"default\" then\n dependency = {}\n dependency.apiVersion = \"v1\"\n dependency.kind = \"ServiceAccount\"\n dependency.name = desiredObj.spec.serviceAccountName\n dependency.namespace = desiredObj.namespace\n dependencies[1] = {}\n dependencies[1] = dependency\n end\n return dependencies\n end\n\nThe content of the LuaScript needs to be a whole function including both declaration and implementation.\n\nThe parameters will be supplied by the system:\n - desiredObj: the object represents the configuration to be applied\n to the member cluster.\n\nThe returned value should be expressed by a slice of DependentObjectReference.", Default: "", Type: []string{"string"}, Format: "", diff --git a/pkg/resourceinterpreter/customized/declarative/luavm/lua_test.go b/pkg/resourceinterpreter/customized/declarative/luavm/lua_test.go index 92e9289e6..e8c6b88e6 100644 --- a/pkg/resourceinterpreter/customized/declarative/luavm/lua_test.go +++ b/pkg/resourceinterpreter/customized/declarative/luavm/lua_test.go @@ -543,7 +543,7 @@ func TestGetDeployPodDependencies(t *testing.T) { luaScript: `function GetDependencies(desiredObj) dependentSas = {} refs = {} - if desiredObj.spec.template.spec.serviceAccountName ~= '' and desiredObj.spec.template.spec.serviceAccountName ~= 'default' then + if desiredObj.spec.template.spec.serviceAccountName ~= nil and desiredObj.spec.template.spec.serviceAccountName ~= 'default' then dependentSas[desiredObj.spec.template.spec.serviceAccountName] = true end local idx = 1 diff --git a/pkg/util/interpreter/rule.go b/pkg/util/interpreter/rule.go index 0568f14f1..1b3e173dc 100644 --- a/pkg/util/interpreter/rule.go +++ b/pkg/util/interpreter/rule.go @@ -351,7 +351,7 @@ func (d *dependencyInterpretationRule) Document() string { The script should implement a function as follows: function GetDependencies(desiredObj) dependencies = {} - if desiredObj.spec.serviceAccountName ~= "" and desiredObj.spec.serviceAccountName ~= "default" then + if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= "default" then dependency = {} dependency.apiVersion = "v1" dependency.kind = "ServiceAccount" diff --git a/pkg/util/interpreter/rule_test.go b/pkg/util/interpreter/rule_test.go index 52b9f5ad5..5ef963cd3 100644 --- a/pkg/util/interpreter/rule_test.go +++ b/pkg/util/interpreter/rule_test.go @@ -571,7 +571,7 @@ func TestDependencyInterpretationRule_Document(t *testing.T) { The script should implement a function as follows: function GetDependencies(desiredObj) dependencies = {} - if desiredObj.spec.serviceAccountName ~= "" and desiredObj.spec.serviceAccountName ~= "default" then + if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= "default" then dependency = {} dependency.apiVersion = "v1" dependency.kind = "ServiceAccount" diff --git a/pkg/webhook/resourceinterpretercustomization/helper_test.go b/pkg/webhook/resourceinterpretercustomization/helper_test.go index 622b60f92..a6c100e8f 100644 --- a/pkg/webhook/resourceinterpretercustomization/helper_test.go +++ b/pkg/webhook/resourceinterpretercustomization/helper_test.go @@ -376,7 +376,7 @@ end DependencyInterpretation: &configv1alpha1.DependencyInterpretation{LuaScript: ` function GetDependencies(desiredObj) dependencies = {} - if desiredObj.spec.serviceAccountName ~= "" and desiredObj.spec.serviceAccountName ~= "default" then + if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= "default" then dependency = {} dependency.apiVersion = "v1" dependency.kind = "ServiceAccount" diff --git a/test/e2e/resourceinterpreter_test.go b/test/e2e/resourceinterpreter_test.go index 8d2389bd2..81f46671e 100644 --- a/test/e2e/resourceinterpreter_test.go +++ b/test/e2e/resourceinterpreter_test.go @@ -935,7 +935,7 @@ var _ = framework.SerialDescribe("Resource interpreter customization testing", f function GetDependencies(desiredObj) dependentSas = {} refs = {} - if desiredObj.spec.template.spec.serviceAccountName ~= '' and desiredObj.spec.template.spec.serviceAccountName ~= 'default' then + if desiredObj.spec.template.spec.serviceAccountName ~= nil and desiredObj.spec.template.spec.serviceAccountName ~= 'default' then dependentSas[desiredObj.spec.template.spec.serviceAccountName] = true end local idx = 1