Skip to content
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

Feat: component replication #4449

Merged
merged 10 commits into from
Aug 17, 2022
Merged

Feat: component replication #4449

merged 10 commits into from
Aug 17, 2022

Conversation

chivalryq
Copy link
Member

@chivalryq chivalryq commented Jul 25, 2022

Description of your change

Fixes #4326
Added a replication policy. When using deploy workflow step, it could replicate components with keys. e.g.

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: app-replication-policy
spec:
  components:
    - name: hello-rep
      type: replica-webservice
      properties:
        image: crccheck/hello-world
      traits:
        - type: expose
          properties:
            port: [8000]
    - name: hello-no-rep
      type: webservice
      properties:
        image: crccheck/hello-world
      traits:
        - type: expose
          properties:
            port: [8001]

  policies:
    - name: comp-to-replicate
      type: override
      properties:
        selector: [ "hello-rep" ]
    - name: comp-not-replicate
      type: override
      properties:
        selector: [ "hello-no-rep" ]
    - name: target-default
      type: topology
      properties:
        clusters: [ "local" ]
    - name: replication-default
      type: replication
      properties:
        keys: ["beijing","hangzhou"]
        selector: ["hello-rep"]

  workflow:
    steps:
      - name: deploy-with-rep
        type: deploy
        properties:
          policies: ["comp-to-replicate","target-default","replication-default"]
      - name: deploy-without-rep
        type: deploy
        properties:
          policies: ["comp-not-replicate","target-default"]

Apply Order of Policies

Now, override, topology and replication can work with deploy workflow step. If they are used together, the apply order is:

topology -->  override -->  replication

Replication Spec

replication policy can NOT be used individually. Like topology, it need override to select target components to deploy.
The selector field of replication policy is used to choose which components to replicate. For example, you can specify three components with override policy and only replicate one of them. "comp2" and "comp3" will be dispatched without any replication

  policies:
    - name: select-three
      type: override
      properties:
        selector: [ "comp1", "comp2", "comp3" ]
    - name: replication-default
      type: replication
      properties:
        keys: [ "beijing","hangzhou" ]
        selector: [ "comp1" ]

Special Definition

Given that there aren't too many replication use case now. One want to use replication policy should modify the Component or Trait definition. A new context key replicaKey is provided when render the components. Here is an replica-webservice example in test/e2e-test/testdata/definition/replica-webservice.yaml

Fixes #

I have:

  • Read and followed KubeVela's contribution process.
  • Related Docs updated properly. In a new feature or configuration option, an update to the documentation is necessary.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Special notes for your reviewer

@chivalryq chivalryq changed the title Feature: component replication Feat: component replication Jul 25, 2022
@codecov
Copy link

codecov bot commented Jul 25, 2022

Codecov Report

Merging #4449 (6ef09ca) into master (6a9064b) will increase coverage by 0.15%.
The diff coverage is 93.22%.

@@            Coverage Diff             @@
##           master    #4449      +/-   ##
==========================================
+ Coverage   61.58%   61.74%   +0.15%     
==========================================
  Files         348      352       +4     
  Lines       34425    34773     +348     
