title | authors | reviewers | creation-date | last-updated | status | ||||
---|---|---|---|---|---|---|---|---|---|
UnitedDeployment |
|
|
2023-04-24 |
2023-04-24 |
implementable |
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
Patch( runtime.RawExtension ) is the specified strategic patch body of this subset, it will be patched to Workload template (StatefulSet|AdvancedStatefulSet|CloneSet|Deployment)
.
# 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
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)
}
- Add the above code snippet to the following files:
advanced_statefulset_adapter.go
,cloneset_adapter.go
,deployment_adapter.go
,statefulset_adapter.go
. - Validate the patch and the workload. Should not broke the fields already set in the template.