Skip to content

Commit 3c731a5

Browse files
authored
feat: Native DaemonSet Progressive Delivery - Part 2: Advanced DaemonSet Controller (#316)
* feat: Native DaemonSet Progressive Delivery - Part 2: Advanced DaemonSet controller Signed-off-by: Marco Ma <qingjin_ma@163.com> * tiny changes Signed-off-by: Marco Ma <qingjin_ma@163.com> * apply reviews Signed-off-by: Marco Ma <qingjin_ma@163.com> * tiny changes Signed-off-by: Marco Ma <qingjin_ma@163.com> * tiny changes Signed-off-by: Marco Ma <qingjin_ma@163.com> * tiny changes Signed-off-by: Marco Ma <qingjin_ma@163.com> * tiny changes Signed-off-by: Marco Ma <qingjin_ma@163.com> * combine annotations Signed-off-by: Marco Ma <qingjin_ma@163.com> * apply reviews Signed-off-by: Marco Ma <qingjin_ma@163.com> * tiny changes Signed-off-by: Marco Ma <qingjin_ma@163.com> * tiny changes Signed-off-by: Marco Ma <qingjin_ma@163.com> * refactor Signed-off-by: Marco Ma <qingjin_ma@163.com> --------- Signed-off-by: Marco Ma <qingjin_ma@163.com>
1 parent 501d832 commit 3c731a5

File tree

14 files changed

+4789
-101
lines changed

14 files changed

+4789
-101
lines changed

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
rolloutapi "github.com/openkruise/rollouts/api"
4141
br "github.com/openkruise/rollouts/pkg/controller/batchrelease"
4242
"github.com/openkruise/rollouts/pkg/controller/deployment"
43+
"github.com/openkruise/rollouts/pkg/controller/nativedaemonset"
4344
"github.com/openkruise/rollouts/pkg/controller/rollout"
4445
"github.com/openkruise/rollouts/pkg/controller/rollouthistory"
4546
"github.com/openkruise/rollouts/pkg/controller/trafficrouting"
@@ -144,6 +145,10 @@ func main() {
144145
setupLog.Error(err, "unable to create controller", "controller", "advanceddeployment")
145146
os.Exit(1)
146147
}
148+
if err = nativedaemonset.Add(mgr); err != nil {
149+
setupLog.Error(err, "unable to create controller", "controller", "nativedaemonset")
150+
os.Exit(1)
151+
}
147152

148153
//+kubebuilder:scaffold:builder
149154
setupLog.Info("setup webhook")

pkg/controller/batchrelease/control/partitionstyle/nativedaemonset/control.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ func (rc *realController) Initialize(release *v1beta1.BatchRelease) error {
134134
// The actual pod deletion is handled by the advanced-daemonset-controller.
135135
func (rc *realController) UpgradeBatch(ctx *batchcontext.BatchContext) error {
136136
// Check if the DaemonSet already has the partition annotation
137-
currentPartitionStr, hasPartition := rc.object.Annotations[util.DaemonSetPartitionAnnotation]
137+
currentPartitionStr, _ := util.ParseDaemonSetAdvancedControl(rc.object.Annotations)
138138
desiredPartitionStr := ctx.DesiredPartition.String()
139139

140140
// If annotation is missing or doesn't equal desired value, patch the DaemonSet
141-
if !hasPartition || currentPartitionStr != desiredPartitionStr {
141+
if currentPartitionStr != desiredPartitionStr {
142142
klog.Infof("Updating partition annotation for DaemonSet %s/%s: %s -> %s",
143143
rc.object.Namespace, rc.object.Name, currentPartitionStr, desiredPartitionStr)
144144
return rc.patchBatchAnnotations(ctx)
@@ -152,13 +152,14 @@ func (rc *realController) UpgradeBatch(ctx *batchcontext.BatchContext) error {
152152

153153
// patchBatchAnnotations patches the DaemonSet with batch control annotations
154154
func (rc *realController) patchBatchAnnotations(ctx *batchcontext.BatchContext) error {
155+
// Use SetDaemonSetAdvancedControl to set annotations
156+
annotations := make(map[string]string)
157+
util.SetDaemonSetAdvancedControl(annotations, ctx.DesiredPartition.String(), ctx.UpdateRevision)
158+
155159
// Create patch with batch annotations
156160
patch := map[string]interface{}{
157161
"metadata": map[string]interface{}{
158-
"annotations": map[string]interface{}{
159-
util.DaemonSetPartitionAnnotation: ctx.DesiredPartition.String(),
160-
util.DaemonSetBatchRevisionAnnotation: ctx.UpdateRevision,
161-
},
162+
"annotations": annotations,
162163
},
163164
}
164165

@@ -181,20 +182,25 @@ func (rc *realController) Finalize(release *v1beta1.BatchRelease) error {
181182
// if batchPartition == nil, workload should be promoted to use the original update strategy
182183
if release.Spec.ReleasePlan.BatchPartition == nil {
183184
if !(utilfeature.DefaultMutableFeatureGate.Enabled(feature.KeepWorkloadPausedOnRolloutDeletion) && !control.ShouldWaitResume(release)) {
185+
// Read the original update strategy from annotation, default to RollingUpdate if not found
186+
originalStrategyType := apps.RollingUpdateDaemonSetStrategyType
187+
if originalStrategy, exists := rc.object.Annotations[util.DaemonSetOriginalUpdateStrategy]; exists {
188+
originalStrategyType = apps.DaemonSetUpdateStrategyType(originalStrategy)
189+
}
190+
184191
updateStrategy := apps.DaemonSetUpdateStrategy{
185-
Type: apps.RollingUpdateDaemonSetStrategyType,
192+
Type: originalStrategyType,
186193
}
187194
strategyBytes, _ := json.Marshal(updateStrategy)
188195
specBody = fmt.Sprintf(`,"spec":{"updateStrategy":%s}`, string(strategyBytes))
189196
}
190197
}
191198

192-
body := fmt.Sprintf(`{"metadata":{"annotations":{"%s":null,"%s":null,"%s":null,"%s":null,"%s":null}}%s}`,
199+
body := fmt.Sprintf(`{"metadata":{"annotations":{"%s":null,"%s":null,"%s":null,"%s":null}}%s}`,
193200
util.BatchReleaseControlAnnotation,
194-
util.DaemonSetCanaryRevisionAnnotation,
195-
util.DaemonSetStableRevisionAnnotation,
196-
util.DaemonSetPartitionAnnotation,
197-
util.DaemonSetBatchRevisionAnnotation,
201+
util.DaemonSetRevisionAnnotation,
202+
util.DaemonSetAdvancedControlAnnotation,
203+
util.DaemonSetOriginalUpdateStrategy,
198204
specBody)
199205

200206
daemon := util.GetEmptyObjectWithKey(rc.object)

0 commit comments

Comments
 (0)