Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 76
fix: identical endpoint name conflicts#1521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
04aa51a08a1a5e88e0d3cd9682c94879878dc0a395c7ddd7491f10149de6b51338237f654ee0144d04a81ea13cf7a5ff10d899dfbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -16,9 +16,14 @@ | ||
| package solvers | ||
| import ( | ||
| "context" | ||
| controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1" | ||
| "github.com/devfile/devworkspace-operator/pkg/common" | ||
| "github.com/devfile/devworkspace-operator/pkg/constants" | ||
| "github.com/go-logr/logr" | ||
| "k8s.io/apimachinery/pkg/api/errors" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| routeV1 "github.com/openshift/api/route/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| @@ -29,14 +34,15 @@ import ( | ||
| ) | ||
| type DevWorkspaceMetadata struct { | ||
| DevWorkspaceId string | ||
| Namespace string | ||
| PodSelector map[string]string | ||
| DevWorkspaceId string | ||
| DevWorkspaceName string | ||
| Namespace string | ||
| PodSelector map[string]string | ||
| } | ||
| // GetDiscoverableServicesForEndpoints converts the endpoint list into a set of services, each corresponding to a single discoverable | ||
| // endpoint from the list. Endpoints with the NoneEndpointExposure are ignored. | ||
| func GetDiscoverableServicesForEndpoints(endpoints map[string]controllerv1alpha1.EndpointList, meta DevWorkspaceMetadata) []corev1.Service { | ||
| func GetDiscoverableServicesForEndpoints(endpoints map[string]controllerv1alpha1.EndpointList, meta DevWorkspaceMetadata, cl client.Client, log logr.Logger) ([]corev1.Service, error) { | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @akurinnoy is there a reason for implementing duplicate endpiont detection in both the webhook and the
| ||
| var services []corev1.Service | ||
| for _, machineEndpoints := range endpoints { | ||
| for _, endpoint := range machineEndpoints { | ||
| @@ -45,21 +51,36 @@ func GetDiscoverableServicesForEndpoints(endpoints map[string]controllerv1alpha1 | ||
| } | ||
| if endpoint.Attributes.GetBoolean(string(controllerv1alpha1.DiscoverableAttribute), nil) { | ||
| // Create service with name matching endpoint | ||
| // TODO: This could cause a reconcile conflict if multiple workspaces define the same discoverable endpoint | ||
| // Also endpoint names may not be valid as service names | ||
| serviceName := common.EndpointName(endpoint.Name) | ||
| existingService := &corev1.Service{} | ||
| err := cl.Get(context.TODO(), client.ObjectKey{Name: serviceName, Namespace: meta.Namespace}, existingService) | ||
| if err != nil { | ||
| if !errors.IsNotFound(err) { | ||
| log.Error(err, "Failed to get service from cluster", "serviceName", serviceName) | ||
| return nil, err | ||
| } | ||
| } else { | ||
| if existingService.Labels[constants.DevWorkspaceIDLabel] != meta.DevWorkspaceId { | ||
| return nil, &ServiceConflictError{ | ||
| EndpointName: endpoint.Name, | ||
| WorkspaceName: existingService.Labels[constants.DevWorkspaceNameLabel], | ||
| } | ||
| } | ||
| } | ||
| servicePort := corev1.ServicePort{ | ||
| Name: common.EndpointName(endpoint.Name), | ||
| Name: serviceName, | ||
| Protocol: corev1.ProtocolTCP, | ||
| Port: int32(endpoint.TargetPort), | ||
| TargetPort: intstr.FromInt(endpoint.TargetPort), | ||
| } | ||
| services = append(services, corev1.Service{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: common.EndpointName(endpoint.Name), | ||
| Name: serviceName, | ||
| Namespace: meta.Namespace, | ||
| Labels: map[string]string{ | ||
| constants.DevWorkspaceIDLabel: meta.DevWorkspaceId, | ||
| constants.DevWorkspaceIDLabel: meta.DevWorkspaceId, | ||
| constants.DevWorkspaceNameLabel: meta.DevWorkspaceName, | ||
| }, | ||
| Annotations: map[string]string{ | ||
| constants.DevWorkspaceDiscoverableServiceAnnotation: "true", | ||
| @@ -74,7 +95,7 @@ func GetDiscoverableServicesForEndpoints(endpoints map[string]controllerv1alpha1 | ||
| } | ||
| } | ||
| } | ||
| return services | ||
| return services, nil | ||
| } | ||
| // GetServiceForEndpoints returns a single service that exposes all endpoints of given exposure types, possibly also including the discoverable types. | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.