Skip to content

Commit

Permalink
fix(canary): ensure canary objects are recycled post-release instead …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
zoumo authored Mar 26, 2024
1 parent 96ef83d commit d747282
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pkg/controllers/rolloutrun/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"

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

func (c *CanaryReleaseControl) getCanaryName(stableName string) string {
return stableName + "-canary"
}

func (c *CanaryReleaseControl) getCanaryObject(cluster, namespace, name string) (client.Object, error) {
if strings.HasSuffix(name, "-canary") {
return nil, fmt.Errorf("input name should not end with -canary, got=%s", name)
}
canaryName := c.getCanaryName(name)
canaryObj := c.workload.NewObject()
err := c.client.Get(
clusterinfo.WithCluster(context.TODO(), cluster),
client.ObjectKey{Namespace: namespace, Name: name},
client.ObjectKey{Namespace: namespace, Name: canaryName},
canaryObj,
)
return canaryObj, err
}

func (c *CanaryReleaseControl) canaryObject(stable *workload.Info) (client.Object, bool, error) {
// retrieve canary object
canaryName := stable.Name + "-canary"
canaryObj, err := c.getCanaryObject(stable.ClusterName, stable.Namespace, canaryName)
canaryObj, err := c.getCanaryObject(stable.ClusterName, stable.Namespace, stable.Name)
if client.IgnoreNotFound(err) != nil {
return nil, false, err
}
Expand All @@ -252,7 +260,7 @@ func (c *CanaryReleaseControl) canaryObject(stable *workload.Info) (client.Objec
canaryObj.SetFinalizers(nil)
canaryObj.SetManagedFields(nil)
// set canary metadata
canaryObj.SetName(canaryName)
canaryObj.SetName(c.getCanaryName(stable.Name))
}

return canaryObj, found, nil
Expand Down

0 comments on commit d747282

Please sign in to comment.