Skip to content

Commit d05b921

Browse files
authored
Merge pull request #4998 from chaosi-zju/dev
fix demo for dependencyInterpretation
2 parents 37dd12f + 3c731e5 commit d05b921

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

api/openapi-spec/swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17605,7 +17605,7 @@
1760517605
],
1760617606
"properties": {
1760717607
"luaScript": {
17608-
"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\n```\n luaScript: \u003e\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```\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.",
17608+
"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\n```\n luaScript: \u003e\n function GetDependencies(desiredObj)\n dependencies = {}\n serviceAccountName = desiredObj.spec.template.spec.serviceAccountName\n if serviceAccountName ~= nil and serviceAccountName ~= \"default\" then\n dependency = {}\n dependency.apiVersion = \"v1\"\n dependency.kind = \"ServiceAccount\"\n dependency.name = serviceAccountName\n dependency.namespace = desiredObj.metadata.namespace\n dependencies[1] = dependency\n end\n return dependencies\n end\n```\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.",
1760917609
"type": "string",
1761017610
"default": ""
1761117611
}

charts/karmada/_crds/bases/config/config.karmada.io_resourceinterpretercustomizations.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ spec:
6969
luaScript: >
7070
function GetDependencies(desiredObj)
7171
dependencies = {}
72-
if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= "default" then
72+
serviceAccountName = desiredObj.spec.template.spec.serviceAccountName
73+
if serviceAccountName ~= nil and serviceAccountName ~= "default" then
7374
dependency = {}
7475
dependency.apiVersion = "v1"
7576
dependency.kind = "ServiceAccount"
76-
dependency.name = desiredObj.spec.serviceAccountName
77-
dependency.namespace = desiredObj.namespace
78-
dependencies[1] = {}
77+
dependency.name = serviceAccountName
78+
dependency.namespace = desiredObj.metadata.namespace
7979
dependencies[1] = dependency
8080
end
8181
return dependencies

pkg/apis/config/v1alpha1/resourceinterpretercustomization_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ type DependencyInterpretation struct {
322322
// luaScript: >
323323
// function GetDependencies(desiredObj)
324324
// dependencies = {}
325-
// if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= "default" then
325+
// serviceAccountName = desiredObj.spec.template.spec.serviceAccountName
326+
// if serviceAccountName ~= nil and serviceAccountName ~= "default" then
326327
// dependency = {}
327328
// dependency.apiVersion = "v1"
328329
// dependency.kind = "ServiceAccount"
329-
// dependency.name = desiredObj.spec.serviceAccountName
330-
// dependency.namespace = desiredObj.namespace
331-
// dependencies[1] = {}
330+
// dependency.name = serviceAccountName
331+
// dependency.namespace = desiredObj.metadata.namespace
332332
// dependencies[1] = dependency
333333
// end
334334
// return dependencies

pkg/generated/openapi/zz_generated.openapi.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/util/interpreter/rule.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,14 @@ func (d *dependencyInterpretationRule) Document() string {
367367
The script should implement a function as follows:
368368
function GetDependencies(desiredObj)
369369
dependencies = {}
370-
if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= "default" then
370+
serviceAccountName = desiredObj.spec.template.spec.serviceAccountName
371+
if serviceAccountName ~= nil and serviceAccountName ~= "default" then
371372
dependency = {}
372373
dependency.apiVersion = "v1"
373374
dependency.kind = "ServiceAccount"
374-
dependency.name = desiredObj.spec.serviceAccountName
375-
dependency.namespace = desiredObj.namespace
376-
dependencies[0] = {}
377-
dependencies[0] = dependency
375+
dependency.name = serviceAccountName
376+
dependency.namespace = desiredObj.metadata.namespace
377+
dependencies[1] = dependency
378378
end
379379
return dependencies
380380
end`

pkg/util/interpreter/rule_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,14 @@ func TestDependencyInterpretationRule_Document(t *testing.T) {
587587
The script should implement a function as follows:
588588
function GetDependencies(desiredObj)
589589
dependencies = {}
590-
if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= "default" then
590+
serviceAccountName = desiredObj.spec.template.spec.serviceAccountName
591+
if serviceAccountName ~= nil and serviceAccountName ~= "default" then
591592
dependency = {}
592593
dependency.apiVersion = "v1"
593594
dependency.kind = "ServiceAccount"
594-
dependency.name = desiredObj.spec.serviceAccountName
595-
dependency.namespace = desiredObj.namespace
596-
dependencies[0] = {}
597-
dependencies[0] = dependency
595+
dependency.name = serviceAccountName
596+
dependency.namespace = desiredObj.metadata.namespace
597+
dependencies[1] = dependency
598598
end
599599
return dependencies
600600
end`

pkg/webhook/resourceinterpretercustomization/helper_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,15 @@ end
391391
`},
392392
DependencyInterpretation: &configv1alpha1.DependencyInterpretation{LuaScript: `
393393
function GetDependencies(desiredObj)
394-
dependencies = {}
395-
if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= "default" then
394+
dependencies = {}
395+
serviceAccountName = desiredObj.spec.template.spec.serviceAccountName
396+
if serviceAccountName ~= nil and serviceAccountName ~= "default" then
396397
dependency = {}
397398
dependency.apiVersion = "v1"
398399
dependency.kind = "ServiceAccount"
399-
dependency.name = desiredObj.spec.serviceAccountName
400-
dependency.namespace = desiredObj.namespace
401-
dependencies[0] = {}
402-
dependencies[0] = dependency
400+
dependency.name = serviceAccountName
401+
dependency.namespace = desiredObj.metadata.namespace
402+
dependencies[1] = dependency
403403
end
404404
return dependencies
405405
end

0 commit comments

Comments
 (0)