openyurtio / yurt-app-manager

The workload controller manager from NodePool level in OpenYurt cluster
Apache License 2.0
6 stars 1 forks source link

[Feature] UnitedDeployment support patch for pool #12

Closed kadisi closed 3 years ago

kadisi commented 3 years ago

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 commented 3 years ago

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

kadisi commented 3 years ago

@Fei-Guo PTAL

kadisi commented 3 years ago

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

@rambohe-ch done, and add some UTs