diff --git a/api/bindings/v1alpha1/boundendpoint_types.go b/api/bindings/v1alpha1/boundendpoint_types.go index 0cfc08b4b..de4c76e4c 100644 --- a/api/bindings/v1alpha1/boundendpoint_types.go +++ b/api/bindings/v1alpha1/boundendpoint_types.go @@ -35,14 +35,14 @@ import ( // BoundEndpointSpec defines the desired state of BoundEndpoint type BoundEndpointSpec struct { - // EndpointURI is the unique identifier + // EndpointURL is the unique identifier // representing the BoundEndpoint + its Endpoints // Format: ://.: // // +kubebuilder:validation:Required // See: https://regex101.com/r/9QkXWl/1 // +kubebuilder:validation:Pattern=`^((?P(tcp|http|https|tls)?)://)?(?P[a-z][a-zA-Z0-9-]{0,62})\.(?P[a-z][a-zA-Z0-9-]{0,62})(:(?P\d+))?$` - EndpointURI string `json:"endpointURI"` + EndpointURL string `json:"endpointURL"` // Scheme is a user-defined field for endpoints that describe how the data packets // are framed by the pod forwarders mTLS connection to the ngrok edge @@ -138,7 +138,7 @@ type BindingEndpoint struct { // +kubebuilder:subresource:status // BoundEndpoint is the Schema for the boundendpoints API -// +kubebuilder:printcolumn:name="URI",type="string",JSONPath=".spec.endpointURI" +// +kubebuilder:printcolumn:name="URL",type="string",JSONPath=".spec.endpointURL" // +kubebuilder:printcolumn:name="Port",type="string",JSONPath=".spec.port" // +kubebuilder:printcolumn:name="Endpoints",type="string",JSONPath=".status.endpointsSummary" // +kubebuilder:printcolumn:name="Services",type="string",JSONPath=".status.conditions[?(@.type==\"ServicesCreated\")].status" diff --git a/helm/ngrok-crds/templates/bindings.k8s.ngrok.com_boundendpoints.yaml b/helm/ngrok-crds/templates/bindings.k8s.ngrok.com_boundendpoints.yaml index 2299048ff..221b8e062 100644 --- a/helm/ngrok-crds/templates/bindings.k8s.ngrok.com_boundendpoints.yaml +++ b/helm/ngrok-crds/templates/bindings.k8s.ngrok.com_boundendpoints.yaml @@ -15,8 +15,8 @@ spec: scope: Namespaced versions: - additionalPrinterColumns: - - jsonPath: .spec.endpointURI - name: URI + - jsonPath: .spec.endpointURL + name: URL type: string - jsonPath: .spec.port name: Port @@ -59,9 +59,9 @@ spec: spec: description: BoundEndpointSpec defines the desired state of BoundEndpoint properties: - endpointURI: + endpointURL: description: |- - EndpointURI is the unique identifier + EndpointURL is the unique identifier representing the BoundEndpoint + its Endpoints Format: ://.: @@ -136,7 +136,7 @@ spec: - service type: object required: - - endpointURI + - endpointURL - port - scheme - target diff --git a/internal/controller/bindings/boundendpoint_controller.go b/internal/controller/bindings/boundendpoint_controller.go index 72204fb34..857ac4a72 100644 --- a/internal/controller/bindings/boundendpoint_controller.go +++ b/internal/controller/bindings/boundendpoint_controller.go @@ -254,7 +254,7 @@ func (r *BoundEndpointReconciler) update(ctx context.Context, cr *bindingsv1alph if err != nil { if client.IgnoreNotFound(err) != nil { // real error - log.Error(err, "Failed to find existing Upstream Service", "name", cr.Name, "uri", cr.Spec.EndpointURI) + log.Error(err, "Failed to find existing Upstream Service", "name", cr.Name, "url", cr.Spec.EndpointURL) return r.updateStatus(ctx, cr, err) } @@ -284,7 +284,7 @@ func (r *BoundEndpointReconciler) update(ctx context.Context, cr *bindingsv1alph if err != nil { if client.IgnoreNotFound(err) != nil { // real error - log.Error(err, "Failed to find existing Target Service", "name", cr.Name, "uri", cr.Spec.EndpointURI) + log.Error(err, "Failed to find existing Target Service", "name", cr.Name, "url", cr.Spec.EndpointURL) return r.updateStatus(ctx, cr, err) } @@ -528,7 +528,7 @@ func (r *BoundEndpointReconciler) findBoundEndpointsForService(ctx context.Conte // tryToBindEndpoint attempts a TCP connection through the provisioned services for the BoundEndpoint func (r *BoundEndpointReconciler) testBoundEndpointConnectivity(ctx context.Context, boundEndpoint *bindingsv1alpha1.BoundEndpoint) error { - log := ctrl.LoggerFrom(ctx).WithValues("uri", boundEndpoint.Spec.EndpointURI) + log := ctrl.LoggerFrom(ctx).WithValues("url", boundEndpoint.Spec.EndpointURL) bindErrMsg := fmt.Sprintf("connectivity check failed for BoundEndpoint %s", boundEndpoint.Name) @@ -540,17 +540,17 @@ func (r *BoundEndpointReconciler) testBoundEndpointConnectivity(ctx context.Cont retries := 8 // rely on kube-dns to resolve the targetService's ExternalName - uri, err := url.Parse(boundEndpoint.Spec.EndpointURI) + uri, err := url.Parse(boundEndpoint.Spec.EndpointURL) if err != nil { - wrappedErr := fmt.Errorf("failed to parse BoundEndpoint URI %s: %w", boundEndpoint.Spec.EndpointURI, err) - log.Error(wrappedErr, bindErrMsg, "uri", boundEndpoint.Spec.EndpointURI) + wrappedErr := fmt.Errorf("failed to parse BoundEndpoint URL %s: %w", boundEndpoint.Spec.EndpointURL, err) + log.Error(wrappedErr, bindErrMsg, "url", boundEndpoint.Spec.EndpointURL) return wrappedErr } for i := range retries { select { case <-ctx.Done(): - err = errors.New("attempting to connect to BoundEndpoint URI timed out") + err = errors.New("attempting to connect to BoundEndpoint URL timed out") log.Error(err, bindErrMsg) return err diff --git a/internal/controller/bindings/boundendpoint_poller.go b/internal/controller/bindings/boundendpoint_poller.go index 6238be3de..e83ded164 100644 --- a/internal/controller/bindings/boundendpoint_poller.go +++ b/internal/controller/bindings/boundendpoint_poller.go @@ -310,8 +310,8 @@ func (r *BoundEndpointPoller) reconcileBoundEndpointAction(ctx context.Context, // 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 BoundEndpoint", "action", actionMsg, "name", name, "uri", binding.Spec.EndpointURI) + name := hashURL(binding.Spec.EndpointURL) + log.Error(err, "Failed to reconcile BoundEndpoint", "action", actionMsg, "name", name, "url", binding.Spec.EndpointURL) failedBindings = append(failedBindings, binding) } } @@ -336,10 +336,10 @@ func (r *BoundEndpointPoller) filterBoundEndpointActions(ctx context.Context, ex log.V(9).Info("Filtering BoundEndpoints", "existing", existingBoundEndpoints, "desired", desiredEndpoints) for _, existingBoundEndpoint := range existingBoundEndpoints { - uri := existingBoundEndpoint.Spec.EndpointURI + endpointURL := existingBoundEndpoint.Spec.EndpointURL - if desiredBoundEndpoint, ok := desiredEndpoints[uri]; ok { - expectedName := hashURI(desiredBoundEndpoint.Spec.EndpointURI) + if desiredBoundEndpoint, ok := desiredEndpoints[endpointURL]; ok { + expectedName := hashURL(desiredBoundEndpoint.Spec.EndpointURL) // if the names match, then they are the same resource and we can update it if existingBoundEndpoint.Name == expectedName { @@ -359,7 +359,7 @@ func (r *BoundEndpointPoller) filterBoundEndpointActions(ctx context.Context, ex // remove the desired endpoint from the set // so we can see which endpoints are net-new - delete(desiredEndpoints, uri) + delete(desiredEndpoints, endpointURL) } for _, desiredBoundEndpoint := range desiredEndpoints { @@ -374,12 +374,12 @@ func (r *BoundEndpointPoller) filterBoundEndpointActions(ctx context.Context, ex func (r *BoundEndpointPoller) createBinding(ctx context.Context, desired bindingsv1alpha1.BoundEndpoint) error { log := ctrl.LoggerFrom(ctx) - name := hashURI(desired.Spec.EndpointURI) + name := hashURL(desired.Spec.EndpointURL) // allocate a port port, err := r.portAllocator.SetAny() if err != nil { - r.Log.Error(err, "Failed to allocate port for BoundEndpoint", "name", name, "uri", desired.Spec.EndpointURI) + r.Log.Error(err, "Failed to allocate port for BoundEndpoint", "name", name, "url", desired.Spec.EndpointURL) return err } @@ -393,7 +393,7 @@ func (r *BoundEndpointPoller) createBinding(ctx context.Context, desired binding Namespace: r.Namespace, }, Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: desired.Spec.EndpointURI, + EndpointURL: desired.Spec.EndpointURL, Scheme: desired.Spec.Scheme, Port: port, Target: bindingsv1alpha1.EndpointTarget{ @@ -409,15 +409,15 @@ func (r *BoundEndpointPoller) createBinding(ctx context.Context, desired binding }, } - log.Info("Creating new BoundEndpoint", "name", name, "uri", toCreate.Spec.EndpointURI) + log.Info("Creating new BoundEndpoint", "name", name, "url", toCreate.Spec.EndpointURL) if err := r.Create(ctx, toCreate); err != nil { if client.IgnoreAlreadyExists(err) != nil { - log.Error(err, "Failed to create BoundEndpoint", "name", name, "uri", toCreate.Spec.EndpointURI) + log.Error(err, "Failed to create BoundEndpoint", "name", name, "url", toCreate.Spec.EndpointURL) r.Recorder.Event(toCreate, v1.EventTypeWarning, "Created", fmt.Sprintf("Failed to create BoundEndpoint: %v", err)) return err } - log.Info("BoundEndpoint already exists, skipping create...", "name", name, "uri", toCreate.Spec.EndpointURI) + log.Info("BoundEndpoint already exists, skipping create...", "name", name, "url", toCreate.Spec.EndpointURL) if toCreate.Status.HashedName != "" && len(toCreate.Status.Endpoints) > 0 { // Status is filled, no need to update @@ -425,10 +425,10 @@ func (r *BoundEndpointPoller) createBinding(ctx context.Context, desired binding } // intentionally fall through and fill in status - log.Info("BoundEndpoint 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, "url", toCreate.Spec.EndpointURL, "toCreate", toCreate) if err := r.Get(ctx, client.ObjectKey{Namespace: r.Namespace, Name: name}, toCreate); err != nil { - log.Error(err, "Failed to get existing BoundEndpoint, skipping status update...", "name", name, "uri", toCreate.Spec.EndpointURI) + log.Error(err, "Failed to get existing BoundEndpoint, skipping status update...", "name", name, "url", toCreate.Spec.EndpointURL) return nil } } @@ -463,7 +463,7 @@ func (r *BoundEndpointPoller) createBinding(ctx context.Context, desired binding func (r *BoundEndpointPoller) updateBinding(ctx context.Context, desired bindingsv1alpha1.BoundEndpoint) error { log := ctrl.LoggerFrom(ctx) - desiredName := hashURI(desired.Spec.EndpointURI) + desiredName := hashURL(desired.Spec.EndpointURL) // Attach the metadata fields to the desired boundendpoint desired.Spec.Target.Metadata.Annotations = r.TargetServiceAnnotations @@ -474,16 +474,16 @@ func (r *BoundEndpointPoller) updateBinding(ctx context.Context, desired binding if err != nil { if client.IgnoreNotFound(err) == nil { // 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) + log.Info("Unable to find existing BoundEndpoint, skipping update...", "name", desiredName, "url", desired.Spec.EndpointURL) return nil // not an error } // real error - log.Error(err, "Failed to find existing BoundEndpoint", "name", desiredName, "uri", desired.Spec.EndpointURI) + log.Error(err, "Failed to find existing BoundEndpoint", "name", desiredName, "url", desired.Spec.EndpointURL) return err } if !boundEndpointNeedsUpdate(ctx, *existing, desired) { - log.Info("BoundEndpoint already matches existing state, skipping update...", "name", desiredName, "uri", desired.Spec.EndpointURI) + log.Info("BoundEndpoint already matches existing state, skipping update...", "name", desiredName, "url", desired.Spec.EndpointURL) return nil } @@ -493,11 +493,11 @@ func (r *BoundEndpointPoller) updateBinding(ctx context.Context, desired binding toUpdate.Spec.Port = existing.Spec.Port // keep the same port toUpdate.Spec.Scheme = desired.Spec.Scheme toUpdate.Spec.Target = desired.Spec.Target - toUpdate.Spec.EndpointURI = desired.Spec.EndpointURI + toUpdate.Spec.EndpointURL = desired.Spec.EndpointURL - log.Info("Updating BoundEndpoint", "name", toUpdate.Name, "uri", toUpdate.Spec.EndpointURI) + log.Info("Updating BoundEndpoint", "name", toUpdate.Name, "url", toUpdate.Spec.EndpointURL) if err := r.Update(ctx, toUpdate); err != nil { - log.Error(err, "Failed updating BoundEndpoint", "name", toUpdate.Name, "uri", toUpdate.Spec.EndpointURI) + log.Error(err, "Failed updating BoundEndpoint", "name", toUpdate.Name, "url", toUpdate.Spec.EndpointURL) r.Recorder.Event(toUpdate, v1.EventTypeWarning, "Updated", fmt.Sprintf("Failed to update BoundEndpoint: %v", err)) return err } @@ -533,10 +533,10 @@ func (r *BoundEndpointPoller) deleteBinding(ctx context.Context, boundEndpoint b log := ctrl.LoggerFrom(ctx) if err := r.Delete(ctx, &boundEndpoint); err != nil { - log.Error(err, "Failed to delete BoundEndpoint", "name", boundEndpoint.Name, "uri", boundEndpoint.Spec.EndpointURI) + log.Error(err, "Failed to delete BoundEndpoint", "name", boundEndpoint.Name, "url", boundEndpoint.Spec.EndpointURL) return err } - log.Info("Deleted BoundEndpoint", "name", boundEndpoint.Name, "uri", boundEndpoint.Spec.EndpointURI) + log.Info("Deleted BoundEndpoint", "name", boundEndpoint.Name, "url", boundEndpoint.Spec.EndpointURL) // unset the port allocation r.portAllocator.Unset(boundEndpoint.Spec.Port) @@ -561,11 +561,11 @@ func (r *BoundEndpointPoller) updateBindingStatus(ctx context.Context, desired * current.Status.HashedName = desired.Status.HashedName if err := r.Status().Update(ctx, current); err != nil { - log.Error(err, "Failed to update BoundEndpoint status", "name", current.Name, "uri", current.Spec.EndpointURI) + log.Error(err, "Failed to update BoundEndpoint status", "name", current.Name, "uri", current.Spec.EndpointURL) return err } - log.Info("Updated BoundEndpoint status", "name", current.Name, "uri", current.Spec.EndpointURI) + log.Info("Updated BoundEndpoint status", "name", current.Name, "uri", current.Spec.EndpointURL) return nil } @@ -625,7 +625,7 @@ func boundEndpointNeedsUpdate(ctx context.Context, existing bindingsv1alpha1.Bou existing.Spec.Target.Protocol != desired.Spec.Target.Protocol || existing.Spec.Target.Service != desired.Spec.Target.Service || existing.Spec.Target.Namespace != desired.Spec.Target.Namespace || - existing.Spec.EndpointURI != desired.Spec.EndpointURI || + existing.Spec.EndpointURL != desired.Spec.EndpointURL || !targetMetadataIsEqual(existing.Spec.Target.Metadata, desired.Spec.Target.Metadata) if hasSpecChanged { @@ -654,8 +654,8 @@ func boundEndpointNeedsUpdate(ctx context.Context, existing bindingsv1alpha1.Bou return false } -// 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)) +// hashURL hashes a URL to a unique string that can be used as BoundEndpoint.metadata.name +func hashURL(url string) string { + uid := uuid.NewSHA1(uuid.NameSpaceURL, []byte(url)) return "ngrok-" + uid.String() } diff --git a/internal/controller/bindings/boundendpoint_poller_test.go b/internal/controller/bindings/boundendpoint_poller_test.go index e977af843..ac6ab69bf 100644 --- a/internal/controller/bindings/boundendpoint_poller_test.go +++ b/internal/controller/bindings/boundendpoint_poller_test.go @@ -22,30 +22,30 @@ func Test_BoundEndpointPoller_filterBoundEndpointActions(t *testing.T) { uriExample1 := "http://service1.namespace1:8080" epdExample1 := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ - Name: hashURI(uriExample1), + Name: hashURL(uriExample1), }, Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: uriExample1, + EndpointURL: uriExample1, }, } uriExample2 := "https://service2.namespace2:443" epdExample2 := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ - Name: hashURI(uriExample2), + Name: hashURL(uriExample2), }, Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: uriExample2, + EndpointURL: uriExample2, }, } uriExample3 := "https://service3.namespace3:443" epdExample3 := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ - Name: hashURI(uriExample3), + Name: hashURL(uriExample3), }, Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: uriExample3, + EndpointURL: uriExample3, }, } @@ -56,7 +56,7 @@ func Test_BoundEndpointPoller_filterBoundEndpointActions(t *testing.T) { Name: "abcd1234-abcd-1234-abcd-1234abcd1234", }, Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: uriExample3, // example 3 on purpose, see Name + EndpointURL: uriExample3, // example 3 on purpose, see Name }, } @@ -168,10 +168,10 @@ func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { uriExample1 := "http://service1.namespace1:8080" epdExample1 := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ - Name: hashURI(uriExample1), + Name: hashURL(uriExample1), }, Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: uriExample1, + EndpointURL: uriExample1, Target: bindingsv1alpha1.EndpointTarget{ Namespace: "namespace1", Service: "service1", @@ -180,7 +180,7 @@ func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { }, }, Status: bindingsv1alpha1.BoundEndpointStatus{ - HashedName: hashURI(uriExample1), + HashedName: hashURL(uriExample1), Endpoints: []bindingsv1alpha1.BindingEndpoint{ { Ref: ngrok.Ref{ID: "ep_abc123", URI: "example-uri"}, @@ -191,10 +191,10 @@ func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { epdExample1NewMetadata := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ - Name: hashURI(uriExample1), + Name: hashURL(uriExample1), }, Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: uriExample1, + EndpointURL: uriExample1, Target: bindingsv1alpha1.EndpointTarget{ Namespace: "namespace1", Service: "service1", @@ -211,7 +211,7 @@ func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { }, }, Status: bindingsv1alpha1.BoundEndpointStatus{ - HashedName: hashURI(uriExample1), + HashedName: hashURL(uriExample1), Endpoints: []bindingsv1alpha1.BindingEndpoint{ { Ref: ngrok.Ref{ID: "ep_abc123", URI: "example-uri"}, @@ -222,10 +222,10 @@ func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { epdExample1EmptyMetadata := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ - Name: hashURI(uriExample1), + Name: hashURL(uriExample1), }, Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: uriExample1, + EndpointURL: uriExample1, Target: bindingsv1alpha1.EndpointTarget{ Namespace: "namespace1", Service: "service1", @@ -238,7 +238,7 @@ func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { }, }, Status: bindingsv1alpha1.BoundEndpointStatus{ - HashedName: hashURI(uriExample1), + HashedName: hashURL(uriExample1), Endpoints: []bindingsv1alpha1.BindingEndpoint{ { Ref: ngrok.Ref{ID: "ep_abc123", URI: "example-uri"}, @@ -250,10 +250,10 @@ func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { uriExample2 := "https://service2.namespace2:443" epdExample2 := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ - Name: hashURI(uriExample2), + Name: hashURL(uriExample2), }, Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: uriExample2, + EndpointURL: uriExample2, Target: bindingsv1alpha1.EndpointTarget{ Namespace: "namespace2", Service: "service2", @@ -262,7 +262,7 @@ func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { }, }, Status: bindingsv1alpha1.BoundEndpointStatus{ - HashedName: hashURI(uriExample2), + HashedName: hashURL(uriExample2), Endpoints: []bindingsv1alpha1.BindingEndpoint{ { Ref: ngrok.Ref{ID: "ep_def456", URI: "example-uri"}, @@ -273,10 +273,10 @@ func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { epdExample2NewStatus := bindingsv1alpha1.BoundEndpoint{ ObjectMeta: metav1.ObjectMeta{ - Name: hashURI(uriExample2), + Name: hashURL(uriExample2), }, Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: uriExample2, + EndpointURL: uriExample2, Target: bindingsv1alpha1.EndpointTarget{ Namespace: "namespace2", Service: "service2", @@ -285,7 +285,7 @@ func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { }, }, Status: bindingsv1alpha1.BoundEndpointStatus{ - HashedName: hashURI(uriExample2), + HashedName: hashURL(uriExample2), Endpoints: []bindingsv1alpha1.BindingEndpoint{ { Ref: ngrok.Ref{ID: "ep_def456", URI: "example-uri"}, @@ -349,14 +349,14 @@ func Test_BoundEndpointPoller_boundEndpointNeedsUpdate(t *testing.T) { } } -func Test_BoundEndpointPoller_hashURI(t *testing.T) { +func Test_BoundEndpointPoller_hashURL(t *testing.T) { assert := assert.New(t) - endpointURI := "http://service.namespace:8080" + endpointURL := "http://service.namespace:8080" // hash must be consistent for i := 0; i < 100; i++ { - hashed := hashURI(endpointURI) + hashed := hashURL(endpointURL) // ensure hashed name meets k8s DNS naming requirements assert.True(len(hashed) <= 63) diff --git a/internal/controller/bindings/forwarder_controller.go b/internal/controller/bindings/forwarder_controller.go index a6bef98f2..9279c85eb 100644 --- a/internal/controller/bindings/forwarder_controller.go +++ b/internal/controller/bindings/forwarder_controller.go @@ -197,13 +197,13 @@ func (r *ForwarderReconciler) update(ctx context.Context, epb *bindingsv1alpha1. tlsDialer.Config.RootCAs = r.RootCAs } - endpointURI, err := url.Parse(epb.Spec.EndpointURI) + endpointURL, err := url.Parse(epb.Spec.EndpointURL) if err != nil { return err } - host := endpointURI.Hostname() - port, err := strconv.Atoi(endpointURI.Port()) + host := endpointURL.Hostname() + port, err := strconv.Atoi(endpointURL.Port()) if err != nil { return err } @@ -223,7 +223,7 @@ func (r *ForwarderReconciler) update(ctx context.Context, epb *bindingsv1alpha1. }, "binding", map[string]string{ "host": host, - "port": endpointURI.Port(), + "port": endpointURL.Port(), }, ) diff --git a/internal/ngrokapi/bindingendpoint_aggregator.go b/internal/ngrokapi/bindingendpoint_aggregator.go index 5704d4cb0..fd5c70f77 100644 --- a/internal/ngrokapi/bindingendpoint_aggregator.go +++ b/internal/ngrokapi/bindingendpoint_aggregator.go @@ -35,18 +35,18 @@ func AggregateBindingEndpoints(endpoints []ngrok.Endpoint) (AggregatedEndpoints, return nil, fmt.Errorf("failed to parse endpoint: %s: %w", endpoint.ID, err) } - endpointURI := parsed.String() + endpointURL := parsed.String() // Create a new BindingEndpoint if one doesn't exist var bindingEndpoint bindingsv1alpha1.BoundEndpoint - if val, ok := aggregated[endpointURI]; ok { + if val, ok := aggregated[endpointURL]; ok { bindingEndpoint = val } else { // newly found hostport, create a new BoundEndpoint bindingEndpoint = bindingsv1alpha1.BoundEndpoint{ // parsed bits are shared across endpoints with the same hostport Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: endpointURI, + EndpointURL: endpointURL, Scheme: parsed.Scheme, Target: bindingsv1alpha1.EndpointTarget{ Service: parsed.ServiceName, @@ -70,7 +70,7 @@ func AggregateBindingEndpoints(endpoints []ngrok.Endpoint) (AggregatedEndpoints, }) // update the aggregated map - aggregated[endpointURI] = bindingEndpoint + aggregated[endpointURL] = bindingEndpoint } return aggregated, nil @@ -84,7 +84,7 @@ type parsedHostport struct { Port int32 } -// String prints the parsed hostport as a EndpointURI in the format: ://.: +// String prints the parsed hostport as a EndpointURL in the format: ://.: func (p *parsedHostport) String() string { return fmt.Sprintf("%s://%s.%s:%d", p.Scheme, p.ServiceName, p.Namespace, p.Port) } diff --git a/internal/ngrokapi/bindingendpoint_aggregator_test.go b/internal/ngrokapi/bindingendpoint_aggregator_test.go index 75c31b7fe..e655e416c 100644 --- a/internal/ngrokapi/bindingendpoint_aggregator_test.go +++ b/internal/ngrokapi/bindingendpoint_aggregator_test.go @@ -65,7 +65,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { want: AggregatedEndpoints{ "https://service1.namespace1:443": { Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: "https://service1.namespace1:443", + EndpointURL: "https://service1.namespace1:443", Scheme: "https", Target: bindingsv1alpha1.EndpointTarget{ Service: "service1", @@ -97,7 +97,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { want: AggregatedEndpoints{ "https://service1.namespace1:443": { Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: "https://service1.namespace1:443", + EndpointURL: "https://service1.namespace1:443", Scheme: "https", Target: bindingsv1alpha1.EndpointTarget{ Service: "service1", @@ -116,7 +116,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { }, "tcp://service2.namespace2:2020": { Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: "tcp://service2.namespace2:2020", + EndpointURL: "tcp://service2.namespace2:2020", Scheme: "tcp", Target: bindingsv1alpha1.EndpointTarget{ Service: "service2", @@ -134,7 +134,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { }, "https://service3.namespace3:443": { Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: "https://service3.namespace3:443", + EndpointURL: "https://service3.namespace3:443", Scheme: "https", Target: bindingsv1alpha1.EndpointTarget{ Service: "service3", @@ -151,7 +151,7 @@ func Test_AggregateBindingEndpoints(t *testing.T) { }, "http://service4.namespace4:8080": { Spec: bindingsv1alpha1.BoundEndpointSpec{ - EndpointURI: "http://service4.namespace4:8080", + EndpointURL: "http://service4.namespace4:8080", Scheme: "http", Target: bindingsv1alpha1.EndpointTarget{ Service: "service4", diff --git a/tests/chainsaw-uninstall/bindings-delete-policy/chainsaw-test.yaml b/tests/chainsaw-uninstall/bindings-delete-policy/chainsaw-test.yaml index 75301edb4..1b74326db 100644 --- a/tests/chainsaw-uninstall/bindings-delete-policy/chainsaw-test.yaml +++ b/tests/chainsaw-uninstall/bindings-delete-policy/chainsaw-test.yaml @@ -142,13 +142,13 @@ spec: BE_NAME=$(kubectl get boundendpoint -n uninstall-test -o jsonpath='{.items[0].metadata.name}') echo "BoundEndpoint name: $BE_NAME" - # Verify the endpoint URI matches our CloudEndpoint - ENDPOINT_URI=$(kubectl get boundendpoint "$BE_NAME" -n uninstall-test -o jsonpath='{.spec.endpointURI}') - echo "Endpoint URI: $ENDPOINT_URI" - if echo "$ENDPOINT_URI" | grep -q "bound-test-svc.bound-target-ns"; then - echo "✓ BoundEndpoint has correct endpoint URI" + # Verify the endpoint URL matches our CloudEndpoint + ENDPOINT_URL=$(kubectl get boundendpoint "$BE_NAME" -n uninstall-test -o jsonpath='{.spec.endpointURL}') + echo "Endpoint URL: $ENDPOINT_URL" + if echo "$ENDPOINT_URL" | grep -q "bound-test-svc.bound-target-ns"; then + echo "✓ BoundEndpoint has correct endpoint URL" else - echo "✗ BoundEndpoint has unexpected endpoint URI: $ENDPOINT_URI" + echo "✗ BoundEndpoint has unexpected endpoint URL: $ENDPOINT_URL" exit 1 fi