Skip to content

Commit

Permalink
nlb-guestbook: set right target replicas
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
  • Loading branch information
gyuho committed Jun 12, 2021
1 parent 5b5e7fd commit 3204f61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion client/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ func WaitForDeploymentAvailables(
zap.Int32("available-replicas", dp.Status.AvailableReplicas),
zap.Int32("unavailable-replicas", dp.Status.UnavailableReplicas),
zap.Int32("ready-replicas", dp.Status.ReadyReplicas),
zap.Int32("target-available-replicas", targetAvailableReplicas),
zap.String("condition-last-updated", dpCond.LastUpdateTime.String()),
zap.String("condition-type", string(dpCond.Type)),
zap.String("condition-status", string(dpCond.Status)),
zap.String("condition-reason", dpCond.Reason),
zap.String("condition-message", dpCond.Message),
)
if dpCond.Type == apps_v1.DeploymentReplicaFailure {
return true, fmt.Errorf("Deployment %q status %q", deploymentName, dpCond.Type)
return true, fmt.Errorf("deployment %q status %q", deploymentName, dpCond.Type)
}
if dp.Status.AvailableReplicas >= targetAvailableReplicas {
if dpCond.Type == apps_v1.DeploymentAvailable {
Expand Down
26 changes: 14 additions & 12 deletions k8s-tester/nlb-guestbook/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,18 @@ const (
redisLeaderAppName = "redis-master"
// ref. https://hub.docker.com/_/redis/?tab=tags
// ref. https://gallery.ecr.aws/bitnami/redis
redisLeaderAppImageName = "public.ecr.aws/bitnami/redis:latest"
redisLeaderServiceName = "redis-master" // e..g "Connecting to MASTER redis-master:6379"
redisLeaderRoleName = "master" // TODO: change this to "leader"
redisLeaderAppImageName = "public.ecr.aws/bitnami/redis:latest"
redisLeaderServiceName = "redis-master" // e..g "Connecting to MASTER redis-master:6379"
redisLeaderRoleName = "master" // TODO: change this to "leader"
redisLeaderTargetReplicas int32 = 1

redisFollowerDeploymentName = "redis-follower"
redisFollowerAppName = "redis-slave"
// ref. https://hub.docker.com/_/redis/?tab=tags
redisFollowerAppImageName = "k8s.gcr.io/redis-slave:v2"
redisFollowerServiceName = "redis-slave"
redisFollowerRoleName = "slave" // TODO: change this to "follower"
redisFollowerAppImageName = "k8s.gcr.io/redis-slave:v2"
redisFollowerServiceName = "redis-slave"
redisFollowerRoleName = "slave" // TODO: change this to "follower"
redisFollowerTargetReplicas int32 = 1

deploymentName = "guestbook"
appName = "guestbook"
Expand Down Expand Up @@ -403,7 +405,7 @@ func (ts *tester) createDeploymentRedisLeader() error {
},
},
Spec: apps_v1.DeploymentSpec{
Replicas: int32Ref(1),
Replicas: int32Ref(redisLeaderTargetReplicas),
Selector: &meta_v1.LabelSelector{
MatchLabels: map[string]string{
"app.kubernetes.io/name": redisLabelName,
Expand Down Expand Up @@ -460,7 +462,7 @@ func (ts *tester) createDeploymentRedisLeader() error {
}

func (ts *tester) checkDeploymentRedisLeader() error {
timeout := 7*time.Minute + time.Duration(ts.cfg.DeploymentReplicas)*time.Minute
timeout := 7*time.Minute + time.Duration(redisLeaderTargetReplicas)*time.Minute
ctx, cancel := context.WithTimeout(context.Background(), timeout)
_, err := client.WaitForDeploymentAvailables(
ctx,
Expand All @@ -472,7 +474,7 @@ func (ts *tester) checkDeploymentRedisLeader() error {
20*time.Second,
ts.cfg.Namespace,
redisLeaderDeploymentName,
ts.cfg.DeploymentReplicas,
redisLeaderTargetReplicas,
client.WithQueryFunc(func() {
descArgs := []string{
ts.cfg.Client.Config().KubectlPath,
Expand Down Expand Up @@ -594,7 +596,7 @@ func (ts *tester) createDeploymentRedisFollower() error {
},
},
Spec: apps_v1.DeploymentSpec{
Replicas: int32Ref(2),
Replicas: int32Ref(redisFollowerTargetReplicas),
Selector: &meta_v1.LabelSelector{
MatchLabels: map[string]string{
"app.kubernetes.io/name": redisLabelName,
Expand Down Expand Up @@ -651,7 +653,7 @@ func (ts *tester) createDeploymentRedisFollower() error {
}

func (ts *tester) checkDeploymentRedisFollower() error {
timeout := 7*time.Minute + time.Duration(ts.cfg.DeploymentReplicas)*time.Minute
timeout := 7*time.Minute + time.Duration(redisFollowerTargetReplicas)*time.Minute
ctx, cancel := context.WithTimeout(context.Background(), timeout)
_, err := client.WaitForDeploymentAvailables(
ctx,
Expand All @@ -663,7 +665,7 @@ func (ts *tester) checkDeploymentRedisFollower() error {
20*time.Second,
ts.cfg.Namespace,
redisFollowerDeploymentName,
ts.cfg.DeploymentReplicas,
redisFollowerTargetReplicas,
client.WithQueryFunc(func() {
descArgs := []string{
ts.cfg.Client.Config().KubectlPath,
Expand Down

0 comments on commit 3204f61

Please sign in to comment.