Skip to content

Commit c471927

Browse files
feat: add IsHub marker for hub/storage version in device resource
Signed-off-by: Alex Lovell-Troy <alex@lovelltroy.org>
1 parent a36de6f commit c471927

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

cmd/fabrica/add.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ func (r *` + resourceName + `) GetUID() string {
372372
}
373373
`
374374

375+
// Add IsHub marker for hub/storage version
376+
if isHub {
377+
content += `
378+
// IsHub marks this as the hub/storage version
379+
func (r *` + resourceName + `) IsHub() {}
380+
`
381+
}
382+
375383
// Add conversion stubs for non-hub versions (spokes)
376384
if !isHub && config != nil {
377385
hubVersion := config.Features.Versioning.StorageVersion

examples/08-api-versioning/apis/infra.example.io/v1/device_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ func (r *Device) GetName() string {
5757
func (r *Device) GetUID() string {
5858
return r.Metadata.UID
5959
}
60+
61+
// IsHub marks this as the hub/storage version
62+
func (r *Device) IsHub() {}

examples/08-api-versioning/apis/infra.example.io/v1alpha1/device_types.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,16 @@ type Device struct {
2121

2222
// DeviceSpec defines the desired state of Device
2323
type DeviceSpec struct {
24-
Name string `json:"name" validate:"required"`
25-
IPAddress string `json:"ipAddress" validate:"required,ip"`
26-
Location string `json:"location,omitempty"`
27-
DeviceType string `json:"deviceType" validate:"oneof=server switch router"`
2824
Description string `json:"description,omitempty" validate:"max=200"`
25+
// Add your spec fields here
2926
}
3027

3128
// DeviceStatus defines the observed state of Device
3229
type DeviceStatus struct {
33-
Phase string `json:"phase,omitempty"`
34-
Message string `json:"message,omitempty"`
35-
Ready bool `json:"ready"`
36-
Health string `json:"health,omitempty" validate:"omitempty,oneof=healthy degraded unhealthy"`
37-
LastChecked string `json:"lastChecked,omitempty"`
30+
Phase string `json:"phase,omitempty"`
31+
Message string `json:"message,omitempty"`
32+
Ready bool `json:"ready"`
33+
// Add your status fields here
3834
}
3935

4036
// Validate implements custom validation logic for Device

examples/08-api-versioning/apis/infra.example.io/v1beta1/device_types.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,16 @@ type Device struct {
2121

2222
// DeviceSpec defines the desired state of Device
2323
type DeviceSpec struct {
24-
Name string `json:"name" validate:"required"`
25-
IPAddress string `json:"ipAddress" validate:"required,ip"`
26-
Location string `json:"location,omitempty"`
27-
DeviceType string `json:"deviceType" validate:"oneof=server switch router"`
2824
Description string `json:"description,omitempty" validate:"max=200"`
25+
// Add your spec fields here
2926
}
3027

3128
// DeviceStatus defines the observed state of Device
3229
type DeviceStatus struct {
33-
Phase string `json:"phase,omitempty"`
34-
Message string `json:"message,omitempty"`
35-
Ready bool `json:"ready"`
36-
Health string `json:"health,omitempty" validate:"omitempty,oneof=healthy degraded unhealthy"`
37-
LastChecked string `json:"lastChecked,omitempty"`
30+
Phase string `json:"phase,omitempty"`
31+
Message string `json:"message,omitempty"`
32+
Ready bool `json:"ready"`
33+
// Add your status fields here
3834
}
3935

4036
// Validate implements custom validation logic for Device

0 commit comments

Comments
 (0)