Skip to content

Commit

Permalink
Merge pull request #174 from beagles/conditions
Browse files Browse the repository at this point in the history
Conditions cleanup
  • Loading branch information
openshift-merge-robot authored Sep 25, 2023
2 parents 1a7b708 + e9d7a1c commit f25ee41
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 16 deletions.
9 changes: 9 additions & 0 deletions api/v1beta1/amphoracontroller_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// HealthManager is the role name for amphora controllers for the Octavia Health Manager services
HealthManager = "healthmanager"
// Housekeeping is the role name for amphora controllers for the Octavia Housekeeping services
Housekeeping = "housekeeping"
// Worker is the role name for amphora controllers for the Octavia Workerservices
Worker = "worker"
)

// OctaviaAmphoraControllerSpec defines common state for all Octavia Amphora Controllers
type OctaviaAmphoraControllerSpec struct {
// +kubebuilder:validation:Required
Expand Down
72 changes: 72 additions & 0 deletions api/v1beta1/conditions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
)

// Octavia Condition Types used by API Objects
const (
// OctaviaAPIReadyCondition Status=True condition which indicates that the OctaviaAPI is configured and operational.
OctaviaAPIReadyCondition condition.Type = "OctaviaAPIReady"

OctaviaHealthManagerReadyCondition condition.Type = "OctaviaHealthManagerReady"

OctaviaHousekeepingReadyCondition condition.Type = "OctaviaHousekeepingReady"

OctaviaWorkerReadyCondition condition.Type = "OctaviaWorkerReady"
)

// Common Messages used by API objects
const (
//
// OctaviaAPIReady condition messages
//
// OctaviaAPIReadyInitMessage
OctaviaAPIReadyInitMessage = "OctaviaAPI not started"

// OctaviaAPIReadyErrorMessage
OctaviaAPIReadyErrorMessage = "OctaviaAPI error occured %s"

//
// OctaviaHealthManagerReady condition messages
//
// OctaviaHealthManagerReadyInitMessage
OctaviaHealthManagerReadyInitMessage = "OctaviaHealthManager is not started"

// OctaviaHealthManagerReadyErrorMessage
OctaviaHealthManagerReadyErrorMessage = "OctaviaHealthManager error occured %s"

//
// OctaviaHousekeepingReady condition messages
//
// OctaviaHousekeepingReadyInitMessage
OctaviaHousekeepingReadyInitMessage = "OctaviaHousekeeping are not started"

// OctaviaAmphoraControllerReadyErrorMessage
OctaviaHousekeepingReadyErrorMessage = "OctaviaHousekeeping error occured %s"

//
// OctaviaWorkerReady condition messages
//
// OctaviaWorkerReadyInitMessage
OctaviaWorkerReadyInitMessage = "OctaviaWorker are not started"

// OctaviaAmphoraControllerReadyErrorMessage
OctaviaWorkerReadyErrorMessage = "OctaviaWorker error occured %s"
)
93 changes: 77 additions & 16 deletions controllers/octavia_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,16 @@ func (r *OctaviaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
cl := condition.CreateList(
condition.UnknownCondition(condition.DBReadyCondition, condition.InitReason, condition.DBReadyInitMessage),
condition.UnknownCondition(condition.DBSyncReadyCondition, condition.InitReason, condition.DBSyncReadyInitMessage),
condition.UnknownCondition(condition.RabbitMqTransportURLReadyCondition, condition.InitReason, condition.RabbitMqTransportURLReadyInitMessage),
condition.UnknownCondition(condition.InputReadyCondition, condition.InitReason, condition.InputReadyInitMessage),
condition.UnknownCondition(condition.ServiceConfigReadyCondition, condition.InitReason, condition.ServiceConfigReadyInitMessage),
condition.UnknownCondition(condition.ServiceAccountReadyCondition, condition.InitReason, condition.ServiceAccountReadyInitMessage),
condition.UnknownCondition(condition.RoleReadyCondition, condition.InitReason, condition.RoleReadyInitMessage),
condition.UnknownCondition(condition.RoleBindingReadyCondition, condition.InitReason, condition.RoleBindingReadyInitMessage),
condition.UnknownCondition(octaviav1.OctaviaAPIReadyCondition, condition.InitReason, octaviav1.OctaviaAPIReadyInitMessage),
amphoraControllerInitCondition(octaviav1.HealthManager),
amphoraControllerInitCondition(octaviav1.Housekeeping),
amphoraControllerInitCondition(octaviav1.Worker),
)

instance.Status.Conditions.Init(&cl)
Expand Down Expand Up @@ -379,10 +384,10 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
transportURL, op, err := r.transportURLCreateOrUpdate(instance)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
condition.RabbitMqTransportURLReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.RabbitMqTransportURLReadyErrorMessage, err.Error()))
return ctrl.Result{}, err
}

Expand Down Expand Up @@ -519,10 +524,10 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
octaviaAPI, op, err := r.apiDeploymentCreateOrUpdate(instance)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.ReadyCondition,
octaviav1.OctaviaAPIReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
"OctaviaAPI error occurred %s",
octaviav1.OctaviaAPIReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
}
Expand All @@ -534,18 +539,20 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
// TODO(beagles): We need to have a way to aggregate conditions from the other services into this
//
instance.Status.OctaviaAPIReadyCount = octaviaAPI.Status.ReadyCount
conditionStatus := octaviaAPI.Status.Conditions.Mirror(condition.ReadyCondition)
conditionStatus := octaviaAPI.Status.Conditions.Mirror(octaviav1.OctaviaAPIReadyCondition)
if conditionStatus != nil {
instance.Status.Conditions.Set(conditionStatus)
} else {
instance.Status.Conditions.MarkTrue(octaviav1.OctaviaAPIReadyCondition, condition.DeploymentReadyMessage)
}

