Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Oct 30, 2021
1 parent 5bf3798 commit 64f4bc9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
3 changes: 3 additions & 0 deletions components/ws-manager/pkg/manager/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const (
// workspaceIDAnnotation is the annotation on the WS pod which contains the workspace ID
workspaceIDAnnotation = "gitpod/id"

// servicePrefixAnnotation is the annotation on the WS pod which contains the service prefix
servicePrefixAnnotation = "gitpod/servicePrefix"

// workspaceURLAnnotation is the annotation on the WS pod which contains the public workspace URL
workspaceURLAnnotation = "gitpod/url"

Expand Down
9 changes: 9 additions & 0 deletions components/ws-manager/pkg/manager/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func (m *Manager) createDefiniteWorkspacePod(startContext *startWorkspaceContext
"prometheus.io/path": "/metrics",
"prometheus.io/port": strconv.Itoa(int(startContext.IDEPort)),
workspaceIDAnnotation: req.Id,
servicePrefixAnnotation: getServicePrefix(req),
workspaceURLAnnotation: startContext.WorkspaceURL,
workspaceInitializerAnnotation: initializerConfig,
workspaceNeverReadyAnnotation: "true",
Expand Down Expand Up @@ -713,6 +714,14 @@ func (m *Manager) newStartWorkspaceContext(ctx context.Context, req *api.StartWo
}, nil
}

func getServicePrefix(req *api.StartWorkspaceRequest) string {
if req.ServicePrefix != "" {
return req.ServicePrefix
}

return req.Id
}

// validCookieChars contains all characters which may occur in an HTTP Cookie value (unicode \u0021 through \u007E),
// without the characters , ; and / ... I did not find more details about permissible characters in RFC2965, so I took
// this list of permissible chars from Wikipedia.
Expand Down
5 changes: 5 additions & 0 deletions components/ws-manager/pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@ func (m *Manager) ControlPort(ctx context.Context, req *api.ControlPortRequest)
}
tracing.ApplyOWI(span, wsk8s.GetOWIFromObject(&pod.ObjectMeta))

servicePrefix, ok := pod.Annotations[servicePrefixAnnotation]
if !ok || servicePrefix == "" {
return nil, xerrors.Errorf("workspace pod %s has no service prefix annotation", pod.Name)
}

notifyStatusChange := func() error {
// by modifying the ports service we have changed the workspace status. However, this status change is not propagated
// through the regular monitor mechanism as we did not modify the pod itself. We have to send out a status update
Expand Down
27 changes: 0 additions & 27 deletions components/ws-manager/pkg/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)
Expand Down Expand Up @@ -60,7 +59,6 @@ func TestControlPort(t *testing.T) {
}
type gold struct {
Error string `json:"error,omitempty"`
PortsService *corev1.Service `json:"portsService,omitempty"`
Response *api.ControlPortResponse `json:"response,omitempty"`
PostChangeStatus []*api.PortSpec `json:"postChangeStatus,omitempty"`
}
Expand Down Expand Up @@ -110,31 +108,6 @@ func TestControlPort(t *testing.T) {
// wait for informer sync of any change introduced by ControlPort
time.Sleep(500 * time.Millisecond)

var svc corev1.Service
_ = manager.Clientset.Get(context.Background(), types.NamespacedName{
Namespace: manager.Config.Namespace,
Name: getPortsServiceName(startCtx.Request.ServicePrefix),
}, &svc)

cleanTemporalAttributes := func(svc *corev1.Service) *corev1.Service {
// only process services from the API server
if svc.ResourceVersion == "" {
return nil
}

copy := svc.DeepCopy()
copy.ObjectMeta.SelfLink = ""
copy.ObjectMeta.ResourceVersion = ""
copy.ObjectMeta.SetCreationTimestamp(metav1.Time{})
copy.ObjectMeta.UID = ""
copy.Spec.ClusterIP = ""
copy.Spec.SessionAffinity = ""

return copy
}

result.PortsService = cleanTemporalAttributes(&svc)

return &result
},
Fixture: func() interface{} { return &fixture{} },
Expand Down

0 comments on commit 64f4bc9

Please sign in to comment.