Skip to content

Commit

Permalink
Fix port mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Nov 1, 2021
1 parent ffccf87 commit 438daf9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
21 changes: 13 additions & 8 deletions components/ws-manager/pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ type startWorkspaceContext struct {
}

const (
// theiaVolume is the name of the theia volume
theiaVolumeName = "vol-this-theia"
// workspaceVolume is the name of the workspace volume
workspaceVolumeName = "vol-this-workspace"
// workspaceDir is the path within all containers where workspaceVolume is mounted to
Expand Down Expand Up @@ -548,25 +546,32 @@ func (m *Manager) ControlPort(ctx context.Context, req *api.ControlPortRequest)
return nil, xerrors.Errorf("cannot render public URL for %d: %w", port, err)
}

portSpec := api.PortSpec{
portSpec := &api.PortSpec{
Port: uint32(port),
Visibility: api.PortVisibility_PORT_VISIBILITY_PUBLIC,
Target: req.Spec.Target,
Target: port,
Url: url,
}

if !req.Expose {
portSpec.Visibility = api.PortVisibility_PORT_VISIBILITY_PRIVATE
}

exposedPorts.Ports = append(exposedPorts.Ports, &portSpec)
if req.Spec.Target != 0 {
portSpec.Target = req.Spec.Target
}

exposedPorts.Ports = append(exposedPorts.Ports, portSpec)
} else {
exposedPorts.Ports[existingPortSpecIdx].Target = req.Spec.Target
exposedPorts.Ports[existingPortSpecIdx].Target = port
exposedPorts.Ports[existingPortSpecIdx].Visibility = api.PortVisibility_PORT_VISIBILITY_PRIVATE

if req.Spec.Target != 0 {
exposedPorts.Ports[existingPortSpecIdx].Target = req.Spec.Target
}

if req.Expose {
exposedPorts.Ports[existingPortSpecIdx].Visibility = api.PortVisibility_PORT_VISIBILITY_PUBLIC
} else {
exposedPorts.Ports[existingPortSpecIdx].Visibility = api.PortVisibility_PORT_VISIBILITY_PRIVATE
}
}

Expand Down
27 changes: 9 additions & 18 deletions components/ws-manager/pkg/manager/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,14 @@ func (m *Manager) completeWorkspaceObjects(ctx context.Context, wso *workspaceOb
return xerrors.Errorf("completeWorkspaceObjects: need either pod or lifecycle independent state")
}

// find pod events - this only makes sense if we still have a pod
if wso.Pod != nil {
if wso.Events == nil && wso.Pod != nil {
events, err := m.RawClient.CoreV1().Events(m.Config.Namespace).Search(scheme, wso.Pod)
if err != nil {
return xerrors.Errorf("completeWorkspaceObjects: %w", err)
}

wso.Events = make([]corev1.Event, len(events.Items))
copy(wso.Events, events.Items)
if wso.Events == nil {
events, err := m.RawClient.CoreV1().Events(m.Config.Namespace).Search(scheme, wso.Pod)
if err != nil {
return xerrors.Errorf("completeWorkspaceObjects: %w", err)
}

wso.Events = make([]corev1.Event, len(events.Items))
copy(wso.Events, events.Items)
}

return nil
Expand Down Expand Up @@ -267,11 +264,7 @@ func (m *Manager) getWorkspaceStatus(wso workspaceObjects) (*api.WorkspaceStatus

status.Spec.ExposedPorts = extractExposedPorts(wso.Pod).Ports

if wso.Pod == nil {
status.Conditions.Deployed = api.WorkspaceConditionBool_FALSE
} else {
status.Conditions.Deployed = api.WorkspaceConditionBool_TRUE
}
status.Conditions.Deployed = api.WorkspaceConditionBool_TRUE

return status, nil
}
Expand Down Expand Up @@ -604,9 +597,7 @@ func extractFailure(wso workspaceObjects) (string, *api.WorkspacePhase) {
}

// ideally we do not just use evt.Message as failure reason because it contains internal paths and is not useful for the user
if strings.Contains(evt.Message, theiaVolumeName) {
return "cannot mount Theia", nil
} else if strings.Contains(evt.Message, workspaceVolumeName) {
if strings.Contains(evt.Message, workspaceVolumeName) {
return "cannot mount workspace", nil
} else {
// if this happens we did not do a good job because that means we've introduced another volume to the pod
Expand Down

0 comments on commit 438daf9

Please sign in to comment.