-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically scale down Deployment after migrating to Rollout
Signed-off-by: balasoiu <[email protected]>
- Loading branch information
Showing
18 changed files
with
1,148 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3330,6 +3330,8 @@ spec: | |
type: string | ||
name: | ||
type: string | ||
scaleDown: | ||
type: string | ||
type: object | ||
type: object | ||
status: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package rollout | ||
|
||
import ( | ||
"context" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func (c *rolloutContext) scaleDeployment(targetScale *int32) error { | ||
deploymentName := c.rollout.Spec.WorkloadRef.Name | ||
namespace := c.rollout.Namespace | ||
deployment, err := c.kubeclientset.AppsV1().Deployments(namespace).Get(context.TODO(), deploymentName, metav1.GetOptions{}) | ||
if err != nil { | ||
c.log.Warnf("Failed to fetch deployment %s: %s", deploymentName, err.Error()) | ||
return err | ||
} | ||
|
||
var newReplicasCount int32 | ||
if *targetScale < 0 { | ||
newReplicasCount = 0 | ||
} else { | ||
newReplicasCount = *targetScale | ||
} | ||
if newReplicasCount == *deployment.Spec.Replicas { | ||
return nil | ||
} | ||
c.log.Infof("Scaling deployment %s to %d replicas", deploymentName, newReplicasCount) | ||
*deployment.Spec.Replicas = newReplicasCount | ||
|
||
_, err = c.kubeclientset.AppsV1().Deployments(namespace).Update(context.TODO(), deployment, metav1.UpdateOptions{}) | ||
if err != nil { | ||
c.log.Warnf("Failed to update deployment %s: %s", deploymentName, err.Error()) | ||
return err | ||
} | ||
return nil | ||
} |
Oops, something went wrong.