Skip to content

Commit

Permalink
Merge pull request #363 from weaveworks/no-hpa
Browse files Browse the repository at this point in the history
Use the specified replicas when scaling up the canary
  • Loading branch information
stefanprodan authored Nov 7, 2019
2 parents 614b7c7 + 0e9fe8a commit 8e582e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 24 additions & 0 deletions pkg/canary/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ func (c *Deployer) Scale(cd *flaggerv1.Canary, replicas int32) error {
return nil
}

func (c *Deployer) ScaleUp(cd *flaggerv1.Canary) error {
targetName := cd.Spec.TargetRef.Name
dep, err := c.KubeClient.AppsV1().Deployments(cd.Namespace).Get(targetName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return fmt.Errorf("deployment %s.%s not found", targetName, cd.Namespace)
}
return fmt.Errorf("deployment %s.%s query error %v", targetName, cd.Namespace, err)
}

replicas := int32p(1)
if dep.Spec.Replicas != nil && *dep.Spec.Replicas > 0 {
replicas = dep.Spec.Replicas
}
depCopy := dep.DeepCopy()
depCopy.Spec.Replicas = replicas

_, err = c.KubeClient.AppsV1().Deployments(dep.Namespace).Update(depCopy)
if err != nil {
return fmt.Errorf("scaling %s.%s to %v failed: %v", depCopy.GetName(), depCopy.Namespace, replicas, err)
}
return nil
}

func (c *Deployer) createPrimaryDeployment(cd *flaggerv1.Canary) (string, map[string]int32, error) {
targetName := cd.Spec.TargetRef.Name
primaryName := fmt.Sprintf("%s-primary", cd.Spec.TargetRef.Name)
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ func (c *Controller) checkCanaryStatus(cd *flaggerv1.Canary, shouldAdvance bool)
c.recordEventInfof(cd, "New revision detected! Scaling up %s.%s", cd.Spec.TargetRef.Name, cd.Namespace)
c.sendNotification(cd, "New revision detected, starting canary analysis.",
true, false)
if err := c.deployer.Scale(cd, 1); err != nil {
if err := c.deployer.ScaleUp(cd); err != nil {
c.recordEventErrorf(cd, "%v", err)
return false
}
Expand Down Expand Up @@ -817,8 +817,8 @@ func (c *Controller) analyseCanary(r *flaggerv1.Canary) bool {
val, err := observerFactory.Client.RunQuery(metric.Query)
if err != nil {
if strings.Contains(err.Error(), "no values found") {
c.recordEventWarningf(r, "Halt advancement no values found for metric %s probably %s.%s is not receiving traffic",
metric.Name, r.Spec.TargetRef.Name, r.Namespace)
c.recordEventWarningf(r, "Halt advancement no values found for custom metric: %s",
metric.Name)
} else {
c.recordEventErrorf(r, "Metrics server %s query failed for %s: %v", metricsServer, metric.Name, err)
}
Expand Down

0 comments on commit 8e582e9

Please sign in to comment.