Skip to content

Commit

Permalink
Re-init conditions each reconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkisaolamb committed Mar 26, 2024
1 parent 3558f06 commit bfd0ff8
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 76 deletions.
2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/openstack-k8s-operators/placement-operator/api
go 1.20

require (
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240313084555-12e3d33d7a2d
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240325204456-ec1f5f6464ee
k8s.io/api v0.28.7
k8s.io/apimachinery v0.28.7
sigs.k8s.io/controller-runtime v0.16.5
Expand Down
3 changes: 1 addition & 2 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.16.0 h1:7q1w9frJDzninhXxjZd+Y/x54XNjG/UlRLIYPZafsPM=
github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240313084555-12e3d33d7a2d h1:9KrN+ILfO+BmTbAoXEfRIJd9Exw79oEHOIhsH31L5Ow=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240313084555-12e3d33d7a2d/go.mod h1:DL+Ts0k+fzgZmx0XxWArIeAmdKuTkPa1I5DThdybfmE=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240325204456-ec1f5f6464ee h1:z92Tw9DJdjLyNLwXEMMgV+9h+VfWRwzn3bsNwXzLI0M=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
145 changes: 75 additions & 70 deletions controllers/placementapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,18 @@ func (r *PlacementAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request
Log.Error(err, "Failed to create lib-common Helper")
return ctrl.Result{}, err
}

// Save a copy of the condtions so that we can restore the LastTransitionTime
// when a condition's state doesn't change.
savedConditions := instance.Status.Conditions.DeepCopy()
// initialize status fields
if err = r.initStatus(ctx, h, instance); err != nil {
return ctrl.Result{}, err
}

// Always patch the instance status when exiting this function so we can persist any changes.
defer func() {
condition.RestoreLastTransitionTimes(&instance.Status.Conditions, savedConditions)
// update the Ready condition based on the sub conditions
if instance.Status.Conditions.AllSubConditionIsTrue() {
instance.Status.Conditions.MarkTrue(
Expand Down Expand Up @@ -752,77 +757,77 @@ func (r *PlacementAPIReconciler) initConditions(
) error {
if instance.Status.Conditions == nil {
instance.Status.Conditions = condition.Conditions{}
// initialize conditions used later as Status=Unknown
cl := condition.CreateList(
condition.UnknownCondition(
condition.DBReadyCondition,
condition.InitReason,
condition.DBReadyInitMessage,
),
condition.UnknownCondition(
condition.DBSyncReadyCondition,
condition.InitReason,
condition.DBSyncReadyInitMessage,
),
condition.UnknownCondition(
condition.ExposeServiceReadyCondition,
condition.InitReason,
condition.ExposeServiceReadyInitMessage,
),
condition.UnknownCondition(
condition.InputReadyCondition,
condition.InitReason,
condition.InputReadyInitMessage,
),
condition.UnknownCondition(
condition.ServiceConfigReadyCondition,
condition.InitReason,
condition.ServiceConfigReadyInitMessage,
),
condition.UnknownCondition(
condition.DeploymentReadyCondition,
condition.InitReason,
condition.DeploymentReadyInitMessage,
),
// right now we have no dedicated KeystoneServiceReadyInitMessage and KeystoneEndpointReadyInitMessage
condition.UnknownCondition(
condition.KeystoneServiceReadyCondition,
condition.InitReason,
"Service registration not started",
),
condition.UnknownCondition(
condition.KeystoneEndpointReadyCondition,
condition.InitReason,
"KeystoneEndpoint not created",
),
condition.UnknownCondition(
condition.NetworkAttachmentsReadyCondition,
condition.InitReason,
condition.NetworkAttachmentsReadyInitMessage,
),
// service account, role, rolebinding conditions
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(
condition.TLSInputReadyCondition,
condition.InitReason,
condition.InputReadyInitMessage),
)

instance.Status.Conditions.Init(&cl)
}
// initialize conditions used later as Status=Unknown
cl := condition.CreateList(
condition.UnknownCondition(
condition.DBReadyCondition,
condition.InitReason,
condition.DBReadyInitMessage,
),
condition.UnknownCondition(
condition.DBSyncReadyCondition,
condition.InitReason,
condition.DBSyncReadyInitMessage,
),
condition.UnknownCondition(
condition.ExposeServiceReadyCondition,
condition.InitReason,
condition.ExposeServiceReadyInitMessage,
),
condition.UnknownCondition(
condition.InputReadyCondition,
condition.InitReason,
condition.InputReadyInitMessage,
),
condition.UnknownCondition(
condition.ServiceConfigReadyCondition,
condition.InitReason,
condition.ServiceConfigReadyInitMessage,
),
condition.UnknownCondition(
condition.DeploymentReadyCondition,
condition.InitReason,
condition.DeploymentReadyInitMessage,
),
// right now we have no dedicated KeystoneServiceReadyInitMessage and KeystoneEndpointReadyInitMessage
condition.UnknownCondition(
condition.KeystoneServiceReadyCondition,
condition.InitReason,
"Service registration not started",
),
condition.UnknownCondition(
condition.KeystoneEndpointReadyCondition,
condition.InitReason,
"KeystoneEndpoint not created",
),
condition.UnknownCondition(
condition.NetworkAttachmentsReadyCondition,
condition.InitReason,
condition.NetworkAttachmentsReadyInitMessage,
),
// service account, role, rolebinding conditions
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(
condition.TLSInputReadyCondition,
condition.InitReason,
condition.InputReadyInitMessage),
)

instance.Status.Conditions.Init(&cl)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/onsi/ginkgo/v2 v2.16.0
github.com/onsi/gomega v1.31.1
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240310093110-b4b2614f40ba
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240313084555-12e3d33d7a2d
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240325204456-ec1f5f6464ee
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240313084555-12e3d33d7a2d
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240308170012-6b04e3e9b9ee
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240216174613-3d349f26e681
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7 h1:rncLxJBpFGqBztyxC
github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7/go.mod h1:ctXNyWanKEjGj8sss1KjjHQ3ENKFm33FFnS5BKaIPh4=
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240310093110-b4b2614f40ba h1:0wfKrQMGwjh/kKTH/UpZGKk91HrnReYieHFG73OC+Vg=
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240310093110-b4b2614f40ba/go.mod h1:gB/IeXuvocAv0yNSf79U1lBHhbx6fdWUB501xFJ0l+A=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240313084555-12e3d33d7a2d h1:9KrN+ILfO+BmTbAoXEfRIJd9Exw79oEHOIhsH31L5Ow=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240313084555-12e3d33d7a2d/go.mod h1:DL+Ts0k+fzgZmx0XxWArIeAmdKuTkPa1I5DThdybfmE=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240325204456-ec1f5f6464ee h1:z92Tw9DJdjLyNLwXEMMgV+9h+VfWRwzn3bsNwXzLI0M=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240325204456-ec1f5f6464ee/go.mod h1:DL+Ts0k+fzgZmx0XxWArIeAmdKuTkPa1I5DThdybfmE=
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240313084555-12e3d33d7a2d h1:2IhoIsgtz+TCO3zI5x1YAgT0AkGRio82lvdSjbbQcIo=
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240313084555-12e3d33d7a2d/go.mod h1:ghnFgNIzj4amS897wEto+L+jYzDSg2cJ6y32RNfFGhk=
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240313084555-12e3d33d7a2d h1:o8KgOTpuphMyhYIG6xIi2AYvmkAEfeex2riWCfZOnyk=
Expand Down

0 comments on commit bfd0ff8

Please sign in to comment.