Skip to content

Commit 1db80df

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 1db80df

26 files changed

Lines changed: 279 additions & 26 deletions

api/v1alpha1/controller_options.go

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

1717
package v1alpha1
1818

19+
import (
20+
"time"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
)
24+
1925
// +kubebuilder:validation:Enum:=managed;unmanaged
2026
type ManagementPolicy string
2127

@@ -53,6 +59,14 @@ type ManagedOptions struct {
5359
// +kubebuilder:default:=delete
5460
// +optional
5561
OnDelete OnDelete `json:"onDelete,omitempty"`
62+
63+
// resyncPeriod specifies the interval after which a successfully
64+
// reconciled resource will be reconciled again to detect drift from the
65+
// desired state. Set to 0 to disable periodic resync. If not specified,
66+
// the default is 10 hours.
67+
// +kubebuilder:default:="10h"
68+
// +optional
69+
ResyncPeriod *metav1.Duration `json:"resyncPeriod,omitempty"` //nolint:kubeapilinter
5670
}
5771

5872
// GetOnDelete returns the delete behaviour from ManagedOptions. If called on a
@@ -63,3 +77,15 @@ func (o *ManagedOptions) GetOnDelete() OnDelete {
6377
}
6478
return o.OnDelete
6579
}
80+
81+
// DefaultResyncPeriod is the default interval for periodic resync to detect drift (10 hours).
82+
const DefaultResyncPeriod = 10 * time.Hour
83+
84+
// GetResyncPeriod returns the resync period from ManagedOptions. If called on a
85+
// nil receiver or if ResyncPeriod is not set, it returns the default of 10 hours.
86+
func (o *ManagedOptions) GetResyncPeriod() time.Duration {
87+
if o == nil || o.ResyncPeriod == nil {
88+
return DefaultResyncPeriod
89+
}
90+
return o.ResyncPeriod.Duration
91+
}

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+
default: 10h
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. Set to 0 to disable periodic resync. If not specified,
134+
the default is 10 hours.
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+
default: 10h
142+
description: |-
143+
resyncPeriod specifies the interval after which a successfully
144+
reconciled resource will be reconciled again to detect drift from the
145+
desired state. Set to 0 to disable periodic resync. If not specified,
146+
the default is 10 hours.
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+
default: 10h
214+
description: |-
215+
resyncPeriod specifies the interval after which a successfully
216+
reconciled resource will be reconciled again to detect drift from the
217+
desired state. Set to 0 to disable periodic resync. If not specified,
218+
the default is 10 hours.
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+
default: 10h
131+
description: |-
132+
resyncPeriod specifies the interval after which a successfully
133+
reconciled resource will be reconciled again to detect drift from the
134+
desired state. Set to 0 to disable periodic resync. If not specified,
135+
the default is 10 hours.
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+
default: 10h
144+
description: |-
145+
resyncPeriod specifies the interval after which a successfully
146+
reconciled resource will be reconciled again to detect drift from the
147+
desired state. Set to 0 to disable periodic resync. If not specified,
148+
the default is 10 hours.
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+
default: 10h
126+
description: |-
127+
resyncPeriod specifies the interval after which a successfully
128+
reconciled resource will be reconciled again to detect drift from the
129+
desired state. Set to 0 to disable periodic resync. If not specified,
130+
the default is 10 hours.
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+
default: 10h
200+
description: |-
201+
resyncPeriod specifies the interval after which a successfully
202+
reconciled resource will be reconciled again to detect drift from the
203+
desired state. Set to 0 to disable periodic resync. If not specified,
204+
the default is 10 hours.
205+
type: string
198206
type: object
199207
managementPolicy:
200208
default: managed

0 commit comments

Comments
 (0)