octaviaHousekeeping, op, err := r.amphoraControllerDeploymentCreateOrUpdate(instance, instance.Spec.OctaviaHousekeeping, "housekeeping")
octaviaHousekeeping, op, err := r.amphoraControllerDeploymentCreateOrUpdate(instance, instance.Spec.OctaviaHousekeeping, octaviav1.Housekeeping)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.ReadyCondition,
amphoraControllerReadyCondition(octaviav1.Housekeeping),
condition.ErrorReason,
condition.SeverityWarning,
"OctaviaHousekeeping error occurred %s",
amphoraControllerErrorMessage(octaviav1.Housekeeping),
err.Error()))
return ctrl.Result{}, err
}
Expand All @@ -555,14 +562,20 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
}

instance.Status.OctaviaHousekeepingReadyCount = octaviaHousekeeping.Status.ReadyCount
conditionStatus = octaviaHousekeeping.Status.Conditions.Mirror(amphoraControllerReadyCondition(octaviav1.Housekeeping))
if conditionStatus != nil {
instance.Status.Conditions.Set(conditionStatus)
} else {
instance.Status.Conditions.MarkTrue(amphoraControllerReadyCondition(octaviav1.Housekeeping), condition.DeploymentReadyMessage)
}

octaviaHealthManager, op, err := r.amphoraControllerDeploymentCreateOrUpdate(instance, instance.Spec.OctaviaHealthManager, "healthmanager")
octaviaHealthManager, op, err := r.amphoraControllerDeploymentCreateOrUpdate(instance, instance.Spec.OctaviaHealthManager, octaviav1.HealthManager)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.ReadyCondition,
amphoraControllerReadyCondition(octaviav1.HealthManager),
condition.ErrorReason,
condition.SeverityWarning,
"OctaviaHealthManager error occurred %s",
amphoraControllerErrorMessage(octaviav1.HealthManager),
err.Error()))
return ctrl.Result{}, err
}
Expand All @@ -572,14 +585,20 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
}

instance.Status.OctaviaHealthManagerReadyCount = octaviaHealthManager.Status.ReadyCount
conditionStatus = octaviaHealthManager.Status.Conditions.Mirror(amphoraControllerReadyCondition(octaviav1.HealthManager))
if conditionStatus != nil {
instance.Status.Conditions.Set(conditionStatus)
} else {
instance.Status.Conditions.MarkTrue(amphoraControllerReadyCondition(octaviav1.HealthManager), condition.DeploymentReadyMessage)
}

octaviaWorker, op, err := r.amphoraControllerDeploymentCreateOrUpdate(instance, instance.Spec.OctaviaWorker, "worker")
octaviaWorker, op, err := r.amphoraControllerDeploymentCreateOrUpdate(instance, instance.Spec.OctaviaWorker, octaviav1.Worker)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.ReadyCondition,
amphoraControllerReadyCondition(octaviav1.Worker),
condition.ErrorReason,
condition.SeverityWarning,
"OctaviaWorker error occurred %s",
amphoraControllerErrorMessage(octaviav1.Worker),
err.Error()))
return ctrl.Result{}, err
}
Expand All @@ -589,6 +608,12 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
}

instance.Status.OctaviaWorkerReadyCount = octaviaWorker.Status.ReadyCount
conditionStatus = octaviaWorker.Status.Conditions.Mirror(amphoraControllerReadyCondition(octaviav1.Worker))
if conditionStatus != nil {
instance.Status.Conditions.Set(conditionStatus)
} else {
instance.Status.Conditions.MarkTrue(amphoraControllerReadyCondition(octaviav1.Worker), condition.DeploymentReadyMessage)
}

// create Deployment - end

Expand Down Expand Up @@ -761,3 +786,39 @@ func (r *OctaviaReconciler) amphoraControllerDeploymentCreateOrUpdate(

return deployment, op, err
}

func amphoraControllerReadyCondition(role string) condition.Type {
condMap := map[string]condition.Type{
octaviav1.HealthManager: octaviav1.OctaviaHealthManagerReadyCondition,
octaviav1.Housekeeping: octaviav1.OctaviaHousekeepingReadyCondition,
octaviav1.Worker: octaviav1.OctaviaWorkerReadyCondition,
}
return condMap[role]
}

func amphoraControllerInitCondition(role string) *condition.Condition {
condMap := map[string]*condition.Condition{
octaviav1.HealthManager: condition.UnknownCondition(
amphoraControllerReadyCondition(role),
condition.InitReason,
octaviav1.OctaviaHealthManagerReadyInitMessage),
octaviav1.Housekeeping: condition.UnknownCondition(
amphoraControllerReadyCondition(role),
condition.InitReason,
octaviav1.OctaviaHousekeepingReadyInitMessage),
octaviav1.Worker: condition.UnknownCondition(
amphoraControllerReadyCondition(role),
condition.InitReason,
octaviav1.OctaviaWorkerReadyInitMessage),
}
return condMap[role]
}

func amphoraControllerErrorMessage(role string) string {
condMap := map[string]string{
octaviav1.HealthManager: octaviav1.OctaviaHealthManagerReadyErrorMessage,
octaviav1.Housekeeping: octaviav1.OctaviaHousekeepingReadyErrorMessage,
octaviav1.Worker: octaviav1.OctaviaWorkerReadyErrorMessage,
}
return condMap[role]
}

0 comments on commit f25ee41

Please sign in to comment.