Skip to content
Merged
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
rolloutapi "github.com/openkruise/rollouts/api"
br "github.com/openkruise/rollouts/pkg/controller/batchrelease"
"github.com/openkruise/rollouts/pkg/controller/deployment"
"github.com/openkruise/rollouts/pkg/controller/nativedaemonset"
"github.com/openkruise/rollouts/pkg/controller/rollout"
"github.com/openkruise/rollouts/pkg/controller/rollouthistory"
"github.com/openkruise/rollouts/pkg/controller/trafficrouting"
Expand Down Expand Up @@ -144,6 +145,10 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "advanceddeployment")
os.Exit(1)
}
if err = nativedaemonset.Add(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "nativedaemonset")
os.Exit(1)
}

//+kubebuilder:scaffold:builder
setupLog.Info("setup webhook")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ func (rc *realController) Initialize(release *v1beta1.BatchRelease) error {
// The actual pod deletion is handled by the advanced-daemonset-controller.
func (rc *realController) UpgradeBatch(ctx *batchcontext.BatchContext) error {
// Check if the DaemonSet already has the partition annotation
currentPartitionStr, hasPartition := rc.object.Annotations[util.DaemonSetPartitionAnnotation]
currentPartitionStr, _ := util.ParseDaemonSetAdvancedControl(rc.object.Annotations)
desiredPartitionStr := ctx.DesiredPartition.String()

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

// patchBatchAnnotations patches the DaemonSet with batch control annotations
func (rc *realController) patchBatchAnnotations(ctx *batchcontext.BatchContext) error {
// Use SetDaemonSetAdvancedControl to set annotations
annotations := make(map[string]string)
util.SetDaemonSetAdvancedControl(annotations, ctx.DesiredPartition.String(), ctx.UpdateRevision)

// Create patch with batch annotations
patch := map[string]interface{}{
"metadata": map[string]interface{}{
"annotations": map[string]interface{}{
util.DaemonSetPartitionAnnotation: ctx.DesiredPartition.String(),
util.DaemonSetBatchRevisionAnnotation: ctx.UpdateRevision,
},
"annotations": annotations,
},
}

Expand All @@ -181,20 +182,25 @@ func (rc *realController) Finalize(release *v1beta1.BatchRelease) error {
// if batchPartition == nil, workload should be promoted to use the original update strategy
if release.Spec.ReleasePlan.BatchPartition == nil {
if !(utilfeature.DefaultMutableFeatureGate.Enabled(feature.KeepWorkloadPausedOnRolloutDeletion) && !control.ShouldWaitResume(release)) {
// Read the original update strategy from annotation, default to RollingUpdate if not found
originalStrategyType := apps.RollingUpdateDaemonSetStrategyType
if originalStrategy, exists := rc.object.Annotations[util.DaemonSetOriginalUpdateStrategy]; exists {
originalStrategyType = apps.DaemonSetUpdateStrategyType(originalStrategy)
}

updateStrategy := apps.DaemonSetUpdateStrategy{
Type: apps.RollingUpdateDaemonSetStrategyType,
Type: originalStrategyType,
}
strategyBytes, _ := json.Marshal(updateStrategy)
specBody = fmt.Sprintf(`,"spec":{"updateStrategy":%s}`, string(strategyBytes))
}
}

body := fmt.Sprintf(`{"metadata":{"annotations":{"%s":null,"%s":null,"%s":null,"%s":null,"%s":null}}%s}`,
body := fmt.Sprintf(`{"metadata":{"annotations":{"%s":null,"%s":null,"%s":null,"%s":null}}%s}`,
util.BatchReleaseControlAnnotation,
util.DaemonSetCanaryRevisionAnnotation,
util.DaemonSetStableRevisionAnnotation,
util.DaemonSetPartitionAnnotation,
util.DaemonSetBatchRevisionAnnotation,
util.DaemonSetRevisionAnnotation,
util.DaemonSetAdvancedControlAnnotation,
util.DaemonSetOriginalUpdateStrategy,
specBody)

daemon := util.GetEmptyObjectWithKey(rc.object)
Expand Down
Loading
Loading