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: Support trait with custom resource be dispatched to hubcluster #3774

Merged
merged 1 commit into from
Apr 28, 2022

Conversation

fourierr
Copy link
Member

@fourierr fourierr commented Apr 28, 2022

Signed-off-by: Xiangbo Ma maxiangboo@cmbchina.com

Description of your changes

Support trait with custom resource be dispatched to hubcluster
Fixes #3754

The following is an example of how to use controlPlaneOnly

  • Firstly, hubcpuscaler is defined on the basis of cpusccaler, so that HPA can be deployed to hubcuster
hubcpuscaler: {
	type: "trait"
	annotations: {}
	labels: {
		"ui-hidden": "true"
	}
	description: "Automatically scale the component based on CPU usage."
	attributes: {
		appliesToWorkloads: ["deployments.apps"]
		controlPlaneOnly: true
	}
}

template: {
	outputs: hubcpuscaler: {
		apiVersion: "autoscaling/v1"
		kind:       "HorizontalPodAutoscaler"
		metadata: name: context.name
		spec: {
			scaleTargetRef: {
				apiVersion: parameter.targetAPIVersion
				kind:       parameter.targetKind
				name:       context.name
			}
			minReplicas:                    parameter.min
			maxReplicas:                    parameter.max
			targetCPUUtilizationPercentage: parameter.cpuUtil
		}
	}

	parameter: {
		// +usage=Specify the minimal number of replicas to which the autoscaler can scale down
		min: *1 | int
		// +usage=Specify the maximum number of of replicas to which the autoscaler can scale up
		max: *10 | int
		// +usage=Specify the average CPU utilization, for example, 50 means the CPU usage is 50%
		cpuUtil: *50 | int
		// +usage=Specify the apiVersion of scale target
		targetAPIVersion: *"apps/v1" | string
		// +usage=Specify the kind of scale target
		targetKind: *"Deployment" | string
	}
}
  • Secondly, write application file and apply
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: fourierapp03
  namespace: fourier
spec:
  components:
    - name: fourierapp03-fouriercomponent-01
      type: webservice
      properties:
        image: busybox:latest
        imagePullPolicy: IfNotPresent
        cmd: [ "sleep", "10000" ]
        cpu: "0.1"
        mem: "100Mi"
      traits:
        - type: hubcpuscaler
          properties:
            min: 1
            max: 10
            cpuPercent: 60
        - type: expose
          properties:
            port: [ 80 ]
  policies:
    - name: fourierapp03-topology-01
      type: topology
      properties:
        clusters: [ "kind01" ]
        namespace: fourier01
    - name: fourierapp03-topology-02
      type: topology
      properties:
        clusters: [ "kind02" ]
        namespace: fourier02
  workflow:
    steps:
      - type: deploy
        name: fourierapp03-deploy-01
        properties:
          policies: [ "fourierapp03-topology-01","fourierapp03-topology-02" ]
  • Finally, you can see that HPA was dispatched to cluster local, deployment and service were dispatched to the cluster kind01, kind02 .
  • And if you remove the hubcpuscaler in application, the Custom Resource in local will be GC Simultaneously. as shown below
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: fourierapp03
  namespace: fourier
spec:
  components:
    - name: fourierapp03-fouriercomponent-01
      type: webservice
      properties:
        image: busybox:latest
        imagePullPolicy: IfNotPresent
        cmd: [ "sleep", "10000" ]
        cpu: "0.1"
        mem: "100Mi"
      traits:
        - type: expose
          properties:
            port: [ 80 ]
  policies:
    - name: fourierapp03-topology-01
      type: topology
      properties:
        clusters: [ "kind01" ]
        namespace: fourier01
    - name: fourierapp03-topology-02
      type: topology
      properties:
        clusters: [ "kind02" ]
        namespace: fourier02
  workflow:
    steps:
      - type: deploy
        name: fourierapp03-deploy-01
        properties:
          policies: [ "fourierapp03-topology-01","fourierapp03-topology-02" ]

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.

@codecov
Copy link

codecov bot commented Apr 28, 2022

Codecov Report

Merging #3774 (495aced) into master (6761b18) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #3774      +/-   ##
==========================================
+ Coverage   63.87%   63.90%   +0.02%     
==========================================
  Files         309      309              
  Lines       29439    29452      +13     
==========================================
+ Hits        18805    18822      +17     
+ Misses       8196     8191       -5     
- Partials     2438     2439       +1     
Flag Coverage Δ
apiserver-unittests 35.32% <0.00%> (-0.03%) ⬇️
core-unittests 56.18% <68.75%> (-0.07%) ⬇️
e2e-multicluster-test 26.51% <68.75%> (+0.13%) ⬆️
e2e-rollout-tests 23.69% <37.50%> (-0.01%) ⬇️
e2etests 31.48% <37.50%> (+0.39%) ⬆️

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

