Skip to content

Commit 7b5ac69

Browse files
committed
Implement GetComponents for thirdpartyInterpreter
Signed-off-by: wei-chenglai <[email protected]>
1 parent 17caa1b commit 7b5ac69

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pkg/resourceinterpreter/default/thirdparty/thirdparty.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func (p *ConfigurableInterpreter) HookEnabled(kind schema.GroupVersionKind, oper
5656
script = customAccessor.GetHealthInterpretationLuaScript()
5757
case configv1alpha1.InterpreterOperationInterpretReplica:
5858
script = customAccessor.GetReplicaResourceLuaScript()
59+
case configv1alpha1.InterpreterOperationInterpretComponent:
60+
script = customAccessor.GetComponentResourceLuaScript()
5961
case configv1alpha1.InterpreterOperationInterpretStatus:
6062
script = customAccessor.GetStatusReflectionLuaScript()
6163
case configv1alpha1.InterpreterOperationRetain:
@@ -85,6 +87,25 @@ func (p *ConfigurableInterpreter) GetReplicas(object *unstructured.Unstructured)
8587
return
8688
}
8789

90+
// GetComponents returns the desired components of the object.
91+
func (p *ConfigurableInterpreter) GetComponents(object *unstructured.Unstructured) (components []workv1alpha2.ComponentRequirements, enabled bool, err error) {
92+
klog.V(4).Infof("Get components for object: %v %s/%s with thirdparty configurable interpreter.", object.GroupVersionKind(), object.GetNamespace(), object.GetName())
93+
94+
customAccessor, enabled := p.getCustomAccessor(object.GroupVersionKind())
95+
if !enabled {
96+
return
97+
}
98+
99+
script := customAccessor.GetComponentResourceLuaScript()
100+
if len(script) == 0 {
101+
enabled = false
102+
return
103+
}
104+
105+
components, err = p.luaVM.GetComponents(object, script)
106+
return
107+
}
108+
88109
// ReviseReplica revises the replica of the given object.
89110
func (p *ConfigurableInterpreter) ReviseReplica(object *unstructured.Unstructured, replica int64) (revised *unstructured.Unstructured, enabled bool, err error) {
90111
klog.V(4).Infof("Revise replicas for object: %v %s/%s with thirdparty configurable interpreter.", object.GroupVersionKind(), object.GetNamespace(), object.GetName())

pkg/resourceinterpreter/interpreter.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ func (i *customResourceInterpreterImpl) GetComponents(object *unstructured.Unstr
216216
return components, nil
217217
}
218218

219+
components, hookEnabled, err = i.thirdpartyInterpreter.GetComponents(object)
220+
if err != nil {
221+
return nil, err
222+
}
223+
if hookEnabled {
224+
return components, nil
225+
}
226+
219227
// TODO(@RainbowMango): Implement GetComponents for extracting per-component replica and resource requirements.
220228
// Follow up tracked by: https://github.com/karmada-io/karmada/issues/6641
221229
return nil, errors.New("interface GetComponents not implemented yet")

0 commit comments

Comments
 (0)