mirror of
https://github.com/ngrok/ngrok-operator.git
synced 2026-05-17 16:50:44 +00:00
URI vs URL inconsistency (#779)
* URI vs URL inconsistency * Depecating slowly
This commit is contained in:
@@ -35,14 +35,19 @@ 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: <scheme>://<service>.<namespace>:<port>
|
||||
//
|
||||
// +kubebuilder:validation:Required
|
||||
// +kubebuilder:validation:Optional
|
||||
// See: https://regex101.com/r/9QkXWl/1
|
||||
// +kubebuilder:validation:Pattern=`^((?P<scheme>(tcp|http|https|tls)?)://)?(?P<service>[a-z][a-zA-Z0-9-]{0,62})\.(?P<namespace>[a-z][a-zA-Z0-9-]{0,62})(:(?P<port>\d+))?$`
|
||||
EndpointURI string `json:"endpointURI"`
|
||||
EndpointURL string `json:"endpointURL,omitempty"`
|
||||
|
||||
// Deprecated: Use EndpointURL instead. Will be removed in a future release.
|
||||
// +kubebuilder:validation:Optional
|
||||
// +kubebuilder:validation:Pattern=`^((?P<scheme>(tcp|http|https|tls)?)://)?(?P<service>[a-z][a-zA-Z0-9-]{0,62})\.(?P<namespace>[a-z][a-zA-Z0-9-]{0,62})(:(?P<port>\d+))?$`
|
||||
EndpointURI string `json:"endpointURI,omitempty"`
|
||||
|
||||
// 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
|
||||
@@ -60,6 +65,14 @@ type BoundEndpointSpec struct {
|
||||
Target EndpointTarget `json:"target"`
|
||||
}
|
||||
|
||||
// GetEndpointURL returns EndpointURL if set, falling back to the deprecated EndpointURI field.
|
||||
func (s *BoundEndpointSpec) GetEndpointURL() string {
|
||||
if s.EndpointURL != "" {
|
||||
return s.EndpointURL
|
||||
}
|
||||
return s.EndpointURI
|
||||
}
|
||||
|
||||
// BoundEndpointStatus defines the observed state of BoundEndpoint
|
||||
type BoundEndpointStatus struct {
|
||||
// Endpoints is the list of ngrok API endpoint references bound to this BoundEndpoint
|
||||
@@ -138,7 +151,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"
|
||||
|
||||
@@ -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
|
||||
@@ -60,8 +60,13 @@ spec:
|
||||
description: BoundEndpointSpec defines the desired state of BoundEndpoint
|
||||
properties:
|
||||
endpointURI:
|
||||
description: 'Deprecated: Use EndpointURL instead. Will be removed
|
||||
in a future release.'
|
||||
pattern: ^((?P<scheme>(tcp|http|https|tls)?)://)?(?P<service>[a-z][a-zA-Z0-9-]{0,62})\.(?P<namespace>[a-z][a-zA-Z0-9-]{0,62})(:(?P<port>\d+))?$
|
||||
type: string
|
||||
endpointURL:
|
||||
description: |-
|
||||
EndpointURI is the unique identifier
|
||||
EndpointURL is the unique identifier
|
||||
representing the BoundEndpoint + its Endpoints
|
||||
Format: <scheme>://<service>.<namespace>:<port>
|
||||
|
||||
@@ -136,7 +141,6 @@ spec:
|
||||
- service
|
||||
type: object
|
||||
required:
|
||||
- endpointURI
|
||||
- port
|
||||
- scheme
|
||||
- target
|
||||
|
||||
@@ -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.GetEndpointURL())
|
||||
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.GetEndpointURL())
|
||||
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.GetEndpointURL())
|
||||
|
||||
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.GetEndpointURL())
|
||||
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.GetEndpointURL(), err)
|
||||
log.Error(wrappedErr, bindErrMsg, "url", boundEndpoint.Spec.GetEndpointURL())
|
||||
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
|
||||
|
||||
|
||||
@@ -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.GetEndpointURL())
|
||||
log.Error(err, "Failed to reconcile BoundEndpoint", "action", actionMsg, "name", name, "url", binding.Spec.GetEndpointURL())
|
||||
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.GetEndpointURL()
|
||||
|
||||
if desiredBoundEndpoint, ok := desiredEndpoints[uri]; ok {
|
||||
expectedName := hashURI(desiredBoundEndpoint.Spec.EndpointURI)
|
||||
if desiredBoundEndpoint, ok := desiredEndpoints[endpointURL]; ok {
|
||||
expectedName := hashURL(desiredBoundEndpoint.Spec.GetEndpointURL())
|
||||
|
||||
// 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.GetEndpointURL())
|
||||
|
||||
// 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.GetEndpointURL())
|
||||
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.GetEndpointURL(),
|
||||
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.GetEndpointURL())
|
||||
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.GetEndpointURL())
|
||||
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.GetEndpointURL())
|
||||
|
||||
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.GetEndpointURL(), "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.GetEndpointURL())
|
||||
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.GetEndpointURL())
|
||||
|
||||
// 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.GetEndpointURL())
|
||||
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.GetEndpointURL())
|
||||
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.GetEndpointURL())
|
||||
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.GetEndpointURL()
|
||||
|
||||
log.Info("Updating BoundEndpoint", "name", toUpdate.Name, "uri", toUpdate.Spec.EndpointURI)
|
||||
log.Info("Updating BoundEndpoint", "name", toUpdate.Name, "url", toUpdate.Spec.GetEndpointURL())
|
||||
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.GetEndpointURL())
|
||||
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.GetEndpointURL())
|
||||
return err
|
||||
}
|
||||
log.Info("Deleted BoundEndpoint", "name", boundEndpoint.Name, "uri", boundEndpoint.Spec.EndpointURI)
|
||||
log.Info("Deleted BoundEndpoint", "name", boundEndpoint.Name, "url", boundEndpoint.Spec.GetEndpointURL())
|
||||
|
||||
// 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.GetEndpointURL())
|
||||
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.GetEndpointURL())
|
||||
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.GetEndpointURL() != desired.Spec.GetEndpointURL() ||
|
||||
!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()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.GetEndpointURL())
|
||||
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(),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -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: <scheme>://<service>.<namespace>:<port>
|
||||
// String prints the parsed hostport as a EndpointURL in the format: <scheme>://<service>.<namespace>:<port>
|
||||
func (p *parsedHostport) String() string {
|
||||
return fmt.Sprintf("%s://%s.%s:%d", p.Scheme, p.ServiceName, p.Namespace, p.Port)
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user