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

add EnvBinding Controller for Multi cluster deploy and Configuration Management #1968

Merged
merged 2 commits into from Jul 30, 2021

Conversation

yangsoon
Copy link
Collaborator

@yangsoon yangsoon commented Jul 26, 2021

What this PR does / why we need it:

this PR add EnvBinding Controller for Multi cluster deploy and Configuration Management.

Now EnvBinding Controller default support use OCM as multi-cluster engine. In the future, we will support other multi-cluster solutions such as karmada etc.

Suppose you have deploy KubeVela in your controller-plane cluster and have use OCM to register multiple ManagedCluster.

You have a ManagedCluster called kind-cluster1

$ kubectl get managedclusters.cluster.open-cluster-management.io
NAME            HUB ACCEPTED   MANAGED CLUSTER URLS             JOINED   AVAILABLE   AGE
kind-cluster1   true           https://hub-control-plane:6443   True     Unknown     10h

And have labeled ManagedCluster with purpose: test.

# kubectl get managedclusters.cluster.open-cluster-management.io kind-cluster1 -o yaml
apiVersion: cluster.open-cluster-management.io/v1
kind: ManagedCluster
metadata:
  finalizers:
  - cluster.open-cluster-management.io/api-resource-cleanup
  generation: 2
  labels:

    purpose: test

  name: kind-cluster1
spec:
  hubAcceptsClient: true
  leaseDurationSeconds: 60
  managedClusterClientConfigs:
  - caBundle: XXX
    url: https://hub-control-plane:6443
status:
  allocatable:
    cpu: "4"
    memory: 7962Mi
  capacity:
    cpu: "4"
    memory: 7962Mi
  conditions:
  - lastTransitionTime: "2021-07-26T01:23:39Z"
    message: Accepted by hub cluster admin
    reason: HubClusterAdminAccepted
    status: "True"
    type: HubAcceptedManagedCluster
  version:
    kubernetes: v1.20.2

Then you can define an EnvBinding object as follow:

apiVersion: core.oam.dev/v1alpha1
kind: EnvBinding
metadata:
  name: test-env
  namespace: default
spec:
  engine: ocm
  # This is the app template you want to configure
  appTemplate:
    apiVersion: core.oam.dev/v1beta1
    kind: Application
    metadata:
      name: test-app
      namespace: default
    spec:
      components:
        - name: myweb
          type: worker
          properties:
            image: busybox
            cmd: ["sleep", "10000"]
  envs:
    - name: env1
      # you can patch properties for application in different envs
      patch:
        components:
          - name: myweb
            type: worker
            properties:
              image: busybox
              cmd: ["sleep", "20000"]
      #  select cluster you want app be deployed to
      placement:
        clusterSelector:
          # you can select by label
          labels:
            purpose: test
          # you can also specify cluster name directly
          #name: kind-cluster1

The EnvBinding Controller will store the manifest of different envs to ConfigMap.

apiVersion: v1
data:
  env1: |
    apiVersion: work.open-cluster-management.io/v1
    kind: ManifestWork
    metadata:
      name: test-app-env1
      namespace: kind-cluster1
    spec:
      workload:
        manifests:
        - apiVersion: apps/v1
          kind: Deployment
          metadata:
            labels:
              app.oam.dev/appRevision: ""
              app.oam.dev/component: myweb
              app.oam.dev/name: test-app
              workload.oam.dev/type: worker
            name: myweb
            namespace: default
          spec:
            selector:
              matchLabels:
                app.oam.dev/component: myweb
            template:
              metadata:
                labels:
                  app.oam.dev/component: myweb
              spec:
                containers:
                - command:
                  - sleep
                  - "20000"
                  image: busybox
                  name: myweb
        - apiVersion: v1
          kind: Pod
          metadata:
            labels:
              app.oam.dev/appRevision: ""
              app.oam.dev/component: myweb
              app.oam.dev/name: test-app
              trait.oam.dev/resource: ingress
              trait.oam.dev/type: AuxiliaryWorkload
            name: test
            namespace: default
          spec:
            containers:
            - command:
              - sleep
              - "20000"
              image: busybox
              name: myweb
kind: ConfigMap
metadata:
  name: test-env
  namespace: default

Which issue(s) this PR fixes:

Fixes #1881

Special notes for your reviewer:

  • add envbinding controller
  • add test

@codecov
Copy link

codecov bot commented Jul 26, 2021

Codecov Report

Merging #1968 (f14b27e) into master (4481e76) will increase coverage by 0.13%.
The diff coverage is 61.97%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1968      +/-   ##
==========================================
+ Coverage   63.78%   63.91%   +0.13%     
==========================================
  Files         152      158       +6     
  Lines       14512    14892     +380     
==========================================
+ Hits         9256     9518     +262     
- Misses       4336     4412      +76     
- Partials      920      962      +42     
Flag Coverage Δ
e2e-rollout-tests 28.88% <10.32%> (-0.47%) ⬇️
e2etests 38.19% <61.97%> (+0.88%) ⬆️
unittests 59.10% <7.69%> (-0.13%) ⬇️

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

Impacted Files Coverage Δ
apis/core.oam.dev/v1alpha2/conversion.go 44.44% <0.00%> (ø)
apis/core.oam.dev/v1beta1/application_types.go 20.00% <ø> (ø)
apis/core.oam.dev/v1beta1/zz_generated.deepcopy.go 41.37% <ø> (+1.02%) ⬆️
pkg/appfile/parser.go 73.33% <ø> (ø)
pkg/oam/util/helper.go 79.00% <33.33%> (-0.95%) ⬇️
pkg/appfile/helm/helm.go 59.45% <50.00%> (-2.55%) ⬇️
...m.dev/v1alpha2/envbinding/envbinding_controller.go 52.00% <52.00%> (ø)
apis/core.oam.dev/common/zz_generated.deepcopy.go 37.95% <53.06%> (+3.77%) ⬆️
...pis/core.oam.dev/v1alpha1/zz_generated.deepcopy.go 53.08% <53.08%> (ø)
...roller/core.oam.dev/v1alpha2/envbinding/binding.go 62.87% <62.87%> (ø)
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4481e76...f14b27e. Read the comment docs.

@yangsoon yangsoon force-pushed the envbinding branch 6 times, most recently from 6a5dc97 to 9c298e4 Compare July 27, 2021 06:08
@yangsoon yangsoon force-pushed the envbinding branch 7 times, most recently from 743ace1 to 69af9f4 Compare July 29, 2021 05:14
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.

good job

@yangsoon yangsoon force-pushed the envbinding branch 5 times, most recently from 3e82395 to 8cc96d6 Compare July 29, 2021 13:04
@yangsoon yangsoon force-pushed the envbinding branch 2 times, most recently from a52741d to 46e1d19 Compare July 29, 2021 13:38
@wonderflow wonderflow merged commit 7161959 into kubevela:master Jul 30, 2021
@wonderflow wonderflow deleted the envbinding branch July 30, 2021 02:02
Somefive pushed a commit to Somefive/kubevela that referenced this pull request Jul 30, 2021
…Management (kubevela#1968)

* patch env configuration

* add e2e-test
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] EnvBinding Controller for Multi cluster deploy and Configuration Management
3 participants