Skip to content

Commit d747282

Browse files
authored
fix(canary): ensure canary objects are recycled post-release instead of deleting stable ones (#67)
This commit corrects the release cleanup logic to recycle canary objects after the canary release phase is complete, rather than erroneously removing stable objects. The updated logic helps maintain service stability and ensures a proper transition from canary to stable environment.
1 parent 96ef83d commit d747282

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pkg/controllers/rolloutrun/control/control.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/json"
2222
"errors"
2323
"fmt"
24+
"strings"
2425

2526
apierrors "k8s.io/apimachinery/pkg/api/errors"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -213,20 +214,27 @@ func (c *CanaryReleaseControl) CreateOrUpdate(ctx context.Context, stable *workl
213214
return controllerutil.OperationResultUpdated, canaryInfo, nil
214215
}
215216

217+
func (c *CanaryReleaseControl) getCanaryName(stableName string) string {
218+
return stableName + "-canary"
219+
}
220+
216221
func (c *CanaryReleaseControl) getCanaryObject(cluster, namespace, name string) (client.Object, error) {
222+
if strings.HasSuffix(name, "-canary") {
223+
return nil, fmt.Errorf("input name should not end with -canary, got=%s", name)
224+
}
225+
canaryName := c.getCanaryName(name)
217226
canaryObj := c.workload.NewObject()
218227
err := c.client.Get(
219228
clusterinfo.WithCluster(context.TODO(), cluster),
220-
client.ObjectKey{Namespace: namespace, Name: name},
229+
client.ObjectKey{Namespace: namespace, Name: canaryName},
221230
canaryObj,
222231
)
223232
return canaryObj, err
224233
}
225234

226235
func (c *CanaryReleaseControl) canaryObject(stable *workload.Info) (client.Object, bool, error) {
227236
// retrieve canary object
228-
canaryName := stable.Name + "-canary"
229-
canaryObj, err := c.getCanaryObject(stable.ClusterName, stable.Namespace, canaryName)
237+
canaryObj, err := c.getCanaryObject(stable.ClusterName, stable.Namespace, stable.Name)
230238
if client.IgnoreNotFound(err) != nil {
231239
return nil, false, err
232240
}
@@ -252,7 +260,7 @@ func (c *CanaryReleaseControl) canaryObject(stable *workload.Info) (client.Objec
252260
canaryObj.SetFinalizers(nil)
253261
canaryObj.SetManagedFields(nil)
254262
// set canary metadata
255-
canaryObj.SetName(canaryName)
263+
canaryObj.SetName(c.getCanaryName(stable.Name))
256264
}
257265

258266
return canaryObj, found, nil

0 commit comments

Comments
 (0)