karmada-io / karmada

Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration
https://karmada.io
Apache License 2.0
4.12k stars 807 forks source link

Feat: defining value by CEL in overriders #4799

Open Patrick0308 opened 1 month ago

Patrick0308 commented 1 month ago

What would you like to be added: Supporting defining value by CEL in overriders. And the target k8s resource is been exposed by self object in CEL expression.

About multi override rules

Previous override rules modify the self object

  resourceSelectors:
    - apiVersion: apps/v1
      kind: Deployment
      name: nginx
  overrideRules:
    - targetCluster:
        clusterNames:
          - member1
      overriders:
        labelsOverrider:
          - operator: replace
             value:
              env: member1-env
    - targetCluster:
        clusterNames:
          - member2
      overriders:
        labelsOverrider:
          - operator: replace
             value:
              env: member2-env
    - targetCluster:
        clusterNames:
          - member1
          - member2
      overriders:
        labelsOverrider:
          - operator: add
             expression:
               env1:  self.label['env']  ## env1 label's value is member1-env, member2-env in member1 cluster and member2 cluster.

Why is this needed: At https://github.com/karmada-io/karmada/issues/4739, we discussed the feature of variables on OverridePolicy. And we need a expression language to refer the variables.

CEL is a single line language. It's simple to written in yaml config . And It's been used on k8s validation.

Patrick0308 commented 1 month ago

https://playcel.undistro.io/ This is a cel playground.

chaunceyjiang commented 3 weeks ago

A question: is 'self' referring to the OP themselves or the object chosen by the OP?

Patrick0308 commented 3 weeks ago

A question: is 'self' referring to the OP themselves or the object chosen by the OP?

The k8s resource in a cluster chosen by the OP

chaunceyjiang commented 3 weeks ago

I believe this is a very good solution.

My only concern at the moment is whether Karmada's simultaneous support for Lua and CEL will increase the learning cost for end users.

Patrick0308 commented 3 weeks ago

Lua is not good for expression evaluation. If you only wanna using Lua on karmada, pls adding a ScriptOverrider feature. It's another request. ScriptOverrider's example on above:

overrideRules:
    - targetCluster:
        clusterNames:
          - member1
          - member2
      overriders:
        scriptOverrider:
           inlineString: >
               function modifyObj(self)
                    //...
               end
           configMap:
               name: scripts1
               key: test.lua

My only concern at the moment is whether Karmada's simultaneous support for Lua and CEL will increase the learning cost for end users.

CEL's learning curve is smooth. A simple expression is easy.

RainbowMango commented 3 weeks ago

What problems can be solved by providing the support of CEL? Or can it improve the user experience? Do we have a concrete use case?

Patrick0308 commented 3 weeks ago

@RainbowMango Pls see https://github.com/karmada-io/karmada/issues/4739#issuecomment-2017180616 and the context of this issue.

Patrick0308 commented 3 weeks ago

@XiShanYongYe-Chang @RainbowMango @chaunceyjiang Any idea

RainbowMango commented 3 weeks ago

Sorry, I don't have a chance to dive into it yet. This issue is still in my queue. :( In the meantime, glad to talk at the community meeting.

XiShanYongYe-Chang commented 3 weeks ago

Hi @Patrick0308, I looked at the current issue and the #4739. The features described by both of them are, I understand, two parallel features that extend the OP. Both focus on the way values are obtained in the op.

From the description and comments, both features are amazing, but We'd like to know more about the motivation behind the features, that is, what their user stories are. Maybe we can discuss these two issues in the community meeting to move forward.