Skip to content

Commit

Permalink
Minor enhancements and usability enhancements before publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jstudler authored and henrybear327 committed Aug 30, 2024
1 parent 7fc9dfb commit c854f9f
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 13 deletions.
4 changes: 4 additions & 0 deletions api/v1/ipaddress_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type IpAddressStatus struct {
// Important: Run "make" to regenerate code after modifying this file
IpAddressId int64 `json:"id,omitempty"`

IpAddressUrl string `json:"url,omitempty"`

Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

Expand All @@ -62,6 +64,8 @@ type IpAddressStatus struct {
//+kubebuilder:storageversion
//+kubebuilder:printcolumn:name="IpAddress",type=string,JSONPath=`.spec.ipAddress`
//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
//+kubebuilder:printcolumn:name="ID",type=string,JSONPath=`.status.id`
//+kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.url`
// +kubebuilder:resource:shortName=ip

// IpAddress is the Schema for the ipaddresses API
Expand Down
4 changes: 4 additions & 0 deletions api/v1/prefix_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ type PrefixStatus struct {
// Prefix status: container, active, reserved , deprecated
PrefixId int64 `json:"id,omitempty"`

PrefixUrl string `json:"url,omitempty"`

Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Prefix",type=string,JSONPath=`.spec.prefix`
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
// +kubebuilder:printcolumn:name="ID",type=string,JSONPath=`.status.id`
// +kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.url`
// +kubebuilder:resource:shortName=px
// Prefix is the Schema for the prefixes API
type Prefix struct {
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/netbox.dev_ipaddresses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ spec:
- jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- jsonPath: .status.id
name: ID
type: string
- jsonPath: .status.url
name: URL
type: string
name: v1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -155,6 +161,8 @@ spec:
Important: Run "make" to regenerate code after modifying this file
format: int64
type: integer
url:
type: string
type: object
type: object
served: true
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/netbox.dev_prefixes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ spec:
- jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- jsonPath: .status.id
name: ID
type: string
- jsonPath: .status.url
name: URL
type: string
name: v1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -158,6 +164,8 @@ spec:
Prefix status: container, active, reserved , deprecated
format: int64
type: integer
url:
type: string
type: object
type: object
served: true
Expand Down
5 changes: 2 additions & 3 deletions config/samples/netbox_v1_ipaddress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ metadata:
app.kubernetes.io/managed-by: kustomize
name: ipaddress-sample
spec:
ipAddress: "10.112.131.5/32"
tenant: "Dunder-Mifflin, Inc."
customFields:
example_field: "example value"
description: "some description"
comments: "your comments"
preserveInNetbox: true
ipAddress: "2.0.0.100/32"
5 changes: 2 additions & 3 deletions config/samples/netbox_v1_ipaddressclaim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ metadata:
app.kubernetes.io/managed-by: kustomize
name: ipaddressclaim-sample
spec:
parentPrefix: "10.112.131.0/24"
tenant: "Dunder-Mifflin, Inc."
customFields:
example_field: "example value"
description: "some description"
comments: "your comments"
preserveInNetbox: true
parentPrefix: "2.0.0.0/16"
6 changes: 3 additions & 3 deletions config/samples/netbox_v1_prefix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ metadata:
app.kubernetes.io/managed-by: kustomize
name: prefix-sample
spec:
prefix: "10.112.128.16/28"
tenant: "Dunder-Mifflin, Inc."
site: "DataCenter"
description: "some description"
comments: "your comments"
customFields:
example_field: "example value"
preserveInNetbox: true
prefix: "2.0.0.0/24"
8 changes: 4 additions & 4 deletions config/samples/netbox_v1_prefixclaim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ metadata:
app.kubernetes.io/managed-by: kustomize
name: prefixclaim-sample
spec:
parentPrefix: "10.112.129.0/24"
prefixLength: "/28"
tenant: "Dunder-Mifflin, Inc."
site: "DataCenter"
description: "some description"
comments: "your comments"
customFields:
example_field: "example value"
preserveInNetbox: true
parentPrefix: "2.0.0.0/16"
prefixLength: "/28"
2 changes: 2 additions & 0 deletions internal/controller/ipaddress_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"maps"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -215,6 +216,7 @@ func (r *IpAddressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

// 4. update status conditions
o.Status.IpAddressId = netboxIpAddressModel.ID
o.Status.IpAddressUrl = "https://" + config.GetOperatorConfig().NetboxHost + "/ipam/ip-addresses/" + strconv.FormatInt(netboxIpAddressModel.ID, 10)
err = r.SetConditionAndCreateEvent(ctx, o, netboxv1.ConditionIpaddressReadyTrue, corev1.EventTypeNormal, "")
if err != nil {
return ctrl.Result{}, err
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/prefix_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"maps"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -210,6 +211,7 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr

/* 4. update status conditions */
prefix.Status.PrefixId = netboxPrefixModel.ID
prefix.Status.PrefixUrl = "https://" + config.GetOperatorConfig().NetboxHost + "/ipam/prefixes/" + strconv.FormatInt(netboxPrefixModel.ID, 10)
if err = r.SetConditionAndCreateEvent(ctx, prefix, netboxv1.ConditionPrefixReadyTrue, corev1.EventTypeNormal, ""); err != nil {
return ctrl.Result{}, err
}
Expand Down
4 changes: 4 additions & 0 deletions kind/load-data-job/local-demo-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ INSERT INTO public.extras_customfield_object_types (id, customfield_id, objectty
VALUES (5, 3, 70);

-- misc
INSERT INTO public.tenancy_tenant (created, last_updated, custom_field_data, id, name, slug, description, comments, group_id)
VALUES ('2024-06-14 09:57:11.709344+00', '2024-06-14 09:57:11.709359+00', '{"cust_id": null}', 100, 'MY_TENANT', 'my_tenant', '', '', NULL);
INSERT INTO public.ipam_prefix (created, last_updated, custom_field_data, prefix, status, is_pool, description, role_id, site_id, tenant_id, vlan_id, vrf_id, _children, _depth, mark_utilized, comments)
VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{}', '2.0.0.0/16', 'active', false, '', NULL, NULL, 100, NULL, NULL, 0, 0, false, '');
INSERT INTO public.users_token (id, created, expires, key, write_enabled, description, user_id, allowed_ips, last_used)
VALUES (1, '2024-06-14 12:20:13.317942+00', NULL, '0123456789abcdef0123456789abcdef01234567', true, 'test-token', 1, '{}', NULL);

0 comments on commit c854f9f

Please sign in to comment.