Skip to content

Latest commit

 

History

History
80 lines (68 loc) · 2.21 KB

20230424-uniteddeployment-patch.md

File metadata and controls

80 lines (68 loc) · 2.21 KB
title authors reviewers creation-date last-updated status
UnitedDeployment
@chengleqi
@Fei-Guo
@furykerry
@FillZpp
2023-04-24
2023-04-24
implementable

UnitedDeployment Patch

Motivation

We need to configure the subsets governed by UnitedDeployment differently to meet various business requirements, such as setting different environment variables or labels for different subsets. Therefore, we need to patch the template to enable different configurations. Issue 811

Proposal

Patch( runtime.RawExtension ) is the specified strategic patch body of this subset, it will be patched to Workload template (StatefulSet|AdvancedStatefulSet|CloneSet|Deployment) .

Samples

# patch metadata:
patch:
  metadata:
    labels:
      xxx-specific-label: xxx
# patch container resources:
patch:
  spec:
    containers:
    - name: main
      resources:
        limits:
          cpu: "2"
          memory: 800Mi
# patch container environments:
patch:
  spec:
    containers:
    - name: main
      env:
      - name: K8S_CONTAINER_NAME
        value: main

Implement

if subSetConfig.Patch.Raw != nil {
		cloneBytes, _ := json.Marshal(set)
		modified, err := strategicpatch.StrategicMergePatch(cloneBytes, subSetConfig.Patch.Raw, &v1beta1.StatefulSet{})
		if err != nil {
			klog.Errorf("failed to merge patch raw %s", subSetConfig.Patch.Raw)
			return err
		}
		patchedSet := &v1beta1.StatefulSet{}
		if err = json.Unmarshal(modified, patchedSet); err != nil {
			klog.Errorf("failed to unmarshal %s to AdvancedStatefulSet", modified)
			return err
		}
		// ... check labels
		patchedSet.DeepCopyInto(set)
		klog.V(2).Infof("AdvancedStatefulSet [%s/%s] was patched successfully: %s", set.Namespace, set.GenerateName, subSetConfig.Patch.Raw)
	}
  1. Add the above code snippet to the following files: advanced_statefulset_adapter.go,cloneset_adapter.go,deployment_adapter.go,statefulset_adapter.go.
  2. Validate the patch and the workload. Should not broke the fields already set in the template.