-
Notifications
You must be signed in to change notification settings - Fork 919
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
add execute mod for interpret command #2824
add execute mod for interpret command #2824
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2824 +/- ##
==========================================
- Coverage 37.84% 37.79% -0.06%
==========================================
Files 190 191 +1
Lines 17696 17715 +19
==========================================
- Hits 6697 6695 -2
- Misses 10592 10612 +20
- Partials 407 408 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Hi @ikaven1024 as #2750 has been merged, dose this need to rebase the master branch? |
ca4de7c
to
fb27426
Compare
@RainbowMango @XiShanYongYe-Chang this PR is ready for reviewing. |
06f246c
to
4423a0b
Compare
/assign @XiShanYongYe-Chang |
How about providing some test demos for each action in the library, otherwise it's too difficult for users to construct tests, such as |
@RainbowMango How do you think? |
pkg/resourceinterpreter/configurableinterpreter/configmanager/manager.go
Outdated
Show resolved
Hide resolved
What kind of demo we are taking about? And, to which library? |
aefe334
to
87a47b6
Compare
Demo for
Current library, such as |
25b54d4
to
f70eafd
Compare
287f6a3
to
c898140
Compare
func(_ interface{}) { manager.updateConfiguration() }) | ||
inform.ForResource(resourceInterpreterCustomizationsGVR, configHandlers) | ||
|
||
if inform != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When will the inform
be nil?
By the way, inform
should be informer
, it's a typo brought by the previous patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When will the
inform
be nil?
In executing mode, config is not synced from informer, it's loaded by
interpreter := configurableinterpreter.NewConfigurableInterpreter(nil)
So informer is unused in this mode.
By the way,
inform
should beinformer
, it's a typo brought by the previous patch.
updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you met a case that the informer
is nil
?
I'm still confused about why to add the if inform != nil
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In interpret command, we don't use informer, so it's nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add some comments to explain the situation where informer is nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add some comments to explain the situation where informer is nil.
Updated.
The function test is okay. yaml preparation: observed-deploy-nginx.yamlapiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 3
paused: true
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
status:
availableReplicas: 2
observedGeneration: 1
readyReplicas: 2
replicas: 2
updatedReplicas: 2 desired-deploy-nginx.yamlapiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 3
paused: false
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
serviceAccountName: test-sa config.yamlapiVersion: config.karmada.io/v1alpha1
kind: ResourceInterpreterCustomization
metadata:
name: get-replica
spec:
target:
apiVersion: apps/v1
kind: Deployment
customizations:
retention:
replicaResource:
luaScript: >
function GetReplicas(obj)
replica = obj.spec.replicas
requirement = {}
return replica, requirement
end
replicaRevision:
luaScript: >
function ReviseReplica(obj, desiredReplica)
obj.spec.replicas = desiredReplica
return obj
end
retention:
luaScript: >
function Retain(desiredObj, observedObj)
desiredObj.spec.paused = observedObj.spec.paused
return desiredObj
end
statusAggregation:
luaScript: >
function AggregateStatus(desiredObj, statusItems)
if statusItems == nil then
return desiredObj
end
if desiredObj.status == nil then
desiredObj.status = {}
end
replicas = 0
for i = 1, #statusItems do
if statusItems[i].status ~= nil and statusItems[i].status.replicas ~= nil then
replicas = replicas + statusItems[i].status.replicas
end
end
desiredObj.status.replicas = replicas
return desiredObj
end
statusReflection:
luaScript: >
function ReflectStatus (observedObj)
if observedObj.status == nil then
return nil
end
return observedObj.status
end
healthInterpretation:
luaScript: >
function InterpretHealth(observedObj)
return observedObj.status.readyReplicas == observedObj.spec.replicas
end
dependencyInterpretation:
luaScript: >
function GetDependencies(desiredObj)
dependentSas = {}
refs = {}
if desiredObj.spec.template.spec.serviceAccountName ~= '' and desiredObj.spec.template.spec.serviceAccountName ~= 'default' then
dependentSas[desiredObj.spec.template.spec.serviceAccountName] = true
end
local idx = 1
for key, value in pairs(dependentSas) do
dependObj = {}
dependObj.apiVersion = 'v1'
dependObj.kind = 'ServiceAccount'
dependObj.name = key
dependObj.namespace = desiredObj.metadata.namespace
refs[idx] = dependObj
idx = idx + 1
end
return refs
end status-file.yamlapplied: true
clusterName: member1
health: Healthy
status:
availableReplicas: 1
readyReplicas: 1
replicas: 1
updatedReplicas: 1
---
applied: true
clusterName: member2
health: Healthy
status:
availableReplicas: 1
readyReplicas: 1
replicas: 1
updatedReplicas: 1 test command:
|
c898140
to
47cb8a6
Compare
Signed-off-by: yingjinhui <yingjinhui@didiglobal.com>
47cb8a6
to
4a37e9c
Compare
Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
Thanks.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: RainbowMango The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: yingjinhui yingjinhui@didiglobal.com
What type of PR is this?
/kind feature
What this PR does / why we need it:
add skeleton of interpreter command.
Which issue(s) this PR fixes:
part of #2371
Special notes for your reviewer:
Testing
Prepare a
get-replica.yml
and
deploy-nginx.yml
Output:
Does this PR introduce a user-facing change?: