Skip to content

Commit

Permalink
feat: add WorkspaceStopped method to RoutingSolver
Browse files Browse the repository at this point in the history
Signed-off-by: David Kwon <[email protected]>
  • Loading branch information
dkwon17 committed May 16, 2022
1 parent 1f0c474 commit 5dd5901
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
5 changes: 5 additions & 0 deletions apis/controller/v1alpha1/devworkspacerouting_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1
import (
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/devfile/devworkspace-operator/pkg/constants"
)

// DevWorkspaceRoutingSpec defines the desired state of DevWorkspaceRouting
Expand Down Expand Up @@ -205,3 +206,7 @@ type DevWorkspaceRoutingList struct {
func init() {
SchemeBuilder.Register(&DevWorkspaceRouting{}, &DevWorkspaceRoutingList{})
}

func (d *DevWorkspaceRouting) IsWorkspaceStopped() bool {
return d.Annotations != nil && d.Annotations[constants.DevWorkspaceStartedStatusAnnotation] == "false"
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(ctx context.Context, req ctrl.
return reconcile.Result{}, r.finalize(solver, instance)
}

if instance.Annotations != nil && instance.Annotations[constants.DevWorkspaceStartedStatusAnnotation] == "false" {
return reconcile.Result{}, nil
workspaceMeta := solvers.DevWorkspaceMetadata{
DevWorkspaceId: instance.Spec.DevWorkspaceId,
Namespace: instance.Namespace,
PodSelector: instance.Spec.PodSelector,
}

if instance.IsWorkspaceStopped() {
err := solver.WorkspaceStopped(instance, workspaceMeta)
return reconcile.Result{}, err
}

if instance.Status.Phase == controllerv1alpha1.RoutingFailed {
Expand All @@ -120,12 +127,6 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(ctx context.Context, req ctrl.
return reconcile.Result{}, err
}

workspaceMeta := solvers.DevWorkspaceMetadata{
DevWorkspaceId: instance.Spec.DevWorkspaceId,
Namespace: instance.Namespace,
PodSelector: instance.Spec.PodSelector,
}

restrictedAccess, setRestrictedAccess := instance.Annotations[constants.DevWorkspaceRestrictedAccessAnnotation]
routingObjects, err := solver.GetSpecObjects(instance, workspaceMeta)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ func (s *BasicSolver) GetExposedEndpoints(
routingObj RoutingObjects) (exposedEndpoints map[string]controllerv1alpha1.ExposedEndpointList, ready bool, err error) {
return getExposedEndpoints(endpoints, routingObj)
}

func (s *BasicSolver) WorkspaceStopped(routing *controllerv1alpha1.DevWorkspaceRouting, workspaceMeta DevWorkspaceMetadata) error {
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,7 @@ func getHostnameFromService(service corev1.Service, port int32) string {
}
return fmt.Sprintf("%s://%s.%s.svc:%d", scheme, service.Name, service.Namespace, port)
}

func (s *ClusterSolver) WorkspaceStopped(routing *controllerv1alpha1.DevWorkspaceRouting, workspaceMeta DevWorkspaceMetadata) error {
return nil
}
3 changes: 3 additions & 0 deletions controllers/controller/devworkspacerouting/solvers/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type RoutingSolver interface {
// Return value "ready" specifies if all endpoints are resolved on the cluster; if false it is necessary to retry, as
// URLs will be undefined.
GetExposedEndpoints(endpoints map[string]controllerv1alpha1.EndpointList, routingObj RoutingObjects) (exposedEndpoints map[string]controllerv1alpha1.ExposedEndpointList, ready bool, err error)

// WorkspaceStopped is called when the DevWorkspace for the current routing has .spec.started set to false
WorkspaceStopped(routing *controllerv1alpha1.DevWorkspaceRouting, workspaceMeta DevWorkspaceMetadata) error
}

type RoutingSolverGetter interface {
Expand Down

0 comments on commit 5dd5901

Please sign in to comment.