Skip to content

Commit a9270a7

Browse files
committed
Add resyncPeriod and lastSyncTime API fields
Add resyncPeriod to the code generator spec template allowing per-resource configuration of how frequently the controller re-reconciles even when no changes are detected. Add lastSyncTime to the status template to track when the last successful resync occurred. Update the adapter template and interface to expose GetResyncPeriod(), GetLastSyncTime(), and IsImported() methods.
1 parent 3050d71 commit a9270a7

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ __pycache__/
4242

4343
/bundle/
4444
bundle.Dockerfile
45+
46+
# Forge workflow state (do not commit)
47+
.forge/

api/v1alpha1/controller_options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ func (o *ManagedOptions) GetOnDelete() OnDelete {
6363
}
6464
return o.OnDelete
6565
}
66+

cmd/resource-generator/data/adapter.template

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package {{ .NameLower }}
1818

1919
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
2022
orcv1alpha1 "github.com/k-orc/openstack-resource-controller/v2/api/v1alpha1"
2123
"github.com/k-orc/openstack-resource-controller/v2/internal/controllers/generic/interfaces"
2224
)
@@ -54,6 +56,14 @@ func (f adapterT) GetManagedOptions() *orcv1alpha1.ManagedOptions {
5456
return f.Spec.ManagedOptions
5557
}
5658

59+
func (f adapterT) GetResyncPeriod() *metav1.Duration {
60+
return f.Spec.ResyncPeriod
61+
}
62+
63+
func (f adapterT) GetLastSyncTime() *metav1.Time {
64+
return f.Status.LastSyncTime
65+
}
66+
5767
func (f adapterT) GetStatusID() *string {
5868
return f.Status.ID
5969
}
@@ -76,6 +86,10 @@ func (f adapterT) GetImportFilter() *filterT {
7686
return f.Spec.Import.Filter
7787
}
7888

89+
func (f adapterT) IsImported() bool {
90+
return f.GetImportID() != nil || f.GetImportFilter() != nil
91+
}
92+
7993
{{- if not .IsNotNamed }}
8094

8195
// getResourceName returns the name of the OpenStack resource we should use.

cmd/resource-generator/data/api.template

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ type {{ .Name }}Spec struct {
9090
// +optional
9191
ManagedOptions *ManagedOptions `json:"managedOptions,omitempty"`
9292

93+
// resyncPeriod defines how frequently the controller will re-reconcile
94+
// this resource even when no changes have been detected. This overrides
95+
// the global default resync period. The value must be a valid Go duration
96+
// string, e.g. "10m", "1h". Set to "0s" to disable periodic resync for
97+
// this resource.
98+
// +optional
99+
ResyncPeriod *metav1.Duration `json:"resyncPeriod,omitempty"` //nolint:kubeapilinter // metav1.Duration is appropriate for user-facing duration config
100+
93101
// cloudCredentialsRef points to a secret containing OpenStack credentials
94102
// +required
95103
CloudCredentialsRef CloudCredentialsReference `json:"cloudCredentialsRef,omitzero"`
@@ -127,6 +135,13 @@ type {{ .Name }}Status struct {
127135
// resource contains the observed state of the OpenStack resource.
128136
// +optional
129137
Resource *{{ .Name }}ResourceStatus `json:"resource,omitempty"`
138+
139+
// lastSyncTime is the timestamp of the last successful reconciliation
140+
// that fetched state from OpenStack. It is updated each time the
141+
// controller successfully reads the resource state from the OpenStack
142+
// API.
143+
// +optional
144+
LastSyncTime *metav1.Time `json:"lastSyncTime,omitempty"`
130145
{{- if .StatusExtraType }}
131146

132147
{{ .StatusExtraType }} `json:",inline"`

internal/controllers/generic/interfaces/adapter.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,18 @@ type APIObjectAdapter[orcObjectPT any, resourceSpecT any, filterT any] interface
3333

3434
GetManagementPolicy() orcv1alpha1.ManagementPolicy
3535
GetManagedOptions() *orcv1alpha1.ManagedOptions
36+
GetResyncPeriod() *metav1.Duration
37+
GetLastSyncTime() *metav1.Time
3638

3739
GetStatusID() *string
3840
GetResourceSpec() *resourceSpecT
3941
GetImportID() *string
4042
GetImportFilter() *filterT
43+
44+
// IsImported returns true if the resource was imported (rather than created
45+
// by ORC). A resource is considered imported if it has a non-nil importID or
46+
// a non-nil importFilter. This is used to decide how to handle external
47+
// deletion: imported resources result in a terminal error, while ORC-created
48+
// resources are recreated.
49+
IsImported() bool
4150
}

0 commit comments

Comments
 (0)