Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.8] Bug 2001268: console-operator should report Available=true when at least available replica exists #583

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions pkg/console/operator/sync_v400.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ func (co *consoleOperator) sync_v400(ctx context.Context, controllerContext fact
}
version := os.Getenv("RELEASE_VERSION")
if !deploymentsub.IsAvailableAndUpdated(actualDeployment) {
return errors.New(fmt.Sprintf("Working toward version %s", version))
return errors.New(fmt.Sprintf("Working toward version %s, %v replicas available", version, actualDeployment.Status.AvailableReplicas))
}

if co.versionGetter.GetVersions()["operator"] != version {
co.versionGetter.SetVersion("operator", version)
}
Expand All @@ -152,11 +153,8 @@ func (co *consoleOperator) sync_v400(ctx context.Context, controllerContext fact

statusHandler.AddCondition(status.HandleAvailable(func() (prefix string, reason string, err error) {
prefix = "Deployment"
if !deploymentsub.IsReady(actualDeployment) {
return prefix, "InsufficientReplicas", errors.New(fmt.Sprintf("%v pods available for console deployment", actualDeployment.Status.ReadyReplicas))
}
if !deploymentsub.IsReadyAndUpdated(actualDeployment) {
return prefix, "FailedUpdate", errors.New(fmt.Sprintf("%v replicas ready at version %s", actualDeployment.Status.ReadyReplicas, os.Getenv("RELEASE_VERSION")))
if !deploymentsub.IsAvailable(actualDeployment) {
return prefix, "InsufficientReplicas", errors.New(fmt.Sprintf("%v replicas available for console deployment", actualDeployment.Status.ReadyReplicas))
}
return prefix, "", nil
}()))
Expand Down
25 changes: 4 additions & 21 deletions pkg/console/subresource/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,35 +489,18 @@ func downloadsReadinessProbe() *corev1.Probe {
return probe
}

// for the purpose of availability, ready is when we have at least
// one ready replica
func IsReady(deployment *appsv1.Deployment) bool {
avail := deployment.Status.ReadyReplicas >= 1
func IsAvailable(deployment *appsv1.Deployment) bool {
avail := deployment.Status.AvailableReplicas > 0
if !avail {
klog.V(4).Infof("deployment is not available, expected replicas: %v, ready replicas: %v", deployment.Spec.Replicas, deployment.Status.ReadyReplicas)
klog.V(4).Infof("deployment is not available, expected replicas: %v, available replicas: %v, total replicas: %v", deployment.Spec.Replicas, deployment.Status.AvailableReplicas, deployment.Status.Replicas)
}
return avail
}

func IsReadyAndUpdated(deployment *appsv1.Deployment) bool {
ready := deployment.Status.Replicas == deployment.Status.ReadyReplicas
updated := deployment.Status.Replicas == deployment.Status.UpdatedReplicas
if !ready {
klog.V(4).Infof("deployment is not ready, expected replicas: %v, ready replicas: %v, total replicas: %v", deployment.Spec.Replicas, deployment.Status.ReadyReplicas, deployment.Status.Replicas)
}
if !updated {
klog.V(4).Infof("deployment is not updated, expected replicas: %v, updated replicas: %v, total replicas: %v", deployment.Spec.Replicas, deployment.Status.UpdatedReplicas, deployment.Status.Replicas)
}
return ready && updated
}

func IsAvailableAndUpdated(deployment *appsv1.Deployment) bool {
available := deployment.Status.AvailableReplicas > 0
available := IsAvailable(deployment)
currentGen := deployment.Status.ObservedGeneration >= deployment.Generation
updated := deployment.Status.UpdatedReplicas == deployment.Status.Replicas
if !available {
klog.V(4).Infof("deployment is not available, expected replicas: %v, available replicas: %v, total replicas: %v", deployment.Spec.Replicas, deployment.Status.AvailableReplicas, deployment.Status.Replicas)
}
if !currentGen {
klog.V(4).Infof("deployment is not current, observing generation: %v, generation: %v", deployment.Status.ObservedGeneration, deployment.Generation)
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/console/subresource/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ func Test_consoleVolumeMounts(t *testing.T) {
}
}

func TestIsReady(t *testing.T) {
func TestIsAvailable(t *testing.T) {
type args struct {
deployment *appsv1.Deployment
}
Expand All @@ -925,31 +925,31 @@ func TestIsReady(t *testing.T) {
want bool
}{
{
name: "Test IsReady(): Deployment has one ready replica",
name: "Test IsAvailable(): Deployment has one ready replica",
args: args{
deployment: &appsv1.Deployment{
Status: appsv1.DeploymentStatus{
ReadyReplicas: 1,
AvailableReplicas: 1,
},
},
},
want: true,
}, {
name: "Test IsReady(): Deployment has multiple ready replicas",
name: "Test IsAvailable(): Deployment has multiple ready replicas",
args: args{
deployment: &appsv1.Deployment{
Status: appsv1.DeploymentStatus{
ReadyReplicas: 5,
AvailableReplicas: 5,
},
},
},
want: true,
}, {
name: "Test IsReady(): Deployment has no ready replicas",
name: "Test IsAvailable(): Deployment has no ready replicas",
args: args{
deployment: &appsv1.Deployment{
Status: appsv1.DeploymentStatus{
ReadyReplicas: 0,
AvailableReplicas: 0,
},
},
},
Expand All @@ -958,7 +958,7 @@ func TestIsReady(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsReady(tt.args.deployment); got != tt.want {
if got := IsAvailable(tt.args.deployment); got != tt.want {
t.Errorf("IsReady() = \n%v\n want \n%v", got, tt.want)
}
})
Expand Down