From c854f9fee79abc32c9d5d354e57d10e9615065e4 Mon Sep 17 00:00:00 2001 From: Joel Studler Date: Thu, 29 Aug 2024 14:30:57 +0000 Subject: [PATCH] Minor enhancements and usability enhancements before publishing --- api/v1/ipaddress_types.go | 4 ++++ api/v1/prefix_types.go | 4 ++++ config/crd/bases/netbox.dev_ipaddresses.yaml | 8 ++++++++ config/crd/bases/netbox.dev_prefixes.yaml | 8 ++++++++ config/samples/netbox_v1_ipaddress.yaml | 5 ++--- config/samples/netbox_v1_ipaddressclaim.yaml | 5 ++--- config/samples/netbox_v1_prefix.yaml | 6 +++--- config/samples/netbox_v1_prefixclaim.yaml | 8 ++++---- internal/controller/ipaddress_controller.go | 2 ++ internal/controller/prefix_controller.go | 2 ++ kind/load-data-job/local-demo-data.sql | 4 ++++ 11 files changed, 43 insertions(+), 13 deletions(-) diff --git a/api/v1/ipaddress_types.go b/api/v1/ipaddress_types.go index f0706195..f939fe0e 100644 --- a/api/v1/ipaddress_types.go +++ b/api/v1/ipaddress_types.go @@ -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"` } @@ -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 diff --git a/api/v1/prefix_types.go b/api/v1/prefix_types.go index d6c15d5e..9222bbae 100644 --- a/api/v1/prefix_types.go +++ b/api/v1/prefix_types.go @@ -57,6 +57,8 @@ 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"` } @@ -64,6 +66,8 @@ type PrefixStatus struct { // +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 { diff --git a/config/crd/bases/netbox.dev_ipaddresses.yaml b/config/crd/bases/netbox.dev_ipaddresses.yaml index c7acb09e..844cf85e 100644 --- a/config/crd/bases/netbox.dev_ipaddresses.yaml +++ b/config/crd/bases/netbox.dev_ipaddresses.yaml @@ -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: @@ -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 diff --git a/config/crd/bases/netbox.dev_prefixes.yaml b/config/crd/bases/netbox.dev_prefixes.yaml index de2550af..b61097ff 100644 --- a/config/crd/bases/netbox.dev_prefixes.yaml +++ b/config/crd/bases/netbox.dev_prefixes.yaml @@ -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: @@ -158,6 +164,8 @@ spec: Prefix status: container, active, reserved , deprecated format: int64 type: integer + url: + type: string type: object type: object served: true diff --git a/config/samples/netbox_v1_ipaddress.yaml b/config/samples/netbox_v1_ipaddress.yaml index cf9c8da7..3a5935c1 100644 --- a/config/samples/netbox_v1_ipaddress.yaml +++ b/config/samples/netbox_v1_ipaddress.yaml @@ -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" diff --git a/config/samples/netbox_v1_ipaddressclaim.yaml b/config/samples/netbox_v1_ipaddressclaim.yaml index 5ee50f9a..b067c558 100644 --- a/config/samples/netbox_v1_ipaddressclaim.yaml +++ b/config/samples/netbox_v1_ipaddressclaim.yaml @@ -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" diff --git a/config/samples/netbox_v1_prefix.yaml b/config/samples/netbox_v1_prefix.yaml index 1b219245..3a70aaa9 100644 --- a/config/samples/netbox_v1_prefix.yaml +++ b/config/samples/netbox_v1_prefix.yaml @@ -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" diff --git a/config/samples/netbox_v1_prefixclaim.yaml b/config/samples/netbox_v1_prefixclaim.yaml index 209c27c2..7bf2dd4a 100644 --- a/config/samples/netbox_v1_prefixclaim.yaml +++ b/config/samples/netbox_v1_prefixclaim.yaml @@ -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" diff --git a/internal/controller/ipaddress_controller.go b/internal/controller/ipaddress_controller.go index 0eff0eaf..b3ec64a2 100644 --- a/internal/controller/ipaddress_controller.go +++ b/internal/controller/ipaddress_controller.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "maps" + "strconv" "strings" "time" @@ -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 diff --git a/internal/controller/prefix_controller.go b/internal/controller/prefix_controller.go index f892f42c..bf72bd86 100644 --- a/internal/controller/prefix_controller.go +++ b/internal/controller/prefix_controller.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "maps" + "strconv" "strings" "time" @@ -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 } diff --git a/kind/load-data-job/local-demo-data.sql b/kind/load-data-job/local-demo-data.sql index eba1a2b8..51c9bdb5 100644 --- a/kind/load-data-job/local-demo-data.sql +++ b/kind/load-data-job/local-demo-data.sql @@ -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);