From 7c5b99764566e0f7f190241e9cbfb9091ddc1714 Mon Sep 17 00:00:00 2001 From: Harrison Katz Date: Tue, 29 Oct 2024 11:09:45 -0400 Subject: [PATCH 1/2] Rename EndpointBinding to BoundEndpoint --- PROJECT | 2 +- ...inding_types.go => boundendpoint_types.go} | 32 +-- .../v1alpha1/zz_generated.deepcopy.go | 38 ++-- .../v1alpha1/kubernetesoperator_types.go | 2 +- cmd/api/main.go | 12 +- .../templates/bindings-forwarder/rbac.yaml | 2 +- ...indings.k8s.ngrok.com_boundendpoints.yaml} | 24 +-- ...rok.k8s.ngrok.com_kubernetesoperators.yaml | 2 +- ...le.yaml => boundendpoint_editor_role.yaml} | 8 +- ...le.yaml => boundendpoint_viewer_role.yaml} | 8 +- helm/ngrok-operator/templates/rbac/role.yaml | 6 +- .../controller-deployment_test.yaml.snap | 20 +- .../__snapshot__/deployment_test.yaml.snap | 4 +- .../__snapshot__/rbac_test.yaml.snap | 2 +- ...troller.go => boundendpoint_controller.go} | 188 +++++++++--------- ...st.go => boundendpoint_controller_test.go} | 32 +-- ...ding_poller.go => boundendpoint_poller.go} | 178 ++++++++--------- ...r_test.go => boundendpoint_poller_test.go} | 104 +++++----- .../bindings/forwarder_controller.go | 16 +- .../ngrokapi/bindingendpoint_aggregator.go | 12 +- .../bindingendpoint_aggregator_test.go | 20 +- 21 files changed, 356 insertions(+), 356 deletions(-) rename api/bindings/v1alpha1/{endpointbinding_types.go => boundendpoint_types.go} (88%) rename helm/ngrok-operator/templates/crds/{bindings.k8s.ngrok.com_endpointbindings.yaml => bindings.k8s.ngrok.com_boundendpoints.yaml} (91%) rename helm/ngrok-operator/templates/rbac/{endpointbinding_editor_role.yaml => boundendpoint_editor_role.yaml} (67%) rename helm/ngrok-operator/templates/rbac/{endpointbinding_viewer_role.yaml => boundendpoint_viewer_role.yaml} (65%) rename internal/controller/bindings/{endpointbinding_controller.go => boundendpoint_controller.go} (67%) rename internal/controller/bindings/{endpointbinding_controller_test.go => boundendpoint_controller_test.go} (81%) rename internal/controller/bindings/{endpointbinding_poller.go => boundendpoint_poller.go} (61%) rename internal/controller/bindings/{endpointbinding_poller_test.go => boundendpoint_poller_test.go} (66%) diff --git a/PROJECT b/PROJECT index 03bcac53..5663d8ef 100644 --- a/PROJECT +++ b/PROJECT @@ -104,7 +104,7 @@ resources: controller: true domain: k8s.ngrok.com group: bindings - kind: EndpointBinding + kind: BoundEndpoint path: github.com/ngrok/ngrok-operator/api/bindings/v1alpha1 version: v1alpha1 - controller: true diff --git a/api/bindings/v1alpha1/endpointbinding_types.go b/api/bindings/v1alpha1/boundendpoint_types.go similarity index 88% rename from api/bindings/v1alpha1/endpointbinding_types.go rename to api/bindings/v1alpha1/boundendpoint_types.go index 6201aa87..25bfd93d 100644 --- a/api/bindings/v1alpha1/endpointbinding_types.go +++ b/api/bindings/v1alpha1/boundendpoint_types.go @@ -32,10 +32,10 @@ import ( // NOTE: Run "make" to regenerate code after modifying this file // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. -// EndpointBindingSpec defines the desired state of EndpointBinding -type EndpointBindingSpec struct { +// BoundEndpointSpec defines the desired state of BoundEndpoint +type BoundEndpointSpec struct { // EndpointURI is the unique identifier - // representing the EndpointBinding + its Endpoints + // representing the BoundEndpoint + its Endpoints // Format: ://.: // // +kubebuilder:validation:Required @@ -59,14 +59,14 @@ type EndpointBindingSpec struct { Target EndpointTarget `json:"target"` } -// EndpointBindingStatus defines the observed state of EndpointBinding -type EndpointBindingStatus struct { - // Endpoints is the list of BindingEndpoints that are created for this EndpointBinding +// BoundEndpointStatus defines the observed state of BoundEndpoint +type BoundEndpointStatus struct { + // Endpoints is the list of BindingEndpoints that are created for this BoundEndpoint // // Note: The collection of Endpoints per Binding are Many-to-One // The uniqueness of each Endpoint is not ID, but rather the 4-tuple - // All Endpoints bound to a EndpointBinding will share the same 4-tuple, statuses, errors, etc... - // this is because EndpointBinding represents 1 Service, yet many Endpoints + // All Endpoints bound to a BoundEndpoint will share the same 4-tuple, statuses, errors, etc... + // this is because BoundEndpoint represents 1 Service, yet many Endpoints // // +kubebuilder:validation:Required Endpoints []BindingEndpoint `json:"endpoints"` @@ -156,29 +156,29 @@ const ( // +kubebuilder:object:root=true // +kubebuilder:subresource:status -// EndpointBinding is the Schema for the endpointbindings API +// BoundEndpoint is the Schema for the boundendpoints API // +kubebuilder:printcolumn:name="URI",type="string",JSONPath=".spec.endpointURI" // +kubebuilder:printcolumn:name="Port",type="string",JSONPath=".spec.port" // +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.endpoints[0].status" // +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="Age" -type EndpointBinding struct { +type BoundEndpoint struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec EndpointBindingSpec `json:"spec,omitempty"` - Status EndpointBindingStatus `json:"status,omitempty"` + Spec BoundEndpointSpec `json:"spec,omitempty"` + Status BoundEndpointStatus `json:"status,omitempty"` } // +kubebuilder:object:root=true // +kubebuilder:rbac:groups=core,resources=services,verbs=get;create;update;delete;list;watch -// EndpointBindingList contains a list of EndpointBinding -type EndpointBindingList struct { +// BoundEndpointList contains a list of BoundEndpoint +type BoundEndpointList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []EndpointBinding `json:"items"` + Items []BoundEndpoint `json:"items"` } func init() { - SchemeBuilder.Register(&EndpointBinding{}, &EndpointBindingList{}) + SchemeBuilder.Register(&BoundEndpoint{}, &BoundEndpointList{}) } diff --git a/api/bindings/v1alpha1/zz_generated.deepcopy.go b/api/bindings/v1alpha1/zz_generated.deepcopy.go index 31a268fe..c0d539be 100644 --- a/api/bindings/v1alpha1/zz_generated.deepcopy.go +++ b/api/bindings/v1alpha1/zz_generated.deepcopy.go @@ -49,7 +49,7 @@ func (in *BindingEndpoint) DeepCopy() *BindingEndpoint { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *EndpointBinding) DeepCopyInto(out *EndpointBinding) { +func (in *BoundEndpoint) DeepCopyInto(out *BoundEndpoint) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -57,18 +57,18 @@ func (in *EndpointBinding) DeepCopyInto(out *EndpointBinding) { in.Status.DeepCopyInto(&out.Status) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointBinding. -func (in *EndpointBinding) DeepCopy() *EndpointBinding { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BoundEndpoint. +func (in *BoundEndpoint) DeepCopy() *BoundEndpoint { if in == nil { return nil } - out := new(EndpointBinding) + out := new(BoundEndpoint) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *EndpointBinding) DeepCopyObject() runtime.Object { +func (in *BoundEndpoint) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -76,31 +76,31 @@ func (in *EndpointBinding) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *EndpointBindingList) DeepCopyInto(out *EndpointBindingList) { +func (in *BoundEndpointList) DeepCopyInto(out *BoundEndpointList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]EndpointBinding, len(*in)) + *out = make([]BoundEndpoint, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointBindingList. -func (in *EndpointBindingList) DeepCopy() *EndpointBindingList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BoundEndpointList. +func (in *BoundEndpointList) DeepCopy() *BoundEndpointList { if in == nil { return nil } - out := new(EndpointBindingList) + out := new(BoundEndpointList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *EndpointBindingList) DeepCopyObject() runtime.Object { +func (in *BoundEndpointList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -108,23 +108,23 @@ func (in *EndpointBindingList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *EndpointBindingSpec) DeepCopyInto(out *EndpointBindingSpec) { +func (in *BoundEndpointSpec) DeepCopyInto(out *BoundEndpointSpec) { *out = *in in.Target.DeepCopyInto(&out.Target) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointBindingSpec. -func (in *EndpointBindingSpec) DeepCopy() *EndpointBindingSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BoundEndpointSpec. +func (in *BoundEndpointSpec) DeepCopy() *BoundEndpointSpec { if in == nil { return nil } - out := new(EndpointBindingSpec) + out := new(BoundEndpointSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *EndpointBindingStatus) DeepCopyInto(out *EndpointBindingStatus) { +func (in *BoundEndpointStatus) DeepCopyInto(out *BoundEndpointStatus) { *out = *in if in.Endpoints != nil { in, out := &in.Endpoints, &out.Endpoints @@ -133,12 +133,12 @@ func (in *EndpointBindingStatus) DeepCopyInto(out *EndpointBindingStatus) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointBindingStatus. -func (in *EndpointBindingStatus) DeepCopy() *EndpointBindingStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BoundEndpointStatus. +func (in *BoundEndpointStatus) DeepCopy() *BoundEndpointStatus { if in == nil { return nil } - out := new(EndpointBindingStatus) + out := new(BoundEndpointStatus) in.DeepCopyInto(out) return out } diff --git a/api/ngrok/v1alpha1/kubernetesoperator_types.go b/api/ngrok/v1alpha1/kubernetesoperator_types.go index 1efa3a25..654d4ad3 100644 --- a/api/ngrok/v1alpha1/kubernetesoperator_types.go +++ b/api/ngrok/v1alpha1/kubernetesoperator_types.go @@ -56,7 +56,7 @@ type KubernetesOperatorBinding struct { // +kubebuilder:validation:Pattern=`^k8s[/][a-zA-Z0-9-]{1,63}$` Name string `json:"name,omitempty"` - // AllowedURLs is a list of URI patterns ([scheme://].) thet determine which EndpointBindings are allowed to be created by the operator + // AllowedURLs is a list of URI patterns ([scheme://].) thet determine which BoundEndpoints are allowed to be created by the operator // TODO(hkatz) We are only implementing `*` for now // Support more patterns in the future, see product spec // +kubebuilder:validation:Required diff --git a/cmd/api/main.go b/cmd/api/main.go index a772a659..e8e3595c 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -472,26 +472,26 @@ func enableGatewayFeatureSet(_ context.Context, _ managerOpts, mgr ctrl.Manager, // enableBindingsFeatureSet enables the Bindings feature set for the operator func enableBindingsFeatureSet(_ context.Context, opts managerOpts, mgr ctrl.Manager, _ *store.Driver, _ ngrokapi.Clientset) error { - // EndpointBindings - if err := (&bindingscontroller.EndpointBindingReconciler{ + // BoundEndpoints + if err := (&bindingscontroller.BoundEndpointReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), - Log: ctrl.Log.WithName("controllers").WithName("EndpointBinding"), + Log: ctrl.Log.WithName("controllers").WithName("BoundEndpoint"), Recorder: mgr.GetEventRecorderFor("bindings-controller"), ClusterDomain: opts.clusterDomain, UpstreamServiceLabelSelector: map[string]string{ "app.kubernetes.io/component": "bindings-forwarder", }, }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "EndpointBinding") + setupLog.Error(err, "unable to create controller", "controller", "BoundEndpoint") os.Exit(1) } // Create a new Runnable that implements Start that the manager can manage running - if err := mgr.Add(&bindingscontroller.EndpointBindingPoller{ + if err := mgr.Add(&bindingscontroller.BoundEndpointPoller{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), - Log: ctrl.Log.WithName("controllers").WithName("EndpointBindingPoller"), + Log: ctrl.Log.WithName("controllers").WithName("BoundEndpointPoller"), Recorder: mgr.GetEventRecorderFor("endpoint-binding-poller"), Namespace: opts.namespace, KubernetesOperatorConfigName: opts.releaseName, diff --git a/helm/ngrok-operator/templates/bindings-forwarder/rbac.yaml b/helm/ngrok-operator/templates/bindings-forwarder/rbac.yaml index a0937b71..d61cd342 100644 --- a/helm/ngrok-operator/templates/bindings-forwarder/rbac.yaml +++ b/helm/ngrok-operator/templates/bindings-forwarder/rbac.yaml @@ -11,7 +11,7 @@ rules: - apiGroups: - bindings.k8s.ngrok.com resources: - - endpointbindings + - boundendpoints verbs: - get - list diff --git a/helm/ngrok-operator/templates/crds/bindings.k8s.ngrok.com_endpointbindings.yaml b/helm/ngrok-operator/templates/crds/bindings.k8s.ngrok.com_boundendpoints.yaml similarity index 91% rename from helm/ngrok-operator/templates/crds/bindings.k8s.ngrok.com_endpointbindings.yaml rename to helm/ngrok-operator/templates/crds/bindings.k8s.ngrok.com_boundendpoints.yaml index 2a6da94a..c043ce78 100644 --- a/helm/ngrok-operator/templates/crds/bindings.k8s.ngrok.com_endpointbindings.yaml +++ b/helm/ngrok-operator/templates/crds/bindings.k8s.ngrok.com_boundendpoints.yaml @@ -4,14 +4,14 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.14.0 - name: endpointbindings.bindings.k8s.ngrok.com + name: boundendpoints.bindings.k8s.ngrok.com spec: group: bindings.k8s.ngrok.com names: - kind: EndpointBinding - listKind: EndpointBindingList - plural: endpointbindings - singular: endpointbinding + kind: BoundEndpoint + listKind: BoundEndpointList + plural: boundendpoints + singular: boundendpoint scope: Namespaced versions: - additionalPrinterColumns: @@ -31,7 +31,7 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: EndpointBinding is the Schema for the endpointbindings API + description: BoundEndpoint is the Schema for the boundendpoints API properties: apiVersion: description: |- @@ -51,12 +51,12 @@ spec: metadata: type: object spec: - description: EndpointBindingSpec defines the desired state of EndpointBinding + description: BoundEndpointSpec defines the desired state of BoundEndpoint properties: endpointURI: description: |- EndpointURI is the unique identifier - representing the EndpointBinding + its Endpoints + representing the BoundEndpoint + its Endpoints Format: ://.: @@ -137,17 +137,17 @@ spec: - target type: object status: - description: EndpointBindingStatus defines the observed state of EndpointBinding + description: BoundEndpointStatus defines the observed state of BoundEndpoint properties: endpoints: description: |- - Endpoints is the list of BindingEndpoints that are created for this EndpointBinding + Endpoints is the list of BindingEndpoints that are created for this BoundEndpoint Note: The collection of Endpoints per Binding are Many-to-One The uniqueness of each Endpoint is not ID, but rather the 4-tuple - All Endpoints bound to a EndpointBinding will share the same 4-tuple, statuses, errors, etc... - this is because EndpointBinding represents 1 Service, yet many Endpoints + All Endpoints bound to a BoundEndpoint will share the same 4-tuple, statuses, errors, etc... + this is because BoundEndpoint represents 1 Service, yet many Endpoints items: description: BindingEndpoint is a reference to an Endpoint object in the ngrok API that is attached to the kubernetes operator binding diff --git a/helm/ngrok-operator/templates/crds/ngrok.k8s.ngrok.com_kubernetesoperators.yaml b/helm/ngrok-operator/templates/crds/ngrok.k8s.ngrok.com_kubernetesoperators.yaml index 0448ccb4..1033a22c 100644 --- a/helm/ngrok-operator/templates/crds/ngrok.k8s.ngrok.com_kubernetesoperators.yaml +++ b/helm/ngrok-operator/templates/crds/ngrok.k8s.ngrok.com_kubernetesoperators.yaml @@ -57,7 +57,7 @@ spec: properties: allowedURLs: description: |- - AllowedURLs is a list of URI patterns ([scheme://].) thet determine which EndpointBindings are allowed to be created by the operator + AllowedURLs is a list of URI patterns ([scheme://].) thet determine which BoundEndpoints are allowed to be created by the operator TODO(hkatz) We are only implementing `*` for now Support more patterns in the future, see product spec items: diff --git a/helm/ngrok-operator/templates/rbac/endpointbinding_editor_role.yaml b/helm/ngrok-operator/templates/rbac/boundendpoint_editor_role.yaml similarity index 67% rename from helm/ngrok-operator/templates/rbac/endpointbinding_editor_role.yaml rename to helm/ngrok-operator/templates/rbac/boundendpoint_editor_role.yaml index 00a97420..29fc645f 100644 --- a/helm/ngrok-operator/templates/rbac/endpointbinding_editor_role.yaml +++ b/helm/ngrok-operator/templates/rbac/boundendpoint_editor_role.yaml @@ -1,16 +1,16 @@ -# permissions for end users to edit endpointbindings +# permissions for end users to edit boundendpoints apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: {{- include "ngrok-operator.labels" . | nindent 4 }} app.kubernetes.io/component: rbac - name: {{ include "ngrok-operator.fullname" . }}-endpointbinding-editor-role + name: {{ include "ngrok-operator.fullname" . }}-boundendpoint-editor-role rules: - apiGroups: - ngrok.k8s.ngrok.com resources: - - endpointbindings + - boundendpoints verbs: - create - delete @@ -22,6 +22,6 @@ rules: - apiGroups: - ngrok.k8s.ngrok.com resources: - - endpointbindings/status + - boundendpoints/status verbs: - get diff --git a/helm/ngrok-operator/templates/rbac/endpointbinding_viewer_role.yaml b/helm/ngrok-operator/templates/rbac/boundendpoint_viewer_role.yaml similarity index 65% rename from helm/ngrok-operator/templates/rbac/endpointbinding_viewer_role.yaml rename to helm/ngrok-operator/templates/rbac/boundendpoint_viewer_role.yaml index 5e2058fe..a4bc23b2 100644 --- a/helm/ngrok-operator/templates/rbac/endpointbinding_viewer_role.yaml +++ b/helm/ngrok-operator/templates/rbac/boundendpoint_viewer_role.yaml @@ -1,16 +1,16 @@ -# permissions for end users to view endpointbindings +# permissions for end users to view boundendpoints apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: {{- include "ngrok-operator.labels" . | nindent 4 }} app.kubernetes.io/component: rbac - name: {{ include "ngrok-operator.fullname" . }}-endpointbinding-viewer-role + name: {{ include "ngrok-operator.fullname" . }}-boundendpoint-viewer-role rules: - apiGroups: - ngrok.k8s.ngrok.com resources: - - endpointbindings + - boundendpoints verbs: - get - list @@ -18,7 +18,7 @@ rules: - apiGroups: - ngrok.k8s.ngrok.com resources: - - endpointbindings/status + - boundendpoints/status verbs: - get diff --git a/helm/ngrok-operator/templates/rbac/role.yaml b/helm/ngrok-operator/templates/rbac/role.yaml index 9b20120d..1d649bd6 100644 --- a/helm/ngrok-operator/templates/rbac/role.yaml +++ b/helm/ngrok-operator/templates/rbac/role.yaml @@ -61,7 +61,7 @@ rules: - apiGroups: - bindings.k8s.ngrok.com resources: - - endpointbindings + - boundendpoints verbs: - create - delete @@ -73,13 +73,13 @@ rules: - apiGroups: - bindings.k8s.ngrok.com resources: - - endpointbindings/finalizers + - boundendpoints/finalizers verbs: - update - apiGroups: - bindings.k8s.ngrok.com resources: - - endpointbindings/status + - boundendpoints/status verbs: - get - patch diff --git a/helm/ngrok-operator/tests/__snapshot__/controller-deployment_test.yaml.snap b/helm/ngrok-operator/tests/__snapshot__/controller-deployment_test.yaml.snap index 9807b3d2..ee065c39 100644 --- a/helm/ngrok-operator/tests/__snapshot__/controller-deployment_test.yaml.snap +++ b/helm/ngrok-operator/tests/__snapshot__/controller-deployment_test.yaml.snap @@ -4,7 +4,7 @@ Should match all-options snapshot: kind: Deployment metadata: annotations: - checksum/controller-role: c445c58cfc9209126660b587935d16070ac21b3b193bffb0a6c86edf2b6dd528 + checksum/controller-role: dcccc2ba4fbf215c5abc9df5ada299467dac3d28e2b7a2b7a95405d91fdb0f02 checksum/rbac: 5d27f1783f54a2ab8e69f9bfce35eef2348fda3f6455526619973781d9549322 labels: app.kubernetes.io/component: controller @@ -26,7 +26,7 @@ Should match all-options snapshot: template: metadata: annotations: - checksum/controller-role: c445c58cfc9209126660b587935d16070ac21b3b193bffb0a6c86edf2b6dd528 + checksum/controller-role: dcccc2ba4fbf215c5abc9df5ada299467dac3d28e2b7a2b7a95405d91fdb0f02 checksum/rbac: 5d27f1783f54a2ab8e69f9bfce35eef2348fda3f6455526619973781d9549322 checksum/secret: 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b prometheus.io/path: /metrics @@ -272,7 +272,7 @@ Should match all-options snapshot: - apiGroups: - bindings.k8s.ngrok.com resources: - - endpointbindings + - boundendpoints verbs: - create - delete @@ -284,13 +284,13 @@ Should match all-options snapshot: - apiGroups: - bindings.k8s.ngrok.com resources: - - endpointbindings/finalizers + - boundendpoints/finalizers verbs: - update - apiGroups: - bindings.k8s.ngrok.com resources: - - endpointbindings/status + - boundendpoints/status verbs: - get - patch @@ -608,7 +608,7 @@ Should match default snapshot: kind: Deployment metadata: annotations: - checksum/controller-role: c445c58cfc9209126660b587935d16070ac21b3b193bffb0a6c86edf2b6dd528 + checksum/controller-role: dcccc2ba4fbf215c5abc9df5ada299467dac3d28e2b7a2b7a95405d91fdb0f02 checksum/rbac: 5d27f1783f54a2ab8e69f9bfce35eef2348fda3f6455526619973781d9549322 labels: app.kubernetes.io/component: controller @@ -630,7 +630,7 @@ Should match default snapshot: template: metadata: annotations: - checksum/controller-role: c445c58cfc9209126660b587935d16070ac21b3b193bffb0a6c86edf2b6dd528 + checksum/controller-role: dcccc2ba4fbf215c5abc9df5ada299467dac3d28e2b7a2b7a95405d91fdb0f02 checksum/rbac: 5d27f1783f54a2ab8e69f9bfce35eef2348fda3f6455526619973781d9549322 checksum/secret: 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b prometheus.io/path: /metrics @@ -863,7 +863,7 @@ Should match default snapshot: - apiGroups: - bindings.k8s.ngrok.com resources: - - endpointbindings + - boundendpoints verbs: - create - delete @@ -875,13 +875,13 @@ Should match default snapshot: - apiGroups: - bindings.k8s.ngrok.com resources: - - endpointbindings/finalizers + - boundendpoints/finalizers verbs: - update - apiGroups: - bindings.k8s.ngrok.com resources: - - endpointbindings/status + - boundendpoints/status verbs: - get - patch diff --git a/helm/ngrok-operator/tests/bindings-forwarder/__snapshot__/deployment_test.yaml.snap b/helm/ngrok-operator/tests/bindings-forwarder/__snapshot__/deployment_test.yaml.snap index 397be2ad..f1cf9295 100644 --- a/helm/ngrok-operator/tests/bindings-forwarder/__snapshot__/deployment_test.yaml.snap +++ b/helm/ngrok-operator/tests/bindings-forwarder/__snapshot__/deployment_test.yaml.snap @@ -4,7 +4,7 @@ Should match snapshot: kind: Deployment metadata: annotations: - checksum/rbac: 2c79f18bfeb71e9ec363f715df607b994ee4a9a5fe3552f6840bf273fc375868 + checksum/rbac: b65bdfec14430fda58dbbf530f639790ab8e9d58926cf0e8405122c80fd4fbba labels: app.kubernetes.io/component: bindings-forwarder app.kubernetes.io/instance: RELEASE-NAME @@ -25,7 +25,7 @@ Should match snapshot: template: metadata: annotations: - checksum/rbac: 2c79f18bfeb71e9ec363f715df607b994ee4a9a5fe3552f6840bf273fc375868 + checksum/rbac: b65bdfec14430fda58dbbf530f639790ab8e9d58926cf0e8405122c80fd4fbba prometheus.io/path: /metrics prometheus.io/port: "8080" prometheus.io/scrape: "true" diff --git a/helm/ngrok-operator/tests/bindings-forwarder/__snapshot__/rbac_test.yaml.snap b/helm/ngrok-operator/tests/bindings-forwarder/__snapshot__/rbac_test.yaml.snap index 5d2c0cf6..f50dd9cf 100644 --- a/helm/ngrok-operator/tests/bindings-forwarder/__snapshot__/rbac_test.yaml.snap +++ b/helm/ngrok-operator/tests/bindings-forwarder/__snapshot__/rbac_test.yaml.snap @@ -9,7 +9,7 @@ Should match snapshot: - apiGroups: - bindings.k8s.ngrok.com resources: - - endpointbindings + - boundendpoints verbs: - get - list diff --git a/internal/controller/bindings/endpointbinding_controller.go b/internal/controller/bindings/boundendpoint_controller.go similarity index 67% rename from internal/controller/bindings/endpointbinding_controller.go rename to internal/controller/bindings/boundendpoint_controller.go index 552d9625..bab5c834 100644 --- a/internal/controller/bindings/endpointbinding_controller.go +++ b/internal/controller/bindings/boundendpoint_controller.go @@ -49,17 +49,17 @@ import ( ) const ( - LabelManagedBy = "app.kubernetes.io/managed-by" - LabelEndpointBindingName = "bindings.k8s.ngrok.com/endpoint-binding-name" - LabelEndpointBindingNamespace = "bindings.k8s.ngrok.com/endpoint-binding-namespace" - LabelEndpointURL = "bindings.k8s.ngrok.com/endpoint-url" + LabelManagedBy = "app.kubernetes.io/managed-by" + LabelBoundEndpointName = "bindings.k8s.ngrok.com/endpoint-binding-name" + LabelBoundEndpointNamespace = "bindings.k8s.ngrok.com/endpoint-binding-namespace" + LabelEndpointURL = "bindings.k8s.ngrok.com/endpoint-url" - // Used for indexing Services by their EndpointBinding owner. Not an actual + // Used for indexing Services by their BoundEndpoint owner. Not an actual // field on the Service object. - EndpointBindingOwnerKey = ".metadata.controller" - // Used for indexing EndpointBindings by their target namespace. Not an actual - // field on the EndpointBinding object. - EndpointBindingTargetNamespacePath = ".spec.targetNamespace" + BoundEndpointOwnerKey = ".metadata.controller" + // Used for indexing BoundEndpoints by their target namespace. Not an actual + // field on the BoundEndpoint object. + BoundEndpointTargetNamespacePath = ".spec.targetNamespace" // TODO(hkatz) ngrok-error-codes NgrokErrorUpstreamServiceCreateFailed = "NGROK_ERR_0001" @@ -68,16 +68,16 @@ const ( ) var ( - commonEndpointBindingLabels = map[string]string{ + commonBoundEndpointLabels = map[string]string{ LabelManagedBy: "ngrok-operator", } ) -// EndpointBindingReconciler reconciles a EndpointBinding object -type EndpointBindingReconciler struct { +// BoundEndpointReconciler reconciles a BoundEndpoint object +type BoundEndpointReconciler struct { client.Client Scheme *runtime.Scheme - controller *controller.BaseController[*bindingsv1alpha1.EndpointBinding] + controller *controller.BaseController[*bindingsv1alpha1.BoundEndpoint] Log logr.Logger Recorder record.EventRecorder @@ -89,18 +89,18 @@ type EndpointBindingReconciler struct { UpstreamServiceLabelSelector map[string]string } -// +kubebuilder:rbac:groups=bindings.k8s.ngrok.com,resources=endpointbindings,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=bindings.k8s.ngrok.com,resources=endpointbindings/status,verbs=get;update;patch -// +kubebuilder:rbac:groups=bindings.k8s.ngrok.com,resources=endpointbindings/finalizers,verbs=update +// +kubebuilder:rbac:groups=bindings.k8s.ngrok.com,resources=boundendpoints,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=bindings.k8s.ngrok.com,resources=boundendpoints/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=bindings.k8s.ngrok.com,resources=boundendpoints/finalizers,verbs=update // SetupWithManager sets up the controller with the Manager. -func (r *EndpointBindingReconciler) SetupWithManager(mgr ctrl.Manager) error { - r.controller = &controller.BaseController[*bindingsv1alpha1.EndpointBinding]{ +func (r *BoundEndpointReconciler) SetupWithManager(mgr ctrl.Manager) error { + r.controller = &controller.BaseController[*bindingsv1alpha1.BoundEndpoint]{ Kube: r.Client, Log: r.Log, Recorder: r.Recorder, - StatusID: func(obj *bindingsv1alpha1.EndpointBinding) string { return obj.Name }, + StatusID: func(obj *bindingsv1alpha1.BoundEndpoint) string { return obj.Name }, Create: r.create, Update: r.update, Delete: r.delete, @@ -109,17 +109,17 @@ func (r *EndpointBindingReconciler) SetupWithManager(mgr ctrl.Manager) error { // create field indexer for to mimic OwnerReferences. We are creating services in other namespaces, // so we can't use OwnerReferences. - err := mgr.GetFieldIndexer().IndexField(context.Background(), &v1.Service{}, EndpointBindingOwnerKey, func(obj client.Object) []string { + err := mgr.GetFieldIndexer().IndexField(context.Background(), &v1.Service{}, BoundEndpointOwnerKey, func(obj client.Object) []string { service := obj.(*v1.Service) svcLabels := service.GetLabels() if svcLabels == nil { return nil // skip, service has no labels } - epbName := svcLabels[LabelEndpointBindingName] - epbNamespace := svcLabels[LabelEndpointBindingNamespace] + epbName := svcLabels[LabelBoundEndpointName] + epbNamespace := svcLabels[LabelBoundEndpointNamespace] if epbName == "" || epbNamespace == "" { - return nil // skip, service is not part of an EndpointBinding + return nil // skip, service is not part of an BoundEndpoint } return []string{fmt.Sprintf("%s/%s", epbNamespace, epbName)} @@ -129,9 +129,9 @@ func (r *EndpointBindingReconciler) SetupWithManager(mgr ctrl.Manager) error { return err } - // Index the EndpointBindings by their target namespace - err = mgr.GetFieldIndexer().IndexField(context.Background(), &bindingsv1alpha1.EndpointBinding{}, EndpointBindingTargetNamespacePath, func(obj client.Object) []string { - binding, ok := obj.(*bindingsv1alpha1.EndpointBinding) + // Index the BoundEndpoints by their target namespace + err = mgr.GetFieldIndexer().IndexField(context.Background(), &bindingsv1alpha1.BoundEndpoint{}, BoundEndpointTargetNamespacePath, func(obj client.Object) []string { + binding, ok := obj.(*bindingsv1alpha1.BoundEndpoint) if !ok || binding == nil { return nil } @@ -144,30 +144,30 @@ func (r *EndpointBindingReconciler) SetupWithManager(mgr ctrl.Manager) error { } return ctrl.NewControllerManagedBy(mgr). - For(&bindingsv1alpha1.EndpointBinding{}). + For(&bindingsv1alpha1.BoundEndpoint{}). Watches( &v1.Service{}, - r.controller.NewEnqueueRequestForMapFunc(r.findEndpointBindingsForService), + r.controller.NewEnqueueRequestForMapFunc(r.findBoundEndpointsForService), ). Watches( &v1.Namespace{}, - r.controller.NewEnqueueRequestForMapFunc(r.findEndpointBindingsForNamespace), + r.controller.NewEnqueueRequestForMapFunc(r.findBoundEndpointsForNamespace), ). Complete(r) } -// Reconcile turns EndpointBindings into 2 Services +// Reconcile turns BoundEndpoints into 2 Services // - ExternalName Target Service in the Target Namespace/Service name pointed at the Upstream Service // - Upstream Service in the ngrok-op namespace pointed at the Pod Forwarders -func (r *EndpointBindingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - cr := &bindingsv1alpha1.EndpointBinding{} +func (r *BoundEndpointReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + cr := &bindingsv1alpha1.BoundEndpoint{} if ctrlErr, err := r.controller.Reconcile(ctx, req, cr); err != nil { return ctrlErr, err } // update ngrok api resource status on upsert if controller.IsUpsert(cr) { - if err := postEndpointBindingUpdateToNgrokAPI(ctx, cr); err != nil { + if err := postBoundEndpointUpdateToNgrokAPI(ctx, cr); err != nil { return controller.CtrlResultForErr(r.controller.ReconcileStatus(ctx, cr, err)) } } @@ -176,8 +176,8 @@ func (r *EndpointBindingReconciler) Reconcile(ctx context.Context, req ctrl.Requ return ctrl.Result{}, nil } -func (r *EndpointBindingReconciler) create(ctx context.Context, cr *bindingsv1alpha1.EndpointBinding) error { - targetService, upstreamService := r.convertEndpointBindingToServices(cr) +func (r *BoundEndpointReconciler) create(ctx context.Context, cr *bindingsv1alpha1.BoundEndpoint) error { + targetService, upstreamService := r.convertBoundEndpointToServices(cr) if err := r.createUpstreamService(ctx, cr, upstreamService); err != nil { return r.controller.ReconcileStatus(ctx, cr, err) @@ -187,31 +187,31 @@ func (r *EndpointBindingReconciler) create(ctx context.Context, cr *bindingsv1al return r.controller.ReconcileStatus(ctx, cr, err) } - if err := r.tryToBindEndpointBinding(ctx, cr); err != nil { + if err := r.tryToBindEndpoint(ctx, cr); err != nil { return r.controller.ReconcileStatus(ctx, cr, err) } return r.controller.ReconcileStatus(ctx, cr, nil) } -// setEndpointsStatus sets the status of every endpoint on endpointBinding to the desired status +// setEndpointsStatus sets the status of every endpoint on boundEndpoint to the desired status // Note: All endpoints share the same status since they are represented by the same resources (Target/Upstream Services) -func setEndpointsStatus(endpointBinding *bindingsv1alpha1.EndpointBinding, desired *bindingsv1alpha1.BindingEndpoint) { - for i := range endpointBinding.Status.Endpoints { - endpoint := &endpointBinding.Status.Endpoints[i] +func setEndpointsStatus(boundEndpoint *bindingsv1alpha1.BoundEndpoint, desired *bindingsv1alpha1.BindingEndpoint) { + for i := range boundEndpoint.Status.Endpoints { + endpoint := &boundEndpoint.Status.Endpoints[i] endpoint.Status = desired.Status endpoint.ErrorCode = desired.ErrorCode endpoint.ErrorMessage = desired.ErrorMessage } } -// postEndpointBindingUpdateToNgrokAPI sends an update to the ngrok API to update the endpoint binding and status fields -func postEndpointBindingUpdateToNgrokAPI(ctx context.Context, endpointBinding *bindingsv1alpha1.EndpointBinding) error { +// postBoundEndpointUpdateToNgrokAPI sends an update to the ngrok API to update the endpoint binding and status fields +func postBoundEndpointUpdateToNgrokAPI(ctx context.Context, boundEndpoint *bindingsv1alpha1.BoundEndpoint) error { // TODO(hkatz) Implement me return nil } -func (r *EndpointBindingReconciler) createTargetService(ctx context.Context, owner *bindingsv1alpha1.EndpointBinding, service *v1.Service) error { +func (r *BoundEndpointReconciler) createTargetService(ctx context.Context, owner *bindingsv1alpha1.BoundEndpoint, service *v1.Service) error { log := ctrl.LoggerFrom(ctx) if err := r.Client.Create(ctx, service); err != nil { @@ -233,7 +233,7 @@ func (r *EndpointBindingReconciler) createTargetService(ctx context.Context, own return nil } -func (r *EndpointBindingReconciler) createUpstreamService(ctx context.Context, owner *bindingsv1alpha1.EndpointBinding, service *v1.Service) error { +func (r *BoundEndpointReconciler) createUpstreamService(ctx context.Context, owner *bindingsv1alpha1.BoundEndpoint, service *v1.Service) error { log := ctrl.LoggerFrom(ctx) if err := r.Client.Create(ctx, service); err != nil { @@ -256,10 +256,10 @@ func (r *EndpointBindingReconciler) createUpstreamService(ctx context.Context, o return nil } -func (r *EndpointBindingReconciler) update(ctx context.Context, cr *bindingsv1alpha1.EndpointBinding) error { +func (r *BoundEndpointReconciler) update(ctx context.Context, cr *bindingsv1alpha1.BoundEndpoint) error { log := ctrl.LoggerFrom(ctx) - desiredTargetService, desiredUpstreamService := r.convertEndpointBindingToServices(cr) + desiredTargetService, desiredUpstreamService := r.convertBoundEndpointToServices(cr) var existingTargetService v1.Service var existingUpstreamService v1.Service @@ -324,7 +324,7 @@ func (r *EndpointBindingReconciler) update(ctx context.Context, cr *bindingsv1al r.Recorder.Event(&existingTargetService, v1.EventTypeNormal, "Updated", "Updated Target Service") } - if err := r.tryToBindEndpointBinding(ctx, cr); err != nil { + if err := r.tryToBindEndpoint(ctx, cr); err != nil { return r.controller.ReconcileStatus(ctx, cr, err) } @@ -332,10 +332,10 @@ func (r *EndpointBindingReconciler) update(ctx context.Context, cr *bindingsv1al return r.controller.ReconcileStatus(ctx, cr, nil) } -func (r *EndpointBindingReconciler) delete(ctx context.Context, cr *bindingsv1alpha1.EndpointBinding) error { +func (r *BoundEndpointReconciler) delete(ctx context.Context, cr *bindingsv1alpha1.BoundEndpoint) error { log := ctrl.LoggerFrom(ctx) - targetService, upstreamService := r.convertEndpointBindingToServices(cr) + targetService, upstreamService := r.convertBoundEndpointToServices(cr) if err := r.Client.Delete(ctx, targetService); err != nil { if client.IgnoreNotFound(err) == nil { return nil @@ -359,20 +359,20 @@ func (r *EndpointBindingReconciler) delete(ctx context.Context, cr *bindingsv1al return nil } -func (r *EndpointBindingReconciler) errResult(op controller.BaseControllerOp, cr *bindingsv1alpha1.EndpointBinding, err error) (ctrl.Result, error) { +func (r *BoundEndpointReconciler) errResult(op controller.BaseControllerOp, cr *bindingsv1alpha1.BoundEndpoint, err error) (ctrl.Result, error) { return ctrl.Result{}, err } -// convertEndpointBindingToServices converts an EndpointBinding into 2 Services: Target(ExternalName) and Upstream(Pod Forwarders) -func (r *EndpointBindingReconciler) convertEndpointBindingToServices(endpointBinding *bindingsv1alpha1.EndpointBinding) (*v1.Service, *v1.Service) { +// convertBoundEndpointToServices converts an BoundEndpoint into 2 Services: Target(ExternalName) and Upstream(Pod Forwarders) +func (r *BoundEndpointReconciler) convertBoundEndpointToServices(boundEndpoint *bindingsv1alpha1.BoundEndpoint) (*v1.Service, *v1.Service) { // Send traffic to any Node in the cluster internalTrafficPolicy := v1.ServiceInternalTrafficPolicyCluster - endpointURL := fmt.Sprintf("%s.%s.%s", endpointBinding.Name, endpointBinding.Namespace, r.ClusterDomain) + endpointURL := fmt.Sprintf("%s.%s.%s", boundEndpoint.Name, boundEndpoint.Namespace, r.ClusterDomain) thisBindingLabels := map[string]string{ - LabelEndpointBindingName: endpointBinding.Name, - LabelEndpointBindingNamespace: endpointBinding.Namespace, + LabelBoundEndpointName: boundEndpoint.Name, + LabelBoundEndpointNamespace: boundEndpoint.Namespace, } // Target Labels in order of increasing precedence @@ -380,19 +380,19 @@ func (r *EndpointBindingReconciler) convertEndpointBindingToServices(endpointBin // 2. User's labels // 3. Our label selectors (endpoint-binding-name, endpoint-binding-namespace) to mimic OwnerReferences targetLabels := util.MergeMaps( - commonEndpointBindingLabels, - endpointBinding.Spec.Target.Metadata.Labels, + commonBoundEndpointLabels, + boundEndpoint.Spec.Target.Metadata.Labels, thisBindingLabels, ) - targetAnnotations := endpointBinding.Spec.Target.Metadata.Annotations + targetAnnotations := boundEndpoint.Spec.Target.Metadata.Annotations // targetService represents the user's configured endpoint binding as a Service // Clients will send requests to this service: ://.: targetService := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: endpointBinding.Spec.Target.Service, - Namespace: endpointBinding.Spec.Target.Namespace, + Name: boundEndpoint.Spec.Target.Service, + Namespace: boundEndpoint.Spec.Target.Namespace, Labels: targetLabels, Annotations: targetAnnotations, }, @@ -403,17 +403,17 @@ func (r *EndpointBindingReconciler) convertEndpointBindingToServices(endpointBin SessionAffinity: v1.ServiceAffinityClientIP, Ports: []v1.ServicePort{ { - Name: endpointBinding.Spec.Scheme, - Protocol: v1.Protocol(endpointBinding.Spec.Target.Protocol), - // Both Port and TargetPort for the Target Service should match the expected Target.Port on the EndpointBinding - Port: endpointBinding.Spec.Target.Port, - TargetPort: intstr.FromInt(int(endpointBinding.Spec.Target.Port)), + Name: boundEndpoint.Spec.Scheme, + Protocol: v1.Protocol(boundEndpoint.Spec.Target.Protocol), + // Both Port and TargetPort for the Target Service should match the expected Target.Port on the BoundEndpoint + Port: boundEndpoint.Spec.Target.Port, + TargetPort: intstr.FromInt(int(boundEndpoint.Spec.Target.Port)), }, }, }, } - upstreamLabels := util.MergeMaps(commonEndpointBindingLabels, thisBindingLabels) + upstreamLabels := util.MergeMaps(commonBoundEndpointLabels, thisBindingLabels) upstreamAnnotations := map[string]string{ // TODO(hkatz) Implement Metadata LabelEndpointURL: endpointURL, @@ -423,8 +423,8 @@ func (r *EndpointBindingReconciler) convertEndpointBindingToServices(endpointBin // This Service will point to the Pod Forwarders' containers on a dedicated allocated port upstreamService := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: endpointBinding.Name, - Namespace: endpointBinding.Namespace, + Name: boundEndpoint.Name, + Namespace: boundEndpoint.Namespace, Labels: upstreamLabels, Annotations: upstreamAnnotations, }, @@ -435,12 +435,12 @@ func (r *EndpointBindingReconciler) convertEndpointBindingToServices(endpointBin Selector: r.UpstreamServiceLabelSelector, Ports: []v1.ServicePort{ { - Name: endpointBinding.Spec.Scheme, - Protocol: v1.Protocol(endpointBinding.Spec.Target.Protocol), + Name: boundEndpoint.Spec.Scheme, + Protocol: v1.Protocol(boundEndpoint.Spec.Target.Protocol), // ExternalName Target Service's port will need to point to the same port on the Upstream Service - Port: endpointBinding.Spec.Target.Port, - // TargetPort is the port within the pod forwarders' containers that is pre-allocated for this EndpointBinding - TargetPort: intstr.FromInt(int(endpointBinding.Spec.Port)), + Port: boundEndpoint.Spec.Target.Port, + // TargetPort is the port within the pod forwarders' containers that is pre-allocated for this BoundEndpoint + TargetPort: intstr.FromInt(int(boundEndpoint.Spec.Port)), }, }, }, @@ -449,24 +449,24 @@ func (r *EndpointBindingReconciler) convertEndpointBindingToServices(endpointBin return targetService, upstreamService } -func (r *EndpointBindingReconciler) findEndpointBindingsForNamespace(ctx context.Context, namespace client.Object) []reconcile.Request { +func (r *BoundEndpointReconciler) findBoundEndpointsForNamespace(ctx context.Context, namespace client.Object) []reconcile.Request { nsName := namespace.GetName() log := ctrl.LoggerFrom(ctx).WithValues("namespace", nsName) log.V(3).Info("Finding endpoint bindings for namespace") - endpointBindings := &bindingsv1alpha1.EndpointBindingList{} + boundEndpoints := &bindingsv1alpha1.BoundEndpointList{} listOpts := &client.ListOptions{ - FieldSelector: fields.OneTermEqualSelector(EndpointBindingTargetNamespacePath, nsName), + FieldSelector: fields.OneTermEqualSelector(BoundEndpointTargetNamespacePath, nsName), } - err := r.Client.List(ctx, endpointBindings, listOpts) + err := r.Client.List(ctx, boundEndpoints, listOpts) if err != nil { log.Error(err, "Failed to list endpoint bindings for namespace") return []reconcile.Request{} } - requests := make([]reconcile.Request, len(endpointBindings.Items)) - for i, binding := range endpointBindings.Items { + requests := make([]reconcile.Request, len(boundEndpoints.Items)) + for i, binding := range boundEndpoints.Items { requests[i] = reconcile.Request{ NamespacedName: types.NamespacedName{ Namespace: binding.Namespace, @@ -481,7 +481,7 @@ func (r *EndpointBindingReconciler) findEndpointBindingsForNamespace(ctx context return requests } -func (r *EndpointBindingReconciler) findEndpointBindingsForService(ctx context.Context, svc client.Object) []reconcile.Request { +func (r *BoundEndpointReconciler) findBoundEndpointsForService(ctx context.Context, svc client.Object) []reconcile.Request { log := ctrl.LoggerFrom(ctx).WithValues("service.name", svc.GetName(), "service.namespace", svc.GetNamespace()) log.V(3).Info("Finding endpoint bindings for service") @@ -491,22 +491,22 @@ func (r *EndpointBindingReconciler) findEndpointBindingsForService(ctx context.C return []reconcile.Request{} } - epbName := svcLabels[LabelEndpointBindingName] - epbNamespace := svcLabels[LabelEndpointBindingNamespace] + epbName := svcLabels[LabelBoundEndpointName] + epbNamespace := svcLabels[LabelBoundEndpointNamespace] if epbName == "" || epbNamespace == "" { - log.V(3).Info("Service is not part of an EndpointBinding") + log.V(3).Info("Service is not part of an BoundEndpoint") return []reconcile.Request{} } - epb := &bindingsv1alpha1.EndpointBinding{} + epb := &bindingsv1alpha1.BoundEndpoint{} err := r.Client.Get(ctx, types.NamespacedName{Namespace: epbNamespace, Name: epbName}, epb) if err != nil { if client.IgnoreNotFound(err) == nil { - log.V(3).Info("EndpointBinding not found") + log.V(3).Info("BoundEndpoint not found") return []reconcile.Request{} } - log.Error(err, "Failed to get EndpointBinding") + log.Error(err, "Failed to get BoundEndpoint") return []reconcile.Request{} } @@ -520,9 +520,9 @@ func (r *EndpointBindingReconciler) findEndpointBindingsForService(ctx context.C } } -// tryToBindEndpointBinding attempts a TCP connection through the provisioned services for the EndpointBinding -func (r *EndpointBindingReconciler) tryToBindEndpointBinding(ctx context.Context, endpointBinding *bindingsv1alpha1.EndpointBinding) error { - log := ctrl.LoggerFrom(ctx).WithValues("uri", endpointBinding.Spec.EndpointURI) +// tryToBindEndpoint attempts a TCP connection through the provisioned services for the BoundEndpoint +func (r *BoundEndpointReconciler) tryToBindEndpoint(ctx context.Context, boundEndpoint *bindingsv1alpha1.BoundEndpoint) error { + log := ctrl.LoggerFrom(ctx).WithValues("uri", boundEndpoint.Spec.EndpointURI) retries := 5 attempt := 0 @@ -539,15 +539,15 @@ func (r *EndpointBindingReconciler) tryToBindEndpointBinding(ctx context.Context time.Sleep(waitDuration) // rely on kube-dns to resolve the targetService's ExternalName - uri, err := url.Parse(endpointBinding.Spec.EndpointURI) + uri, err := url.Parse(boundEndpoint.Spec.EndpointURI) if err != nil { - bindErr = fmt.Errorf("failed to parse EndpointBinding URI %s: %w", endpointBinding.Spec.EndpointURI, err) + bindErr = fmt.Errorf("failed to parse BoundEndpoint URI %s: %w", boundEndpoint.Spec.EndpointURI, err) continue } conn, err := net.DialTimeout("tcp", uri.Host, dialTimeout) if err != nil { - log.Error(err, "Failed to bind EndpointBinding", "attempt", attempt, "retries", retries) + log.Error(err, "Failed to bind BoundEndpoint", "attempt", attempt, "retries", retries) bindErr = err } else { // conn exists, close it @@ -571,7 +571,7 @@ func (r *EndpointBindingReconciler) tryToBindEndpointBinding(ctx context.Context desired = &bindingsv1alpha1.BindingEndpoint{ Status: bindingsv1alpha1.StatusError, ErrorCode: NgrokErrorFailedToBind, - ErrorMessage: fmt.Sprintf("Failed to bind EndpointBinding: %s", bindErr), + ErrorMessage: fmt.Sprintf("Failed to bind BoundEndpoint: %s", bindErr), } } else { // success @@ -584,6 +584,6 @@ func (r *EndpointBindingReconciler) tryToBindEndpointBinding(ctx context.Context } // set status - setEndpointsStatus(endpointBinding, desired) + setEndpointsStatus(boundEndpoint, desired) return bindErr } diff --git a/internal/controller/bindings/endpointbinding_controller_test.go b/internal/controller/bindings/boundendpoint_controller_test.go similarity index 81% rename from internal/controller/bindings/endpointbinding_controller_test.go rename to internal/controller/bindings/boundendpoint_controller_test.go index 12a3ff53..1de1faf5 100644 --- a/internal/controller/bindings/endpointbinding_controller_test.go +++ b/internal/controller/bindings/boundendpoint_controller_test.go @@ -32,26 +32,26 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func Test_EndpointBinding(t *testing.T) { +func Test_BoundEndpoint(t *testing.T) { assert := assert.New(t) // TODO(hkatz) implement me assert.True(true) } -func Test_convertEndpointBindingToServices(t *testing.T) { +func Test_convertBoundEndpointToServices(t *testing.T) { assert := assert.New(t) - controller := &EndpointBindingReconciler{ + controller := &BoundEndpointReconciler{ ClusterDomain: "svc.cluster.local", } - endpointBinding := &bindingsv1alpha1.EndpointBinding{ + boundEndpoint := &bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ Name: "abc123", // hashed/unique name Namespace: "ngrok-op", }, - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ Scheme: "https", Target: bindingsv1alpha1.EndpointTarget{ Service: "client-service", @@ -60,12 +60,12 @@ func Test_convertEndpointBindingToServices(t *testing.T) { Port: 8080, }, }, - Status: bindingsv1alpha1.EndpointBindingStatus{ + Status: bindingsv1alpha1.BoundEndpointStatus{ HashedName: "abc123", }, } - targetService, upstreamService := controller.convertEndpointBindingToServices(endpointBinding) + targetService, upstreamService := controller.convertBoundEndpointToServices(boundEndpoint) assert.Equal(targetService.Name, "client-service") assert.Equal(targetService.Namespace, "client-namespace") @@ -81,14 +81,14 @@ func Test_setEndpointsStatus(t *testing.T) { t.Parallel() tests := []struct { - name string - endpointBinding *bindingsv1alpha1.EndpointBinding - desired *bindingsv1alpha1.BindingEndpoint + name string + boundEndpoint *bindingsv1alpha1.BoundEndpoint + desired *bindingsv1alpha1.BindingEndpoint }{ { name: "Set provisioning status", - endpointBinding: &bindingsv1alpha1.EndpointBinding{ - Status: bindingsv1alpha1.EndpointBindingStatus{ + boundEndpoint: &bindingsv1alpha1.BoundEndpoint{ + Status: bindingsv1alpha1.BoundEndpointStatus{ Endpoints: []bindingsv1alpha1.BindingEndpoint{ { Status: bindingsv1alpha1.StatusUnknown, @@ -116,8 +116,8 @@ func Test_setEndpointsStatus(t *testing.T) { }, { name: "Set error status", - endpointBinding: &bindingsv1alpha1.EndpointBinding{ - Status: bindingsv1alpha1.EndpointBindingStatus{ + boundEndpoint: &bindingsv1alpha1.BoundEndpoint{ + Status: bindingsv1alpha1.BoundEndpointStatus{ Endpoints: []bindingsv1alpha1.BindingEndpoint{ { Status: bindingsv1alpha1.StatusProvisioning, @@ -150,9 +150,9 @@ func Test_setEndpointsStatus(t *testing.T) { t.Parallel() assert := assert.New(t) - setEndpointsStatus(test.endpointBinding, test.desired) + setEndpointsStatus(test.boundEndpoint, test.desired) - for _, endpoint := range test.endpointBinding.Status.Endpoints { + for _, endpoint := range test.boundEndpoint.Status.Endpoints { assert.Equal(endpoint.Status, test.desired.Status) assert.Equal(endpoint.ErrorCode, test.desired.ErrorCode) assert.Equal(endpoint.ErrorMessage, test.desired.ErrorMessage) diff --git a/internal/controller/bindings/endpointbinding_poller.go b/internal/controller/bindings/boundendpoint_poller.go similarity index 61% rename from internal/controller/bindings/endpointbinding_poller.go rename to internal/controller/bindings/boundendpoint_poller.go index d7d76de6..4afd92c0 100644 --- a/internal/controller/bindings/endpointbinding_poller.go +++ b/internal/controller/bindings/boundendpoint_poller.go @@ -31,14 +31,14 @@ type PortRangeConfig struct { Max uint16 } -// EndpointBindingPoller is a process to poll the ngrok API for binding_endpoints and reconcile the desired state with the cluster state of EndpointBindings -type EndpointBindingPoller struct { +// BoundEndpointPoller is a process to poll the ngrok API for binding_endpoints and reconcile the desired state with the cluster state of BoundEndpoints +type BoundEndpointPoller struct { client.Client Scheme *runtime.Scheme Log logr.Logger Recorder record.EventRecorder - // Namespace is the namespace to manage for EndpointBindings + // Namespace is the namespace to manage for BoundEndpoints Namespace string // KubernetesOperatorConfigName is the expected name of the KubernetesOperator that we should poll @@ -65,7 +65,7 @@ type EndpointBindingPoller struct { } // Start implements the manager.Runnable interface. -func (r *EndpointBindingPoller) Start(ctx context.Context) error { +func (r *BoundEndpointPoller) Start(ctx context.Context) error { log := ctrl.LoggerFrom(ctx) // retrieve k8sop ID @@ -85,7 +85,7 @@ func (r *EndpointBindingPoller) Start(ctx context.Context) error { } // getKubernetesOperatorId waits to retrieve the k8sop ID from the KubernetesOperator resource, post-registration -func (r *EndpointBindingPoller) getKubernetesOperatorId(ctx context.Context) string { +func (r *BoundEndpointPoller) getKubernetesOperatorId(ctx context.Context) string { log := ctrl.LoggerFrom(ctx) log.V(1).Info("Waiting for KubernetesOperator to be registered and ID returned") @@ -123,14 +123,14 @@ func (r *EndpointBindingPoller) getKubernetesOperatorId(ctx context.Context) str } // startPollingAPI polls a mock API every over a polling interval and updates the BindingConfiguration's status. -func (r *EndpointBindingPoller) startPollingAPI(ctx context.Context) { +func (r *BoundEndpointPoller) startPollingAPI(ctx context.Context) { log := ctrl.LoggerFrom(ctx) ticker := time.NewTicker(r.PollingInterval) defer ticker.Stop() // Reconcile on startup - if err := r.reconcileEndpointBindingsFromAPI(ctx); err != nil { + if err := r.reconcileBoundEndpointsFromAPI(ctx); err != nil { log.Error(err, "Failed to update binding_endpoints from API") } @@ -138,7 +138,7 @@ func (r *EndpointBindingPoller) startPollingAPI(ctx context.Context) { select { case <-ticker.C: log.Info("Polling API for binding_endpoints") - if err := r.reconcileEndpointBindingsFromAPI(ctx); err != nil { + if err := r.reconcileBoundEndpointsFromAPI(ctx); err != nil { log.Error(err, "Failed to update binding_endpoints from API") } case <-r.stopCh: @@ -148,9 +148,9 @@ func (r *EndpointBindingPoller) startPollingAPI(ctx context.Context) { } } -// reconcileEndpointBindingsFromAPI fetches the desired binding_endpoints for this kubernetes operator binding -// then creates, updates, or deletes the EndpointBindings in-cluster -func (r *EndpointBindingPoller) reconcileEndpointBindingsFromAPI(ctx context.Context) error { +// reconcileBoundEndpointsFromAPI fetches the desired binding_endpoints for this kubernetes operator binding +// then creates, updates, or deletes the BoundEndpoints in-cluster +func (r *BoundEndpointPoller) reconcileBoundEndpointsFromAPI(ctx context.Context) error { log := ctrl.LoggerFrom(ctx) if r.reconcilingCancel != nil { @@ -171,25 +171,25 @@ func (r *EndpointBindingPoller) reconcileEndpointBindingsFromAPI(ctx context.Con apiBindingEndpoints = resp.BindingEndpoints.Endpoints } - desiredEndpointBindings, err := ngrokapi.AggregateBindingEndpoints(apiBindingEndpoints) + desiredBoundEndpoints, err := ngrokapi.AggregateBindingEndpoints(apiBindingEndpoints) if err != nil { return err } - // Get all current EndpointBinding resources in the cluster. - var epbList bindingsv1alpha1.EndpointBindingList + // Get all current BoundEndpoint resources in the cluster. + var epbList bindingsv1alpha1.BoundEndpointList if err := r.List(ctx, &epbList); err != nil { return err } - existingEndpointBindings := epbList.Items + existingBoundEndpoints := epbList.Items - // since we have the existing EndpointBindings and their Ports + // since we have the existing BoundEndpoints and their Ports // let's use this opportunity to refresh the port allocater's state // NOTE: This range must stay static using this implementation. currentPortAllocations := newPortBitmap(r.PortRange.Min, r.PortRange.Max) - for _, existingEndpointBinding := range existingEndpointBindings { - if err := currentPortAllocations.Set(existingEndpointBinding.Spec.Port); err != nil { - r.Log.Error(err, "Failed to refresh port allocation", "port", existingEndpointBinding.Spec.Port, "name", existingEndpointBinding.Name) + for _, existingBoundEndpoint := range existingBoundEndpoints { + if err := currentPortAllocations.Set(existingBoundEndpoint.Spec.Port); err != nil { + r.Log.Error(err, "Failed to refresh port allocation", "port", existingBoundEndpoint.Spec.Port, "name", existingBoundEndpoint.Name) return err } } @@ -197,36 +197,36 @@ func (r *EndpointBindingPoller) reconcileEndpointBindingsFromAPI(ctx context.Con // reassign port allocations r.portAllocator = currentPortAllocations - toCreate, toUpdate, toDelete := r.filterEndpointBindingActions(ctx, existingEndpointBindings, desiredEndpointBindings) + toCreate, toUpdate, toDelete := r.filterBoundEndpointActions(ctx, existingBoundEndpoints, desiredBoundEndpoints) // create context + errgroup for managing/closing the future goroutine in the reconcile actions loops errGroup, ctx := errgroup.WithContext(ctx) ctx, cancel := context.WithCancel(ctx) r.reconcilingCancel = cancel - // launch goroutines to reconcile the EndpointBindings' actions in the background until the next polling loop + // launch goroutines to reconcile the BoundEndpoints' actions in the background until the next polling loop - r.reconcileEndpointBindingAction(ctx, errGroup, toCreate, "create", func(ctx context.Context, binding bindingsv1alpha1.EndpointBinding) error { + r.reconcileBoundEndpointAction(ctx, errGroup, toCreate, "create", func(ctx context.Context, binding bindingsv1alpha1.BoundEndpoint) error { return r.createBinding(ctx, binding) }) - r.reconcileEndpointBindingAction(ctx, errGroup, toUpdate, "update", func(ctx context.Context, binding bindingsv1alpha1.EndpointBinding) error { + r.reconcileBoundEndpointAction(ctx, errGroup, toUpdate, "update", func(ctx context.Context, binding bindingsv1alpha1.BoundEndpoint) error { return r.updateBinding(ctx, binding) }) - r.reconcileEndpointBindingAction(ctx, errGroup, toDelete, "delete", func(ctx context.Context, binding bindingsv1alpha1.EndpointBinding) error { + r.reconcileBoundEndpointAction(ctx, errGroup, toDelete, "delete", func(ctx context.Context, binding bindingsv1alpha1.BoundEndpoint) error { return r.deleteBinding(ctx, binding) }) return nil } -// endpointBindingActionFn reprents an action to take on an EndpointBinding during reconciliation -type endpointBindingActionFn func(context.Context, bindingsv1alpha1.EndpointBinding) error +// boundEndpointActionFn reprents an action to take on an BoundEndpoint during reconciliation +type boundEndpointActionFn func(context.Context, bindingsv1alpha1.BoundEndpoint) error -// reconcileEndpointBindingAction runs a goroutine to try and process a list of EndpointBindings +// reconcileBoundEndpointAction runs a goroutine to try and process a list of BoundEndpoints // for their desired action over and over again until stopChan is closed or receives a value -func (r *EndpointBindingPoller) reconcileEndpointBindingAction(ctx context.Context, errGroup *errgroup.Group, endpointBindings []bindingsv1alpha1.EndpointBinding, actionMsg string, action endpointBindingActionFn) { +func (r *BoundEndpointPoller) reconcileBoundEndpointAction(ctx context.Context, errGroup *errgroup.Group, boundEndpoints []bindingsv1alpha1.BoundEndpoint, actionMsg string, action boundEndpointActionFn) { log := ctrl.LoggerFrom(ctx) errGroup.Go(func() error { @@ -234,14 +234,14 @@ func (r *EndpointBindingPoller) reconcileEndpointBindingAction(ctx context.Conte ticker := time.NewTicker(5 * time.Second) defer ticker.Stop() - // remainingBindings is the list of EndpointBindings that still need to be actioned upon - remainingBindings := endpointBindings + // remainingBindings is the list of BoundEndpoints that still need to be actioned upon + remainingBindings := boundEndpoints for { select { // stop go routine and return, there is a new reconcile poll happening actively case <-ctx.Done(): - log.Error(ctx.Err(), "Reconcile context canceled, stopping EndpointBinding reconcile loop early", "action", actionMsg) + log.Error(ctx.Err(), "Reconcile context canceled, stopping BoundEndpoint reconcile loop early", "action", actionMsg) return nil case <-ticker.C: log.V(9).Info("Received tick", "action", actionMsg, "remaining", remainingBindings) @@ -249,13 +249,13 @@ func (r *EndpointBindingPoller) reconcileEndpointBindingAction(ctx context.Conte return nil // all bindings have been processed } - failedBindings := []bindingsv1alpha1.EndpointBinding{} + failedBindings := []bindingsv1alpha1.BoundEndpoint{} // process from list for _, binding := range remainingBindings { if err := action(ctx, binding); err != nil { name := hashURI(binding.Spec.EndpointURI) - log.Error(err, "Failed to reconcile EndpointBinding", "action", actionMsg, "name", name, "uri", binding.Spec.EndpointURI) + log.Error(err, "Failed to reconcile BoundEndpoint", "action", actionMsg, "name", name, "uri", binding.Spec.EndpointURI) failedBindings = append(failedBindings, binding) } } @@ -267,38 +267,38 @@ func (r *EndpointBindingPoller) reconcileEndpointBindingAction(ctx context.Conte }) } -// filterEndpointBindingActions takse 2 sets of existing and desired EndpointBindings +// filterBoundEndpointActions takse 2 sets of existing and desired BoundEndpoints // and returns 3 lists: toCreate, toUpdate, toDelete // representing the actions needed to reconcile the existing set with the desired set -func (r *EndpointBindingPoller) filterEndpointBindingActions(ctx context.Context, existingEndpointBindings []bindingsv1alpha1.EndpointBinding, desiredEndpoints ngrokapi.AggregatedEndpoints) (toCreate []bindingsv1alpha1.EndpointBinding, toUpdate []bindingsv1alpha1.EndpointBinding, toDelete []bindingsv1alpha1.EndpointBinding) { +func (r *BoundEndpointPoller) filterBoundEndpointActions(ctx context.Context, existingBoundEndpoints []bindingsv1alpha1.BoundEndpoint, desiredEndpoints ngrokapi.AggregatedEndpoints) (toCreate []bindingsv1alpha1.BoundEndpoint, toUpdate []bindingsv1alpha1.BoundEndpoint, toDelete []bindingsv1alpha1.BoundEndpoint) { log := ctrl.LoggerFrom(ctx) - toCreate = []bindingsv1alpha1.EndpointBinding{} - toUpdate = []bindingsv1alpha1.EndpointBinding{} - toDelete = []bindingsv1alpha1.EndpointBinding{} + toCreate = []bindingsv1alpha1.BoundEndpoint{} + toUpdate = []bindingsv1alpha1.BoundEndpoint{} + toDelete = []bindingsv1alpha1.BoundEndpoint{} - log.V(9).Info("Filtering EndpointBindings", "existing", existingEndpointBindings, "desired", desiredEndpoints) + log.V(9).Info("Filtering BoundEndpoints", "existing", existingBoundEndpoints, "desired", desiredEndpoints) - for _, existingEndpointBinding := range existingEndpointBindings { - uri := existingEndpointBinding.Spec.EndpointURI + for _, existingBoundEndpoint := range existingBoundEndpoints { + uri := existingBoundEndpoint.Spec.EndpointURI - if desiredEndpointBinding, ok := desiredEndpoints[uri]; ok { - expectedName := hashURI(desiredEndpointBinding.Spec.EndpointURI) + if desiredBoundEndpoint, ok := desiredEndpoints[uri]; ok { + expectedName := hashURI(desiredBoundEndpoint.Spec.EndpointURI) // if the names match, then they are the same resource and we can update it - if existingEndpointBinding.Name == expectedName { + if existingBoundEndpoint.Name == expectedName { // existing endpoint is in our desired set - // update this EndpointBinding - toUpdate = append(toUpdate, desiredEndpointBinding) + // update this BoundEndpoint + toUpdate = append(toUpdate, desiredBoundEndpoint) } else { // otherwise, we need a delete + create, rather than an update - toDelete = append(toDelete, existingEndpointBinding) - toCreate = append(toCreate, desiredEndpointBinding) + toDelete = append(toDelete, existingBoundEndpoint) + toCreate = append(toCreate, desiredBoundEndpoint) } } else { // existing endpoint is not in our desired set - // delete this EndpointBinding - toDelete = append(toDelete, existingEndpointBinding) + // delete this BoundEndpoint + toDelete = append(toDelete, existingBoundEndpoint) } // remove the desired endpoint from the set @@ -306,17 +306,17 @@ func (r *EndpointBindingPoller) filterEndpointBindingActions(ctx context.Context delete(desiredEndpoints, uri) } - for _, desiredEndpointBinding := range desiredEndpoints { + for _, desiredBoundEndpoint := range desiredEndpoints { // desired endpoint is not in our existing set - // create this EndpointBinding - toCreate = append(toCreate, desiredEndpointBinding) + // create this BoundEndpoint + toCreate = append(toCreate, desiredBoundEndpoint) } return toCreate, toUpdate, toDelete } // TODO: Metadata -func (r *EndpointBindingPoller) createBinding(ctx context.Context, desired bindingsv1alpha1.EndpointBinding) error { +func (r *BoundEndpointPoller) createBinding(ctx context.Context, desired bindingsv1alpha1.BoundEndpoint) error { log := ctrl.LoggerFrom(ctx) name := hashURI(desired.Spec.EndpointURI) @@ -324,20 +324,20 @@ func (r *EndpointBindingPoller) createBinding(ctx context.Context, desired bindi // allocate a port port, err := r.portAllocator.SetAny() if err != nil { - r.Log.Error(err, "Failed to allocate port for EndpointBinding", "name", name, "uri", desired.Spec.EndpointURI) + r.Log.Error(err, "Failed to allocate port for BoundEndpoint", "name", name, "uri", desired.Spec.EndpointURI) return err } - toCreate := &bindingsv1alpha1.EndpointBinding{ + toCreate := &bindingsv1alpha1.BoundEndpoint{ TypeMeta: metav1.TypeMeta{ APIVersion: "bindings.ngrok.com/v1alpha1", - Kind: "EndpointBinding", + Kind: "BoundEndpoint", }, ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: r.Namespace, }, - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: desired.Spec.EndpointURI, Scheme: desired.Spec.Scheme, Port: port, @@ -350,10 +350,10 @@ func (r *EndpointBindingPoller) createBinding(ctx context.Context, desired bindi }, } - log.Info("Creating new EndpointBinding", "name", name, "uri", toCreate.Spec.EndpointURI) + log.Info("Creating new BoundEndpoint", "name", name, "uri", toCreate.Spec.EndpointURI) if err := r.Create(ctx, toCreate); err != nil { if client.IgnoreAlreadyExists(err) == nil { - log.Info("EndpointBinding already exists, skipping create...", "name", name, "uri", toCreate.Spec.EndpointURI) + log.Info("BoundEndpoint already exists, skipping create...", "name", name, "uri", toCreate.Spec.EndpointURI) if toCreate.Status.HashedName != "" && len(toCreate.Status.Endpoints) > 0 { // Status is filled, no need to update @@ -361,24 +361,24 @@ func (r *EndpointBindingPoller) createBinding(ctx context.Context, desired bindi } else { // intentionally blonk // we want to fall through and fill in the status - log.Info("EndpointBinding already exists, but status is empty, filling in status...", "name", name, "uri", toCreate.Spec.EndpointURI, "toCreate", toCreate) + log.Info("BoundEndpoint already exists, but status is empty, filling in status...", "name", name, "uri", toCreate.Spec.EndpointURI, "toCreate", toCreate) // refresh the toCreate object with existing data if err := r.Get(ctx, client.ObjectKey{Namespace: r.Namespace, Name: name}, toCreate); err != nil { - log.Error(err, "Failed to get existing EndpointBinding, skipping status update...", "name", name, "uri", toCreate.Spec.EndpointURI) + log.Error(err, "Failed to get existing BoundEndpoint, skipping status update...", "name", name, "uri", toCreate.Spec.EndpointURI) return nil } } } else { - log.Error(err, "Failed to create EndpointBinding", "name", name, "uri", toCreate.Spec.EndpointURI) - r.Recorder.Event(toCreate, v1.EventTypeWarning, "Created", fmt.Sprintf("Failed to create EndpointBinding: %v", err)) + log.Error(err, "Failed to create BoundEndpoint", "name", name, "uri", toCreate.Spec.EndpointURI) + r.Recorder.Event(toCreate, v1.EventTypeWarning, "Created", fmt.Sprintf("Failed to create BoundEndpoint: %v", err)) return err } } // now fill in the status into the returned resource - toCreateStatus := bindingsv1alpha1.EndpointBindingStatus{ + toCreateStatus := bindingsv1alpha1.BoundEndpointStatus{ HashedName: name, Endpoints: []bindingsv1alpha1.BindingEndpoint{}, // empty for now, will be filled in just below } @@ -399,31 +399,31 @@ func (r *EndpointBindingPoller) createBinding(ctx context.Context, desired bindi return err } - r.Recorder.Event(toCreate, v1.EventTypeNormal, "Created", "EndpointBinding created successfully") + r.Recorder.Event(toCreate, v1.EventTypeNormal, "Created", "BoundEndpoint created successfully") return nil } -func (r *EndpointBindingPoller) updateBinding(ctx context.Context, desired bindingsv1alpha1.EndpointBinding) error { +func (r *BoundEndpointPoller) updateBinding(ctx context.Context, desired bindingsv1alpha1.BoundEndpoint) error { log := ctrl.LoggerFrom(ctx) desiredName := hashURI(desired.Spec.EndpointURI) - var existing bindingsv1alpha1.EndpointBinding + var existing bindingsv1alpha1.BoundEndpoint err := r.Get(ctx, client.ObjectKey{Namespace: r.Namespace, Name: desiredName}, &existing) if err != nil { if client.IgnoreNotFound(err) == nil { - // EndpointBinding doesn't exist, create it on the next polling loop - log.Info("Unable to find existing EndpointBinding, skipping update...", "name", desiredName, "uri", desired.Spec.EndpointURI) + // BoundEndpoint doesn't exist, create it on the next polling loop + log.Info("Unable to find existing BoundEndpoint, skipping update...", "name", desiredName, "uri", desired.Spec.EndpointURI) return nil // not an error } else { // real error - log.Error(err, "Failed to find existing EndpointBinding", "name", desiredName, "uri", desired.Spec.EndpointURI) + log.Error(err, "Failed to find existing BoundEndpoint", "name", desiredName, "uri", desired.Spec.EndpointURI) return err } } - if !endpointBindingNeedsUpdate(existing, desired) { - log.Info("EndpointBinding already matches existing state, skipping update...", "name", desiredName, "uri", desired.Spec.EndpointURI) + if !boundEndpointNeedsUpdate(existing, desired) { + log.Info("BoundEndpoint already matches existing state, skipping update...", "name", desiredName, "uri", desired.Spec.EndpointURI) return nil } @@ -435,16 +435,16 @@ func (r *EndpointBindingPoller) updateBinding(ctx context.Context, desired bindi toUpdate.Spec.Target = desired.Spec.Target toUpdate.Spec.EndpointURI = desired.Spec.EndpointURI - log.Info("Updating EndpointBinding", "name", toUpdate.Name, "uri", toUpdate.Spec.EndpointURI) + log.Info("Updating BoundEndpoint", "name", toUpdate.Name, "uri", toUpdate.Spec.EndpointURI) if err := r.Update(ctx, toUpdate); err != nil { - log.Error(err, "Failed updating EndpointBinding", "name", toUpdate.Name, "uri", toUpdate.Spec.EndpointURI) - r.Recorder.Event(toUpdate, v1.EventTypeWarning, "Updated", fmt.Sprintf("Failed to update EndpointBinding: %v", err)) + log.Error(err, "Failed updating BoundEndpoint", "name", toUpdate.Name, "uri", toUpdate.Spec.EndpointURI) + r.Recorder.Event(toUpdate, v1.EventTypeWarning, "Updated", fmt.Sprintf("Failed to update BoundEndpoint: %v", err)) return err } // now fill in the status into the returned resource - toUpdateStatus := bindingsv1alpha1.EndpointBindingStatus{ + toUpdateStatus := bindingsv1alpha1.BoundEndpointStatus{ HashedName: desiredName, Endpoints: []bindingsv1alpha1.BindingEndpoint{}, // empty for now, will be filled in just below } @@ -465,43 +465,43 @@ func (r *EndpointBindingPoller) updateBinding(ctx context.Context, desired bindi return err } - r.Recorder.Event(toUpdate, v1.EventTypeNormal, "Updated", "EndpointBinding updated successfully") + r.Recorder.Event(toUpdate, v1.EventTypeNormal, "Updated", "BoundEndpoint updated successfully") return nil } -func (r *EndpointBindingPoller) deleteBinding(ctx context.Context, endpointBinding bindingsv1alpha1.EndpointBinding) error { +func (r *BoundEndpointPoller) deleteBinding(ctx context.Context, boundEndpoint bindingsv1alpha1.BoundEndpoint) error { log := ctrl.LoggerFrom(ctx) - if err := r.Delete(ctx, &endpointBinding); err != nil { - log.Error(err, "Failed to delete EndpointBinding", "name", endpointBinding.Name, "uri", endpointBinding.Spec.EndpointURI) + if err := r.Delete(ctx, &boundEndpoint); err != nil { + log.Error(err, "Failed to delete BoundEndpoint", "name", boundEndpoint.Name, "uri", boundEndpoint.Spec.EndpointURI) return err } else { - log.Info("Deleted EndpointBinding", "name", endpointBinding.Name, "uri", endpointBinding.Spec.EndpointURI) + log.Info("Deleted BoundEndpoint", "name", boundEndpoint.Name, "uri", boundEndpoint.Spec.EndpointURI) // unset the port allocation - r.portAllocator.Unset(endpointBinding.Spec.Port) + r.portAllocator.Unset(boundEndpoint.Spec.Port) } return nil } -func (r *EndpointBindingPoller) updateBindingStatus(ctx context.Context, desired *bindingsv1alpha1.EndpointBinding) error { +func (r *BoundEndpointPoller) updateBindingStatus(ctx context.Context, desired *bindingsv1alpha1.BoundEndpoint) error { log := ctrl.LoggerFrom(ctx) toUpdate := desired toUpdate.Status = desired.Status if err := r.Status().Update(ctx, toUpdate); err != nil { - log.Error(err, "Failed to update EndpointBinding status", "name", toUpdate.Name, "uri", toUpdate.Spec.EndpointURI) + log.Error(err, "Failed to update BoundEndpoint status", "name", toUpdate.Name, "uri", toUpdate.Spec.EndpointURI) return err } - log.Info("Updated EndpointBinding status", "name", toUpdate.Name, "uri", toUpdate.Spec.EndpointURI) + log.Info("Updated BoundEndpoint status", "name", toUpdate.Name, "uri", toUpdate.Spec.EndpointURI) return nil } -// endpointBindingNeedsUpdate returns true if the data in desired does not match existing, and therefore existing needs updating to match desired -func endpointBindingNeedsUpdate(existing bindingsv1alpha1.EndpointBinding, desired bindingsv1alpha1.EndpointBinding) bool { +// boundEndpointNeedsUpdate returns true if the data in desired does not match existing, and therefore existing needs updating to match desired +func boundEndpointNeedsUpdate(existing bindingsv1alpha1.BoundEndpoint, desired bindingsv1alpha1.BoundEndpoint) bool { hasSpecChanged := existing.Spec.Scheme != desired.Spec.Scheme || !reflect.DeepEqual(existing.Spec.Target, desired.Spec.Target) @@ -530,7 +530,7 @@ func endpointBindingNeedsUpdate(existing bindingsv1alpha1.EndpointBinding, desir // TODO: Compare Metadata labels and annotations between configured values and existing values } -// hashURI hashes a URI to a unique string that can be used as EndpointBinding.metadata.name +// hashURI hashes a URI to a unique string that can be used as BoundEndpoint.metadata.name func hashURI(uri string) string { uid := uuid.NewSHA1(uuid.NameSpaceURL, []byte(uri)) return "ngrok-" + uid.String() diff --git a/internal/controller/bindings/endpointbinding_poller_test.go b/internal/controller/bindings/boundendpoint_poller_test.go similarity index 66% rename from internal/controller/bindings/endpointbinding_poller_test.go rename to internal/controller/bindings/boundendpoint_poller_test.go index 8e190c33..6590be54 100644 --- a/internal/controller/bindings/endpointbinding_poller_test.go +++ b/internal/controller/bindings/boundendpoint_poller_test.go @@ -12,88 +12,88 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func Test_EndpointBindingPoller_filterEndpointBindingActions(t *testing.T) { +func Test_BoundEndpointPoller_filterBoundEndpointActions(t *testing.T) { t.Parallel() - examplePoller := EndpointBindingPoller{ + examplePoller := BoundEndpointPoller{ Log: logr.Discard(), } - // some example EndpointBindings we can use for test cases + // some example BoundEndpoints we can use for test cases uriExample1 := "http://service1.namespace1:8080" - epdExample1 := bindingsv1alpha1.EndpointBinding{ + epdExample1 := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ Name: hashURI(uriExample1), }, - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: uriExample1, }, } uriExample2 := "https://service2.namespace2:443" - epdExample2 := bindingsv1alpha1.EndpointBinding{ + epdExample2 := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ Name: hashURI(uriExample2), }, - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: uriExample2, }, } uriExample3 := "https://service3.namespace3:443" - epdExample3 := bindingsv1alpha1.EndpointBinding{ + epdExample3 := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ Name: hashURI(uriExample3), }, - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: uriExample3, }, } - epdExample4 := bindingsv1alpha1.EndpointBinding{ + epdExample4 := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ // Name does not match example3 on puprose // to test if re-names trigger delete/create rather than update Name: "abcd1234-abcd-1234-abcd-1234abcd1234", }, - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: uriExample3, // example 3 on purpose, see Name }, } tests := []struct { name string - existing []bindingsv1alpha1.EndpointBinding + existing []bindingsv1alpha1.BoundEndpoint desired ngrokapi.AggregatedEndpoints - wantCreate []bindingsv1alpha1.EndpointBinding - wantUpdate []bindingsv1alpha1.EndpointBinding - wantDelete []bindingsv1alpha1.EndpointBinding + wantCreate []bindingsv1alpha1.BoundEndpoint + wantUpdate []bindingsv1alpha1.BoundEndpoint + wantDelete []bindingsv1alpha1.BoundEndpoint }{ { name: "empty existing and desired", - existing: []bindingsv1alpha1.EndpointBinding{}, + existing: []bindingsv1alpha1.BoundEndpoint{}, desired: ngrokapi.AggregatedEndpoints{}, - wantCreate: []bindingsv1alpha1.EndpointBinding{}, - wantUpdate: []bindingsv1alpha1.EndpointBinding{}, - wantDelete: []bindingsv1alpha1.EndpointBinding{}, + wantCreate: []bindingsv1alpha1.BoundEndpoint{}, + wantUpdate: []bindingsv1alpha1.BoundEndpoint{}, + wantDelete: []bindingsv1alpha1.BoundEndpoint{}, }, { name: "empty existing; create desired", - existing: []bindingsv1alpha1.EndpointBinding{}, + existing: []bindingsv1alpha1.BoundEndpoint{}, desired: ngrokapi.AggregatedEndpoints{ uriExample1: epdExample1, uriExample2: epdExample2, }, - wantCreate: []bindingsv1alpha1.EndpointBinding{ + wantCreate: []bindingsv1alpha1.BoundEndpoint{ epdExample1, epdExample2, }, - wantUpdate: []bindingsv1alpha1.EndpointBinding{}, - wantDelete: []bindingsv1alpha1.EndpointBinding{}, + wantUpdate: []bindingsv1alpha1.BoundEndpoint{}, + wantDelete: []bindingsv1alpha1.BoundEndpoint{}, }, { - name: "update endpointbindings", - existing: []bindingsv1alpha1.EndpointBinding{ + name: "update boundendpoints", + existing: []bindingsv1alpha1.BoundEndpoint{ epdExample1, epdExample2, }, @@ -101,16 +101,16 @@ func Test_EndpointBindingPoller_filterEndpointBindingActions(t *testing.T) { uriExample1: epdExample1, uriExample2: epdExample2, }, - wantCreate: []bindingsv1alpha1.EndpointBinding{}, - wantUpdate: []bindingsv1alpha1.EndpointBinding{ + wantCreate: []bindingsv1alpha1.BoundEndpoint{}, + wantUpdate: []bindingsv1alpha1.BoundEndpoint{ epdExample1, epdExample2, }, - wantDelete: []bindingsv1alpha1.EndpointBinding{}, + wantDelete: []bindingsv1alpha1.BoundEndpoint{}, }, { name: "create, delete, and update", - existing: []bindingsv1alpha1.EndpointBinding{ + existing: []bindingsv1alpha1.BoundEndpoint{ epdExample1, epdExample2, // epdExample3 is missing, toCreate @@ -120,29 +120,29 @@ func Test_EndpointBindingPoller_filterEndpointBindingActions(t *testing.T) { // epdExample2 is missing, toDelete uriExample3: epdExample3, }, - wantCreate: []bindingsv1alpha1.EndpointBinding{ + wantCreate: []bindingsv1alpha1.BoundEndpoint{ epdExample3, }, - wantUpdate: []bindingsv1alpha1.EndpointBinding{ + wantUpdate: []bindingsv1alpha1.BoundEndpoint{ epdExample1, }, - wantDelete: []bindingsv1alpha1.EndpointBinding{ + wantDelete: []bindingsv1alpha1.BoundEndpoint{ epdExample2, }, }, { name: "delete/create, rather than update", - existing: []bindingsv1alpha1.EndpointBinding{ + existing: []bindingsv1alpha1.BoundEndpoint{ epdExample4, }, desired: ngrokapi.AggregatedEndpoints{ uriExample3: epdExample3, // example4 on purpose }, - wantCreate: []bindingsv1alpha1.EndpointBinding{ + wantCreate: []bindingsv1alpha1.BoundEndpoint{ epdExample3, }, - wantUpdate: []bindingsv1alpha1.EndpointBinding{}, - wantDelete: []bindingsv1alpha1.EndpointBinding{ + wantUpdate: []bindingsv1alpha1.BoundEndpoint{}, + wantDelete: []bindingsv1alpha1.BoundEndpoint{ epdExample4, }, }, @@ -153,7 +153,7 @@ func Test_EndpointBindingPoller_filterEndpointBindingActions(t *testing.T) { t.Parallel() assert := assert.New(t) - gotCreate, gotUpdate, gotDelete := examplePoller.filterEndpointBindingActions(context.TODO(), test.existing, test.desired) + gotCreate, gotUpdate, gotDelete := examplePoller.filterBoundEndpointActions(context.TODO(), test.existing, test.desired) assert.ElementsMatch(test.wantCreate, gotCreate) assert.ElementsMatch(test.wantUpdate, gotUpdate) @@ -162,16 +162,16 @@ func Test_EndpointBindingPoller_filterEndpointBindingActions(t *testing.T) { } } -func Test_EndpointBindingPoller_endpointBindingNeedsUpdate(t *testing.T) { +func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { t.Parallel() - // some example EndpointBindings we can use for test cases + // some example BoundEndpoints we can use for test cases uriExample1 := "http://service1.namespace1:8080" - epdExample1 := bindingsv1alpha1.EndpointBinding{ + epdExample1 := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ Name: hashURI(uriExample1), }, - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: uriExample1, Target: bindingsv1alpha1.EndpointTarget{ Namespace: "namespace1", @@ -180,7 +180,7 @@ func Test_EndpointBindingPoller_endpointBindingNeedsUpdate(t *testing.T) { Protocol: "TCP", }, }, - Status: bindingsv1alpha1.EndpointBindingStatus{ + Status: bindingsv1alpha1.BoundEndpointStatus{ HashedName: hashURI(uriExample1), Endpoints: []bindingsv1alpha1.BindingEndpoint{ { @@ -194,11 +194,11 @@ func Test_EndpointBindingPoller_endpointBindingNeedsUpdate(t *testing.T) { } uriExample2 := "https://service2.namespace2:443" - epdExample2 := bindingsv1alpha1.EndpointBinding{ + epdExample2 := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ Name: hashURI(uriExample2), }, - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: uriExample2, Target: bindingsv1alpha1.EndpointTarget{ Namespace: "namespace2", @@ -207,7 +207,7 @@ func Test_EndpointBindingPoller_endpointBindingNeedsUpdate(t *testing.T) { Protocol: "TCP", }, }, - Status: bindingsv1alpha1.EndpointBindingStatus{ + Status: bindingsv1alpha1.BoundEndpointStatus{ HashedName: hashURI(uriExample2), Endpoints: []bindingsv1alpha1.BindingEndpoint{ { @@ -220,11 +220,11 @@ func Test_EndpointBindingPoller_endpointBindingNeedsUpdate(t *testing.T) { }, } - epdExample2NewStatus := bindingsv1alpha1.EndpointBinding{ + epdExample2NewStatus := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ Name: hashURI(uriExample2), }, - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: uriExample2, Target: bindingsv1alpha1.EndpointTarget{ Namespace: "namespace2", @@ -233,7 +233,7 @@ func Test_EndpointBindingPoller_endpointBindingNeedsUpdate(t *testing.T) { Protocol: "TCP", }, }, - Status: bindingsv1alpha1.EndpointBindingStatus{ + Status: bindingsv1alpha1.BoundEndpointStatus{ HashedName: hashURI(uriExample2), Endpoints: []bindingsv1alpha1.BindingEndpoint{ { @@ -260,8 +260,8 @@ func Test_EndpointBindingPoller_endpointBindingNeedsUpdate(t *testing.T) { tests := []struct { name string - existing bindingsv1alpha1.EndpointBinding - desired bindingsv1alpha1.EndpointBinding + existing bindingsv1alpha1.BoundEndpoint + desired bindingsv1alpha1.BoundEndpoint want bool }{ { @@ -289,13 +289,13 @@ func Test_EndpointBindingPoller_endpointBindingNeedsUpdate(t *testing.T) { t.Parallel() assert := assert.New(t) - got := endpointBindingNeedsUpdate(test.existing, test.desired) + got := boundEndpointNeedsUpdate(test.existing, test.desired) assert.Equal(test.want, got) }) } } -func Test_EndpointBindingPoller_hashURI(t *testing.T) { +func Test_BoundEndpointPoller_hashURI(t *testing.T) { assert := assert.New(t) endpointURI := "http://service.namespace:8080" diff --git a/internal/controller/bindings/forwarder_controller.go b/internal/controller/bindings/forwarder_controller.go index f57b3484..0b151883 100644 --- a/internal/controller/bindings/forwarder_controller.go +++ b/internal/controller/bindings/forwarder_controller.go @@ -54,7 +54,7 @@ type ForwarderReconciler struct { Recorder record.EventRecorder BindingsDriver *bindingsdriver.BindingsDriver - controller *controller.BaseController[*bindingsv1alpha1.EndpointBinding] + controller *controller.BaseController[*bindingsv1alpha1.BoundEndpoint] } func (r *ForwarderReconciler) SetupWithManager(mgr ctrl.Manager) (err error) { @@ -62,7 +62,7 @@ func (r *ForwarderReconciler) SetupWithManager(mgr ctrl.Manager) (err error) { return fmt.Errorf("BindingsDriver is required") } - r.controller = &controller.BaseController[*bindingsv1alpha1.EndpointBinding]{ + r.controller = &controller.BaseController[*bindingsv1alpha1.BoundEndpoint]{ Kube: r.Client, Log: r.Log, Recorder: r.Recorder, @@ -84,7 +84,7 @@ func (r *ForwarderReconciler) SetupWithManager(mgr ctrl.Manager) (err error) { } err = cont.Watch( - source.Kind(mgr.GetCache(), &bindingsv1alpha1.EndpointBinding{}), + source.Kind(mgr.GetCache(), &bindingsv1alpha1.BoundEndpoint{}), &handler.EnqueueRequestForObject{}, predicate.Or( predicate.AnnotationChangedPredicate{}, @@ -100,10 +100,10 @@ func (r *ForwarderReconciler) SetupWithManager(mgr ctrl.Manager) (err error) { } func (r *ForwarderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - return r.controller.Reconcile(ctx, req, new(bindingsv1alpha1.EndpointBinding)) + return r.controller.Reconcile(ctx, req, new(bindingsv1alpha1.BoundEndpoint)) } -func (r *ForwarderReconciler) update(ctx context.Context, epb *bindingsv1alpha1.EndpointBinding) error { +func (r *ForwarderReconciler) update(ctx context.Context, epb *bindingsv1alpha1.BoundEndpoint) error { log := ctrl.LoggerFrom(ctx).WithValues( "endpoint-binding", map[string]string{ "namespace": epb.Namespace, @@ -119,7 +119,7 @@ func (r *ForwarderReconciler) update(ctx context.Context, epb *bindingsv1alpha1. return r.BindingsDriver.Listen(port, exampleConnectionHandler(epb)) } -func (r *ForwarderReconciler) delete(ctx context.Context, epb *bindingsv1alpha1.EndpointBinding) error { +func (r *ForwarderReconciler) delete(ctx context.Context, epb *bindingsv1alpha1.BoundEndpoint) error { port := int32(epb.Spec.Port) r.BindingsDriver.Close(port) return nil @@ -128,13 +128,13 @@ func (r *ForwarderReconciler) delete(ctx context.Context, epb *bindingsv1alpha1. // Always returns the endpoint binding's "namespace/name". This is different than most of our other // controllers which return a .Status.ID field. We do this to always trigger the update handler of // the base controller. -func (r *ForwarderReconciler) statusID(epb *bindingsv1alpha1.EndpointBinding) string { +func (r *ForwarderReconciler) statusID(epb *bindingsv1alpha1.BoundEndpoint) string { return fmt.Sprintf("%s/%s", epb.Namespace, epb.Name) } // exampleConnectionHandler is a simple example of a connection handler that echos back each line // it reads from the client. It also sends a welcome message to the client. -func exampleConnectionHandler(epb *bindingsv1alpha1.EndpointBinding) bindingsdriver.ConnectionHandler { +func exampleConnectionHandler(epb *bindingsv1alpha1.BoundEndpoint) bindingsdriver.ConnectionHandler { return func(conn net.Conn) error { defer conn.Close() _, err := conn.Write([]byte( diff --git a/internal/ngrokapi/bindingendpoint_aggregator.go b/internal/ngrokapi/bindingendpoint_aggregator.go index 4d3a4922..5bfa2610 100644 --- a/internal/ngrokapi/bindingendpoint_aggregator.go +++ b/internal/ngrokapi/bindingendpoint_aggregator.go @@ -20,7 +20,7 @@ var ( ) // AggregatedEndpoints is a map of hostport to BindingEndpoint (partially filled in) -type AggregatedEndpoints map[string]bindingsv1alpha1.EndpointBinding +type AggregatedEndpoints map[string]bindingsv1alpha1.BoundEndpoint // AggregateBindingEndpoints aggregates the endpoints into a map of hostport to BindingEndpoint // by parsing the hostport 4-tuple into each piece ([://].[:]) @@ -37,14 +37,14 @@ func AggregateBindingEndpoints(endpoints []v6.Endpoint) (AggregatedEndpoints, er endpointURI := parsed.String() // Create a new BindingEndpoint if one doesn't exist - var bindingEndpoint bindingsv1alpha1.EndpointBinding + var bindingEndpoint bindingsv1alpha1.BoundEndpoint if val, ok := aggregated[endpointURI]; ok { bindingEndpoint = val } else { - // newly found hostport, create a new EndpointBinding - bindingEndpoint = bindingsv1alpha1.EndpointBinding{ + // newly found hostport, create a new BoundEndpoint + bindingEndpoint = bindingsv1alpha1.BoundEndpoint{ // parsed bits are shared across endpoints with the same hostport - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: endpointURI, Scheme: parsed.Scheme, Target: bindingsv1alpha1.EndpointTarget{ @@ -54,7 +54,7 @@ func AggregateBindingEndpoints(endpoints []v6.Endpoint) (AggregatedEndpoints, er Protocol: "TCP", // always tcp for now }, }, - Status: bindingsv1alpha1.EndpointBindingStatus{ + Status: bindingsv1alpha1.BoundEndpointStatus{ Endpoints: []bindingsv1alpha1.BindingEndpoint{}, }, } diff --git a/internal/ngrokapi/bindingendpoint_aggregator_test.go b/internal/ngrokapi/bindingendpoint_aggregator_test.go index 6fb7aba6..392892ad 100644 --- a/internal/ngrokapi/bindingendpoint_aggregator_test.go +++ b/internal/ngrokapi/bindingendpoint_aggregator_test.go @@ -64,7 +64,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { }, want: AggregatedEndpoints{ "https://service1.namespace1:443": { - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: "https://service1.namespace1:443", Scheme: "https", Target: bindingsv1alpha1.EndpointTarget{ @@ -74,7 +74,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { Protocol: "TCP", }, }, - Status: bindingsv1alpha1.EndpointBindingStatus{ + Status: bindingsv1alpha1.BoundEndpointStatus{ Endpoints: []bindingsv1alpha1.BindingEndpoint{ {Ref: v6.Ref{ID: "ep_123"}}, }, @@ -96,7 +96,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { }, want: AggregatedEndpoints{ "https://service1.namespace1:443": { - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: "https://service1.namespace1:443", Scheme: "https", Target: bindingsv1alpha1.EndpointTarget{ @@ -106,7 +106,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { Protocol: "TCP", }, }, - Status: bindingsv1alpha1.EndpointBindingStatus{ + Status: bindingsv1alpha1.BoundEndpointStatus{ Endpoints: []bindingsv1alpha1.BindingEndpoint{ {Ref: v6.Ref{ID: "ep_100"}}, {Ref: v6.Ref{ID: "ep_101"}}, @@ -115,7 +115,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { }, }, "tcp://service2.namespace2:2020": { - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: "tcp://service2.namespace2:2020", Scheme: "tcp", Target: bindingsv1alpha1.EndpointTarget{ @@ -125,7 +125,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { Protocol: "TCP", }, }, - Status: bindingsv1alpha1.EndpointBindingStatus{ + Status: bindingsv1alpha1.BoundEndpointStatus{ Endpoints: []bindingsv1alpha1.BindingEndpoint{ {Ref: v6.Ref{ID: "ep_200"}}, {Ref: v6.Ref{ID: "ep_201"}}, @@ -133,7 +133,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { }, }, "https://service3.namespace3:443": { - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: "https://service3.namespace3:443", Scheme: "https", Target: bindingsv1alpha1.EndpointTarget{ @@ -143,14 +143,14 @@ func Test_AggregateBindingEndpoints(t *testing.T) { Protocol: "TCP", }, }, - Status: bindingsv1alpha1.EndpointBindingStatus{ + Status: bindingsv1alpha1.BoundEndpointStatus{ Endpoints: []bindingsv1alpha1.BindingEndpoint{ {Ref: v6.Ref{ID: "ep_300"}}, }, }, }, "http://service4.namespace4:8080": { - Spec: bindingsv1alpha1.EndpointBindingSpec{ + Spec: bindingsv1alpha1.BoundEndpointSpec{ EndpointURI: "http://service4.namespace4:8080", Scheme: "http", Target: bindingsv1alpha1.EndpointTarget{ @@ -160,7 +160,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { Protocol: "TCP", }, }, - Status: bindingsv1alpha1.EndpointBindingStatus{ + Status: bindingsv1alpha1.BoundEndpointStatus{ Endpoints: []bindingsv1alpha1.BindingEndpoint{ {Ref: v6.Ref{ID: "ep_400"}}, }, From 5561d98387fc1b5d3650a654ac86e840df4f7305 Mon Sep 17 00:00:00 2001 From: Harrison Katz Date: Tue, 29 Oct 2024 15:44:29 -0400 Subject: [PATCH 2/2] Adjust ERR_NGROK as needed --- internal/controller/bindings/boundendpoint_controller.go | 6 +++--- .../controller/bindings/boundendpoint_controller_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/controller/bindings/boundendpoint_controller.go b/internal/controller/bindings/boundendpoint_controller.go index bab5c834..4634f362 100644 --- a/internal/controller/bindings/boundendpoint_controller.go +++ b/internal/controller/bindings/boundendpoint_controller.go @@ -62,9 +62,9 @@ const ( BoundEndpointTargetNamespacePath = ".spec.targetNamespace" // TODO(hkatz) ngrok-error-codes - NgrokErrorUpstreamServiceCreateFailed = "NGROK_ERR_0001" - NgrokErrorTargetServiceCreateFailed = "NGROK_ERR_0002" - NgrokErrorFailedToBind = "NGROK_ERR_003" + NgrokErrorUpstreamServiceCreateFailed = "ERR_NGROK_0001" + NgrokErrorTargetServiceCreateFailed = "ERR_NGROK_0002" + NgrokErrorFailedToBind = "ERR_NGROK_003" ) var ( diff --git a/internal/controller/bindings/boundendpoint_controller_test.go b/internal/controller/bindings/boundendpoint_controller_test.go index 1de1faf5..f525484d 100644 --- a/internal/controller/bindings/boundendpoint_controller_test.go +++ b/internal/controller/bindings/boundendpoint_controller_test.go @@ -139,7 +139,7 @@ func Test_setEndpointsStatus(t *testing.T) { }, desired: &bindingsv1alpha1.BindingEndpoint{ Status: bindingsv1alpha1.StatusError, - ErrorCode: "NGROK_ERR_1234", + ErrorCode: "ERR_NGROK_1234", ErrorMessage: "Exampl Error Message", }, },