==========================================
+ Hits        21201    21470     +269     
- Misses      10467    10501      +34     
- Partials     2757     2802      +45     
Flag Coverage Δ
apiserver-e2etests 28.07% <2.04%> (+0.43%) ⬆️
apiserver-unittests 40.35% <ø> (+0.09%) ⬆️
core-unittests 56.41% <83.05%> (-0.11%) ⬇️
e2e-multicluster-test 20.17% <42.37%> (+0.41%) ⬆️
e2e-rollout-tests 23.27% <27.11%> (+0.33%) ⬆️
e2etests 30.25% <77.96%> (+0.85%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
apis/core.oam.dev/common/types.go 79.31% <ø> (ø)
apis/core.oam.dev/v1alpha1/policy_types.go 100.00% <ø> (ø)
pkg/appfile/appfile.go 78.99% <ø> (+1.01%) ⬆️
pkg/appfile/parser.go 58.98% <ø> (-0.86%) ⬇️
pkg/workflow/providers/oam/apply.go 68.64% <ø> (+3.09%) ⬆️
pkg/workflow/providers/multicluster/deploy.go 78.72% <33.33%> (+1.19%) ⬆️
pkg/policy/replication.go 94.28% <94.28%> (ø)
...ler/core.oam.dev/v1alpha2/application/generator.go 87.93% <100.00%> (+0.65%) ⬆️
...ller/core.oam.dev/v1alpha2/application/revision.go 72.54% <100.00%> (+0.15%) ⬆️
pkg/cue/definition/template.go 67.64% <100.00%> (+4.84%) ⬆️
... and 108 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@wonderflow wonderflow added the backport release-1.5 add this label will automatically backport this PR to release-1.5 branch label Jul 25, 2022
Add e2e test

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
if replicaKey == "" {
return componentName
}
return fmt.Sprintf("%s-%s", componentName, replicaKey)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if a user define workload name in cue template?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be verified if the old style will overwrite the workload name as well.

@Somefive Somefive removed the backport release-1.5 add this label will automatically backport this PR to release-1.5 branch label Jul 29, 2022
@chivalryq chivalryq marked this pull request as draft August 12, 2022 06:29
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
@chivalryq chivalryq marked this pull request as ready for review August 14, 2022 16:40
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
pkg/oam/labels.go Outdated Show resolved Hide resolved
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Copy link
Collaborator

@Somefive Somefive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Job! LGTM

type ReplicationPolicySpec struct {
Keys []string `json:"keys,omitempty"`
// Selector is the subset of selected components which will be replicated.
Selector []string `json:"selector,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the selector can only specify components?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently yes. It works similar to the selector field in override policy. We can make further extension in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, what else? Trait?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe other component selection ways, like selecting components through regex?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's a string, it lacks flexible?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it lacks flexibility. The consideration here is:

  1. It aligns with the design of override policy, although override policy also lacks flexibility, but it is easy to understand.
  2. It satisfy the scenario we currently encountered by far.
  3. We could have more extension ways in the future. For now although it would be nice to make it more extensible, I do not have too much good points due to the lack of more advanced feature requests.

@Somefive
Copy link
Collaborator

FYI, @chivalryq , a CUE file might need to be added to provide OpenAPI Schema for VelaUX and auto-generate documentations for kubevela.io. We can do it in another PR.

@@ -82,6 +84,10 @@ func (executor *deployWorkflowStepExecutor) Deploy(ctx context.Context, policyNa
if err != nil {
return false, "", err
}
components, err = pkgpolicy.ReplicateComponents(policies, components)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen if the replicaComponent don't use the replicaKey in the definition template?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • If the definition template relies on replicaKey field, an error will be thrown for the incorrect use of that component/trait.
  • If the definition template use the replicaKey field and has a fallback logic for handling the lack of replicaKey, it will be fine to use the definition with or without replicaKey.
  • If the definition template does not use the replicaKey, nothing will be happened while using the replicaKey. (The component will be repeated dispatched but there is no side effect.)

Copy link
Member Author

@chivalryq chivalryq Aug 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it depends on definitions. In definition it can check if context.replicaKey is nil. Just like I did in replica-webservice.yaml. But it's not recommended to mix component designed for replication and common ones.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if one component use the replica key in the definition, but it's used in a fixed workload name? It will apply many times with the last config? What about next time? Does it cause any infinitely loop?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a problem. We can optimize it later. Like scanning the definition used when replicate.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will apply many times but will not cause infinite loop. Replication does not mutate configurations. Multiple apply will be the same.

@chivalryq
Copy link
Member Author

FYI, @chivalryq , a CUE file might need to be added to provide OpenAPI Schema for VelaUX and auto-generate documentations for kubevela.io. We can do it in another PR.

Got it.

Copy link
Collaborator

@wonderflow wonderflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add definition cue file with example markdown file (and some necessary explanation of the usage.)

It's really tricky when use it in definition.

Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
@chivalryq
Copy link
Member Author

ping @wonderflow definition cue and example md added.

Copy link
Collaborator

@wonderflow wonderflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job

@chivalryq chivalryq merged commit 924d553 into kubevela:master Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] support edge application delivery
4 participants