Impacted Files Coverage Δ
apis/core.oam.dev/v1beta1/core_types.go 25.00% <ø> (+25.00%) ⬆️
...troller/core.oam.dev/v1alpha2/application/apply.go 88.55% <100.00%> (-1.08%) ⬇️
...ler/core.oam.dev/v1alpha2/application/generator.go 86.06% <100.00%> (+0.89%) ⬆️
pkg/multicluster/utils.go 66.66% <100.00%> (+0.46%) ⬆️
...tepdefinition/workflowstepdefinition_controller.go 67.02% <0.00%> (-9.58%) ⬇️
...es/policydefinition/policydefinition_controller.go 64.21% <0.00%> (-5.27%) ⬇️
pkg/apiserver/sync/store.go 55.00% <0.00%> (-4.00%) ⬇️
pkg/controller/utils/capability.go 80.30% <0.00%> (+0.44%) ⬆️
.../core/scopes/healthscope/healthscope_controller.go 79.42% <0.00%> (+1.15%) ⬆️
... and 5 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 6761b18...495aced. Read the comment docs.

@fourierr fourierr force-pushed the comp_controlPlaneOnly04 branch 3 times, most recently from d46f4e6 to ed40fd4 Compare April 28, 2022 03:03
@fourierr
Copy link
Member Author

fourierr commented May 5, 2022

The following is an example of how to use controlPlaneOnly.

  • Firstly, hubcpuscaler is defined on the basis of cpusccaler, so that HPA can be deployed to hubcuster
hubcpuscaler: {
	type: "trait"
	annotations: {}
	labels: {
		"ui-hidden": "true"
	}
	description: "Automatically scale the component based on CPU usage."
	attributes: {
		appliesToWorkloads: ["deployments.apps"]
		controlPlaneOnly: true
	}
}

template: {
	outputs: hubcpuscaler: {
		apiVersion: "autoscaling/v1"
		kind:       "HorizontalPodAutoscaler"
		metadata: name: context.name
		spec: {
			scaleTargetRef: {
				apiVersion: parameter.targetAPIVersion
				kind:       parameter.targetKind
				name:       context.name
			}
			minReplicas:                    parameter.min
			maxReplicas:                    parameter.max
			targetCPUUtilizationPercentage: parameter.cpuUtil
		}
	}

	parameter: {
		// +usage=Specify the minimal number of replicas to which the autoscaler can scale down
		min: *1 | int
		// +usage=Specify the maximum number of of replicas to which the autoscaler can scale up
		max: *10 | int
		// +usage=Specify the average CPU utilization, for example, 50 means the CPU usage is 50%
		cpuUtil: *50 | int
		// +usage=Specify the apiVersion of scale target
		targetAPIVersion: *"apps/v1" | string
		// +usage=Specify the kind of scale target
		targetKind: *"Deployment" | string
	}
}
  • Secondly, write application file and apply
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: fourierapp03
  namespace: fourier
spec:
  components:
    - name: fourierapp03-fouriercomponent-01
      type: webservice
      properties:
        image: busybox:latest
        imagePullPolicy: IfNotPresent
        cmd: [ "sleep", "10000" ]
        cpu: "0.1"
        mem: "100Mi"
      traits:
        - type: hubcpuscaler
          properties:
            min: 1
            max: 10
            cpuPercent: 60
        - type: expose
          properties:
            port: [ 80 ]
  policies:
    - name: fourierapp03-topology-01
      type: topology
      properties:
        clusters: [ "kind01" ]
        namespace: fourier01
    - name: fourierapp03-topology-02
      type: topology
      properties:
        clusters: [ "kind02" ]
        namespace: fourier02
  workflow:
    steps:
      - type: deploy
        name: fourierapp03-deploy-01
        properties:
          policies: [ "fourierapp03-topology-01","fourierapp03-topology-02" ]
  • Finally, you can see that HPA was dispatched to cluster local, deployment and service were dispatched to the cluster kind01, kind02 .
  • And if you remove the hubcpuscaler in application, the Custom Resource in local will be GC Simultaneously. as shown below
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: fourierapp03
  namespace: fourier
spec:
  components:
    - name: fourierapp03-fouriercomponent-01
      type: webservice
      properties:
        image: busybox:latest
        imagePullPolicy: IfNotPresent
        cmd: [ "sleep", "10000" ]
        cpu: "0.1"
        mem: "100Mi"
      traits:
        - type: expose
          properties:
            port: [ 80 ]
  policies:
    - name: fourierapp03-topology-01
      type: topology
      properties:
        clusters: [ "kind01" ]
        namespace: fourier01
    - name: fourierapp03-topology-02
      type: topology
      properties:
        clusters: [ "kind02" ]
        namespace: fourier02
  workflow:
    steps:
      - type: deploy
        name: fourierapp03-deploy-01
        properties:
          policies: [ "fourierapp03-topology-01","fourierapp03-topology-02" ]

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 trait with custom resource be dispatched to hubcluster
3 participants