Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

[Feature] UnitedDeployment support patch for pool #12

Merged
merged 3 commits into from
Mar 24, 2021

Conversation

kadisi
Copy link
Member

@kadisi kadisi commented Mar 22, 2021

this pr let unitedDeployment support patch for pool.

ref issue 242

for Pool Struct , add new field Patches :

// Pool defines the detail of a pool.
type Pool struct {
	// Indicates pool name as a DNS_LABEL, which will be used to generate
	// pool workload name prefix in the format '<deployment-name>-<pool-name>-'.
	// Name should be unique between all of the pools under one UnitedDeployment.
	// Name is NodePool Name
	Name string `json:"name"`

	// Indicates the node selector to form the pool. Depending on the node selector,
	// pods provisioned could be distributed across multiple groups of nodes.
	// A pool's nodeSelectorTerm is not allowed to be updated.
	// +optional
	NodeSelectorTerm corev1.NodeSelectorTerm `json:"nodeSelectorTerm,omitempty"`

	// Indicates the tolerations the pods under this pool have.
	// A pool's tolerations is not allowed to be updated.
	// +optional
	Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

	// Indicates the number of the pod to be created under this pool.
	// +required
	Replicas *int32 `json:"replicas,omitempty"`

	// Indicates the patches for the templateSpec
	// Now support strategic merge path :https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/#notes-on-the-strategic-merge-patch
	// +optional
	Patches *runtime.RawExtension `json:"patches,omitempty"`
}

User can use this Patches to apply workloadTemplate.DeploymentTemplate or workloadTemplate.StatefulSetTemplate configuration. and now only support strategic merge path.

For the creation process, workload inherits the workloadTemplate configuration. If Patches are found in the Pool, it applies the workloadTemplate using the strategic merge path. It also saves the patches configuration in the annotation. Please review these documents in detail:

pkg/yurtappmanager/controller/uniteddeployment/adapter/deployment_adapter.go ApplyPoolTemplate
pkg/yurtappmanager/controller/uniteddeployment/adapter/statefulset_adapter.go ApplyPoolTemplate

For the update process, the controller determines whether the annotation patches configuration in the workload matches the pool patches configuration. If not, trigger an update operation.

this is an example:

apiVersion: apps.openyurt.io/v1alpha1
kind: UnitedDeployment
metadata:
  name: deploy
  namespace: default
spec:
  selector:
    matchLabels:
      app: deploy
  workloadTemplate:
    deploymentTemplate:
      metadata:
        labels:
          app: deploy
      spec:
        selector:
          matchLabels:
            app: deploy
        template:
          metadata:
            labels:
              app: deploy
          spec:
            containers:
            - image: nginx:1.19.3
              imagePullPolicy: Always
              name: nginx
  topology:
    pools:
    - name: cloud
      nodeSelectorTerm:
        matchExpressions:
        - key: apps.openyurt.io/uniteddeployment
          operator: In
          values:
          - cloud
      patch:
        spec:
          template:
            spec:
              containers:
              - image: nginx:1.18.0
                name: nginx
      replicas: 1

add an patch field for pool

cc @Fei-Guo @huangyuqi @charleszheng44

@rambohe-ch
Copy link
Member

@kadisi Would you make up an example that uses the patch field?

Copy link
Member

@Fei-Guo Fei-Guo left a comment

Choose a reason for hiding this comment

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

As a best practice, please update the copyright year to 2021 for all the files that you have touched in the PR.

I think you need to add some UTs to test the merge functionality.

Copy link
Member Author

@kadisi kadisi left a comment

Choose a reason for hiding this comment

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

done

@kadisi
Copy link
Member Author

kadisi commented Mar 23, 2021

@Fei-Guo PTAL

@kadisi
Copy link
Member Author

kadisi commented Mar 23, 2021

@kadisi Would you make up an example that uses the patch field?

@rambohe-ch done, and add some UTs

Copy link
Member

@Fei-Guo Fei-Guo left a comment

Choose a reason for hiding this comment

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

Overall LG. Nits

@Fei-Guo Fei-Guo merged commit 8207677 into openyurtio:master Mar 24, 2021
@kadisi kadisi deleted the out_ud_patch branch March 25, 2021 03:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants