Skip to content

Commit 1e62aa9

Browse files
eshulman2claude
andcommitted
Add resyncPeriod option for drift detection
This change introduces a new `resyncPeriod` field in `ManagedOptions` that enables periodic reconciliation of resources to detect and correct drift from the desired state in OpenStack. Motivation: Resources managed by ORC can drift from their desired state due to external modifications in OpenStack. Without drift detection, these changes go unnoticed until the next spec change triggers reconciliation. The resyncPeriod option allows users to configure periodic checks to detect and remediate such drift automatically. Implementation: - Add `resyncPeriod` field (metav1.Duration) to ManagedOptions API - Add GetResyncPeriod() helper method for safe access with nil handling - Modify shouldReconcile() in the generic controller to check if enough time has passed since the last successful reconciliation - Schedule next resync when periodic resync is enabled and no other reschedule is pending - Update all CRDs, OpenAPI schema, and documentation Usage: ```yaml spec: managedOptions: resyncPeriod: 1h # Reconcile every hour to detect drift ``` If not specified or set to 0, periodic resync is disabled (default behavior unchanged). Closes: #655 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 28038cf commit 1e62aa9

25 files changed

+244
-26
lines changed

api/v1alpha1/controller_options.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ limitations under the License.
1616

1717
package v1alpha1
1818

19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
1923
// +kubebuilder:validation:Enum:=managed;unmanaged
2024
type ManagementPolicy string
2125

@@ -53,6 +57,14 @@ type ManagedOptions struct {
5357
// +kubebuilder:default:=delete
5458
// +optional
5559
OnDelete OnDelete `json:"onDelete,omitempty"`
60+
61+
// resyncPeriod specifies the interval after which a successfully
62+
// reconciled resource will be reconciled again to detect drift from the
63+
// desired state. If not specified or set to 0, periodic resync is disabled
64+
// and the resource will only be reconciled when the spec changes or when
65+
// related resources change.
66+
// +optional
67+
ResyncPeriod *metav1.Duration `json:"resyncPeriod,omitempty"`
5668
}
5769

5870
// GetOnDelete returns the delete behaviour from ManagedOptions. If called on a
@@ -63,3 +75,12 @@ func (o *ManagedOptions) GetOnDelete() OnDelete {
6375
}
6476
return o.OnDelete
6577
}
78+
79+
// GetResyncPeriod returns the resync period from ManagedOptions. If called on a
80+
// nil receiver or if ResyncPeriod is not set, it returns 0 (disabled).
81+
func (o *ManagedOptions) GetResyncPeriod() metav1.Duration {
82+
if o == nil || o.ResyncPeriod == nil {
83+
return metav1.Duration{}
84+
}
85+
return *o.ResyncPeriod
86+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 23 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/models-schema/zz_generated.openapi.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/openstack.k-orc.cloud_domains.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ spec:
125125
- delete
126126
- detach
127127
type: string
128+
resyncPeriod:
129+
description: |-
130+
resyncPeriod specifies the interval after which a successfully
131+
reconciled resource will be reconciled again to detect drift from the
132+
desired state. If not specified or set to 0, periodic resync is disabled
133+
and the resource will only be reconciled when the spec changes or when
134+
related resources change.
135+
type: string
128136
type: object
129137
managementPolicy:
130138
default: managed

config/crd/bases/openstack.k-orc.cloud_flavors.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ spec:
137137
- delete
138138
- detach
139139
type: string
140+
resyncPeriod:
141+
description: |-
142+
resyncPeriod specifies the interval after which a successfully
143+
reconciled resource will be reconciled again to detect drift from the
144+
desired state. If not specified or set to 0, periodic resync is disabled
145+
and the resource will only be reconciled when the spec changes or when
146+
related resources change.
147+
type: string
140148
type: object
141149
managementPolicy:
142150
default: managed

config/crd/bases/openstack.k-orc.cloud_floatingips.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ spec:
209209
- delete
210210
- detach
211211
type: string
212+
resyncPeriod:
213+
description: |-
214+
resyncPeriod specifies the interval after which a successfully
215+
reconciled resource will be reconciled again to detect drift from the
216+
desired state. If not specified or set to 0, periodic resync is disabled
217+
and the resource will only be reconciled when the spec changes or when
218+
related resources change.
219+
type: string
212220
type: object
213221
managementPolicy:
214222
default: managed

config/crd/bases/openstack.k-orc.cloud_groups.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ spec:
126126
- delete
127127
- detach
128128
type: string
129+
resyncPeriod:
130+
description: |-
131+
resyncPeriod specifies the interval after which a successfully
132+
reconciled resource will be reconciled again to detect drift from the
133+
desired state. If not specified or set to 0, periodic resync is disabled
134+
and the resource will only be reconciled when the spec changes or when
135+
related resources change.
136+
type: string
129137
type: object
130138
managementPolicy:
131139
default: managed

config/crd/bases/openstack.k-orc.cloud_images.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ spec:
139139
- delete
140140
- detach
141141
type: string
142+
resyncPeriod:
143+
description: |-
144+
resyncPeriod specifies the interval after which a successfully
145+
reconciled resource will be reconciled again to detect drift from the
146+
desired state. If not specified or set to 0, periodic resync is disabled
147+
and the resource will only be reconciled when the spec changes or when
148+
related resources change.
149+
type: string
142150
type: object
143151
managementPolicy:
144152
default: managed

config/crd/bases/openstack.k-orc.cloud_keypairs.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ spec:
121121
- delete
122122
- detach
123123
type: string
124+
resyncPeriod:
125+
description: |-
126+
resyncPeriod specifies the interval after which a successfully
127+
reconciled resource will be reconciled again to detect drift from the
128+
desired state. If not specified or set to 0, periodic resync is disabled
129+
and the resource will only be reconciled when the spec changes or when
130+
related resources change.
131+
type: string
124132
type: object
125133
managementPolicy:
126134
default: managed

config/crd/bases/openstack.k-orc.cloud_networks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ spec:
195195
- delete
196196
- detach
197197
type: string
198+
resyncPeriod:
199+
description: |-
200+
resyncPeriod specifies the interval after which a successfully
201+
reconciled resource will be reconciled again to detect drift from the
202+
desired state. If not specified or set to 0, periodic resync is disabled
203+
and the resource will only be reconciled when the spec changes or when
204+
related resources change.
205+
type: string
198206
type: object
199207
managementPolicy:
200208
default: managed

0 commit comments

Comments
 (0)