Skip to content

Commit 4942b94

Browse files
committed
feat: add RackGroups to NautobotOperator
1 parent 37fd158 commit 4942b94

5 files changed

Lines changed: 80 additions & 0 deletions

File tree

go/nautobotop/api/v1alpha1/nautobot_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type NautobotSpec struct {
3434
DeviceTypesRef []ConfigMapRef `json:"deviceTypeRef,omitempty"`
3535
LocationTypesRef []ConfigMapRef `json:"locationTypesRef,omitempty"`
3636
LocationRef []ConfigMapRef `json:"locationRef,omitempty"`
37+
RackGroupRef []ConfigMapRef `json:"rackGroupRef,omitempty"`
3738
}
3839

3940
// NautobotStatus defines the observed state of Nautobot.

go/nautobotop/api/v1alpha1/zz_generated.deepcopy.go

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

go/nautobotop/config/crd/bases/sync.rax.io_nautobots.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,35 @@ spec:
176176
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
177177
type: string
178178
type: object
179+
rackGroupRef:
180+
items:
181+
description: ConfigMapRef defines a reference to a specific ConfigMap
182+
properties:
183+
configMapSelector:
184+
description: The name of the ConfigMap resource being referred
185+
to
186+
properties:
187+
key:
188+
description: The key in the ConfigMap data
189+
type: string
190+
name:
191+
description: The name of the ConfigMap
192+
minLength: 1
193+
type: string
194+
namespace:
195+
description: The namespace where the ConfigMap resides
196+
type: string
197+
required:
198+
- name
199+
type: object
200+
name:
201+
description: Name of this config set (logical name)
202+
type: string
203+
required:
204+
- configMapSelector
205+
- name
206+
type: object
207+
type: array
179208
requeueAfter:
180209
default: 600
181210
type: integer

go/nautobotop/helm/crds/clients.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,35 @@ spec:
176176
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
177177
type: string
178178
type: object
179+
rackGroupRef:
180+
items:
181+
description: ConfigMapRef defines a reference to a specific ConfigMap
182+
properties:
183+
configMapSelector:
184+
description: The name of the ConfigMap resource being referred
185+
to
186+
properties:
187+
key:
188+
description: The key in the ConfigMap data
189+
type: string
190+
name:
191+
description: The name of the ConfigMap
192+
minLength: 1
193+
type: string
194+
namespace:
195+
description: The namespace where the ConfigMap resides
196+
type: string
197+
required:
198+
- name
199+
type: object
200+
name:
201+
description: Name of this config set (logical name)
202+
type: string
203+
required:
204+
- configMapSelector
205+
- name
206+
type: object
207+
type: array
179208
requeueAfter:
180209
default: 600
181210
type: integer

go/nautobotop/internal/controller/nautobot_controller.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (r *NautobotReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
8383
resources := []resourceConfig{
8484
{name: "locationType", configRefs: nautobotCR.Spec.LocationTypesRef, syncFunc: r.syncLocationTypes},
8585
{name: "location", configRefs: nautobotCR.Spec.LocationRef, syncFunc: r.syncLocation},
86+
{name: "rackGroup", configRefs: nautobotCR.Spec.RackGroupRef, syncFunc: r.syncRackGroup},
8687
{name: "deviceType", configRefs: nautobotCR.Spec.DeviceTypesRef, syncFunc: r.syncDeviceTypes},
8788
}
8889

@@ -191,6 +192,19 @@ func (r *NautobotReconciler) syncDeviceTypes(ctx context.Context,
191192
return nil
192193
}
193194

195+
func (r *NautobotReconciler) syncRackGroup(ctx context.Context,
196+
nautobotClient *nbClient.NautobotClient,
197+
locationType map[string]string,
198+
) error {
199+
log := logf.FromContext(ctx)
200+
log.Info("syncing rack group", "count", len(locationType))
201+
syncSvc := sync.NewRackGroupSync(nautobotClient)
202+
if err := syncSvc.SyncAll(ctx, locationType); err != nil {
203+
return fmt.Errorf("failed to sync rack group: %w", err)
204+
}
205+
return nil
206+
}
207+
194208
func (r *NautobotReconciler) syncLocation(ctx context.Context,
195209
nautobotClient *nbClient.NautobotClient,
196210
locationType map[string]string,

0 commit comments

Comments
 (0)