Skip to content

Finalize workspace -> devWorkspace renaming #322

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

Merged
merged 3 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export ROUTING_SUFFIX ?= 192.168.99.100.nip.io
export PULL_POLICY ?= Always
export DEFAULT_ROUTING ?= basic
export KUBECONFIG ?= ${HOME}/.kube/config
export DEVWORKSPACE_API_VERSION ?= 283b0c54946e9fea9872c25e1e086c303688f0e8
export DEVWORKSPACE_API_VERSION ?= 1f335562c475972132851c68227dd36558317bb3

#internal params
DEVWORKSPACE_CTRL_SA=devworkspace-controller-serviceaccount
Expand Down
2 changes: 1 addition & 1 deletion PROJECT
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
domain: devfile.io
layout: go.kubebuilder.io/v2
multigroup: true
projectName: devworkspace-operator-migration
projectName: devworkspace-operator
repo: github.com/devfile/devworkspace-operator
resources:
- group: controller
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can add these Kubernetes annotations to specific DevWorkspace CR to customiz

The `controller.devfile.io/restricted-access` specifies that a DevWorkspace needs additional access control (in addition to RBAC). When a DevWorkspace is created with the `controller.devfile.io/restricted-access` annotation set to `true`, the webhook server will guarantee
- Only the DevWorkspace Operator ServiceAccount or DevWorkspace creator can modify important fields in the devworksapce
- Only the DevWorkspace creator can create `pods/exec` into workspace-related containers.
- Only the DevWorkspace creator can create `pods/exec` into devworkspace-related containers.

This annotation should be used when a DevWorkspace is expected to contain sensitive information that should be protect above the protection provided by standard RBAC rules (e.g. if the DevWorkspace will store the user's OpenShift token in-memory).

Expand Down Expand Up @@ -49,7 +49,7 @@ export DWO_IMG=quay.io/devfile/devworkspace-controller:next
make install
```

By default, controller will expose workspace servers without any authentication; this is not advisable for public clusters, as any user could access the created workspace via URL.
By default, controller will expose devworkspace servers without any authentication; this is not advisable for public clusters, as any user could access the created devworkspace via URL.

In case of OpenShift, you're able to configure DevWorkspace CR to secure your servers with the following piece of configuration:

Expand Down Expand Up @@ -95,9 +95,9 @@ Some of the rules supported by the makefile:
To see all rules supported by the makefile, run `make help`

### Test run controller
1. Take a look samples workspace configuration in `./samples` folder.
2. Apply any of them by executing `kubectl apply -f ./samples/workspace_java_mysql.yaml -n <namespace>`
3. As soon as workspace is started you're able to get IDE url by executing `kubectl get devworkspace -n <namespace>`
1. Take a look samples devworkspace configuration in `./samples` folder.
2. Apply any of them by executing `kubectl apply -f ./samples/flattened_theia-next.yaml -n <namespace>`
3. As soon as devworkspace is started you're able to get IDE url by executing `kubectl get devworkspace -n <namespace>`

### Run controller locally
```bash
Expand All @@ -106,7 +106,7 @@ oc patch deployment/devworkspace-controller-manager --patch "{\"spec\":{\"replic
make run
```

When running locally, only a single namespace is watched; as a result, all workspaces have to be deployed to `${NAMESPACE}`
When running locally, only a single namespace is watched; as a result, all devworkspaces have to be deployed to `${NAMESPACE}`

### Run controller locally and debug
Debugging the controller depends on `delve` being installed (`go get -u github.com/go-delve/delve/cmd/dlv`). Note that at the time of writing, executing `go get` in this repo's directory will update go.mod; these changes should be dropped before committing.
Expand Down
18 changes: 9 additions & 9 deletions apis/controller/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,44 @@ package v1alpha1

import v1 "k8s.io/api/core/v1"

// Summary of additions that are to be merged into the main workspace deployment
// Summary of additions that are to be merged into the main devworkspace deployment
type PodAdditions struct {
// Annotations to be applied to workspace deployment
// Annotations to be applied to devworkspace deployment
// +optional
// +patchMergeKey=name
// +patchStrategy=merge
Annotations map[string]string `json:"annotations,omitempty"`
// Labels to be applied to workspace deployment
// Labels to be applied to devworkspace deployment
// +optional
// +patchMergeKey=name
// +patchStrategy=merge
Labels map[string]string `json:"labels,omitempty"`
// Containers to add to workspace deployment
// Containers to add to devworkspace deployment
// +optional
// +patchMergeKey=name
// +patchStrategy=merge
Containers []v1.Container `json:"containers,omitempty"`
// Init containers to add to workspace deployment
// Init containers to add to devworkspace deployment
// +optional
// +patchMergeKey=name
// +patchStrategy=merge
InitContainers []v1.Container `json:"initContainers,omitempty"`
// Volumes to add to workspace deployment
// Volumes to add to devworkspace deployment
// +optional
// +patchMergeKey=name
// +patchStrategy=merge
Volumes []v1.Volume `json:"volumes,omitempty"`
// VolumeMounts to add to all containers in a workspace deployment
// VolumeMounts to add to all containers in a devworkspace deployment
// +optional
// +patchMergeKey=name
// +patchStrategy=merge
VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"`
// ImagePullSecrets to add to workspace deployment
// ImagePullSecrets to add to devworkspace deployment
// +optional
// +patchMergeKey=name
// +patchStrategy=merge
PullSecrets []v1.LocalObjectReference `json:"pullSecrets,omitempty"`
// Annotations for the workspace service account, it might be used for e.g. OpenShift oauth with SA as auth client
// Annotations for the devworkspace service account, it might be used for e.g. OpenShift oauth with SA as auth client
// +optional
// +patchMergeKey=name
// +patchStrategy=merge
Expand Down
14 changes: 7 additions & 7 deletions apis/controller/v1alpha1/devworkspacerouting_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
package v1alpha1

import (
devworkspace "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
devfileAttr "github.com/devfile/api/v2/pkg/attributes"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// DevWorkspaceRoutingSpec defines the desired state of DevWorkspaceRouting
// +k8s:openapi-gen=true
type DevWorkspaceRoutingSpec struct {
// WorkspaceId for the workspace being routed
WorkspaceId string `json:"workspaceId"`
// Class of the routing: this drives which Workspace Routing controller will manage this routing
// Id for the DevWorkspace being routed
DevWorkspaceId string `json:"devworkspaceId"`
// Class of the routing: this drives which DevWorkspaceRouting controller will manage this routing
RoutingClass DevWorkspaceRoutingClass `json:"routingClass,omitempty"`
// Routing suffix for cluster
RoutingSuffix string `json:"routingSuffix"`
// Machines to endpoints map
Endpoints map[string]EndpointList `json:"endpoints"`
// Selector that should be used by created services to point to the workspace Pod
// Selector that should be used by created services to point to the devworkspace Pod
PodSelector map[string]string `json:"podSelector"`
}

Expand All @@ -46,7 +46,7 @@ const (
// DevWorkspaceRoutingStatus defines the observed state of DevWorkspaceRouting
// +k8s:openapi-gen=true
type DevWorkspaceRoutingStatus struct {
// Additions to main workspace deployment
// Additions to main devworkspace deployment
PodAdditions *PodAdditions `json:"podAdditions,omitempty"`
// Machine name to exposed endpoint map
ExposedEndpoints map[string]ExposedEndpointList `json:"exposedEndpoints,omitempty"`
Expand All @@ -73,7 +73,7 @@ type ExposedEndpoint struct {
Attributes devfileAttr.Attributes `json:"attributes,omitempty"`
}

type EndpointList []devworkspace.Endpoint
type EndpointList []dw.Endpoint

type ExposedEndpointList []ExposedEndpoint

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(req ctrl.Request) (ctrl.Result
// Error reading the object - requeue the request.
return reconcile.Result{}, err
}
reqLogger = reqLogger.WithValues(constants.WorkspaceIDLoggerKey, instance.Spec.WorkspaceId)
reqLogger = reqLogger.WithValues(constants.DevWorkspaceIDLoggerKey, instance.Spec.DevWorkspaceId)
reqLogger.Info("Reconciling DevWorkspaceRouting")

if instance.Spec.RoutingClass == "" {
reqLogger.Info("workspace routing without an explicit routing class is invalid", "name", instance.Name, "namespace", instance.Namespace)
reqLogger.Info("DevWorkspaceRouting without an explicit routing class is invalid", "name", instance.Name, "namespace", instance.Namespace)
return reconcile.Result{}, r.markRoutingFailed(instance)
}

Expand All @@ -91,7 +91,7 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(req ctrl.Request) (ctrl.Result
if errors.Is(err, solvers.RoutingNotSupported) {
return reconcile.Result{}, nil
}
reqLogger.Error(err, "Invalid routing class for workspace")
reqLogger.Error(err, "Invalid routing class for DevWorkspace")
return reconcile.Result{}, r.markRoutingFailed(instance)
}

Expand All @@ -111,14 +111,14 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(req ctrl.Request) (ctrl.Result
return reconcile.Result{}, err
}

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

restrictedAccess, setRestrictedAccess := instance.Annotations[constants.WorkspaceRestrictedAccessAnnotation]
restrictedAccess, setRestrictedAccess := instance.Annotations[constants.DevWorkspaceRestrictedAccessAnnotation]
routingObjects, err := solver.GetSpecObjects(instance, workspaceMeta)
if err != nil {
var notReady *solvers.RoutingNotReady
Expand All @@ -127,7 +127,7 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(req ctrl.Request) (ctrl.Result
if duration.Milliseconds() == 0 {
duration = 1 * time.Second
}
reqLogger.Info("controller not ready for workspace routing. Retrying", "DelayMs", duration.Milliseconds())
reqLogger.Info("controller not ready for devworkspace routing. Retrying", "DelayMs", duration.Milliseconds())
return reconcile.Result{RequeueAfter: duration}, nil
}

Expand All @@ -148,7 +148,7 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(req ctrl.Request) (ctrl.Result
return reconcile.Result{}, err
}
if setRestrictedAccess {
services[idx].Annotations = maputils.Append(services[idx].Annotations, constants.WorkspaceRestrictedAccessAnnotation, restrictedAccess)
services[idx].Annotations = maputils.Append(services[idx].Annotations, constants.DevWorkspaceRestrictedAccessAnnotation, restrictedAccess)
}
}
ingresses := routingObjects.Ingresses
Expand All @@ -158,7 +158,7 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(req ctrl.Request) (ctrl.Result
return reconcile.Result{}, err
}
if setRestrictedAccess {
ingresses[idx].Annotations = maputils.Append(ingresses[idx].Annotations, constants.WorkspaceRestrictedAccessAnnotation, restrictedAccess)
ingresses[idx].Annotations = maputils.Append(ingresses[idx].Annotations, constants.DevWorkspaceRestrictedAccessAnnotation, restrictedAccess)
}
}
routes := routingObjects.Routes
Expand All @@ -168,7 +168,7 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(req ctrl.Request) (ctrl.Result
return reconcile.Result{}, err
}
if setRestrictedAccess {
routes[idx].Annotations = maputils.Append(routes[idx].Annotations, constants.WorkspaceRestrictedAccessAnnotation, restrictedAccess)
routes[idx].Annotations = maputils.Append(routes[idx].Annotations, constants.DevWorkspaceRestrictedAccessAnnotation, restrictedAccess)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
var routeAnnotations = func(endpointName string) map[string]string {
return map[string]string{
"haproxy.router.openshift.io/rewrite-target": "/",
constants.WorkspaceEndpointNameAnnotation: endpointName,
constants.DevWorkspaceEndpointNameAnnotation: endpointName,
}
}

Expand All @@ -30,7 +30,7 @@ var nginxIngressAnnotations = func(endpointName string) map[string]string {
"kubernetes.io/ingress.class": "nginx",
"nginx.ingress.kubernetes.io/rewrite-target": "/",
"nginx.ingress.kubernetes.io/ssl-redirect": "false",
constants.WorkspaceEndpointNameAnnotation: endpointName,
constants.DevWorkspaceEndpointNameAnnotation: endpointName,
}
}

Expand All @@ -50,7 +50,7 @@ func (s *BasicSolver) Finalize(*controllerv1alpha1.DevWorkspaceRouting) error {
return nil
}

func (s *BasicSolver) GetSpecObjects(routing *controllerv1alpha1.DevWorkspaceRouting, workspaceMeta WorkspaceMetadata) (RoutingObjects, error) {
func (s *BasicSolver) GetSpecObjects(routing *controllerv1alpha1.DevWorkspaceRouting, workspaceMeta DevWorkspaceMetadata) (RoutingObjects, error) {
routingObjects := RoutingObjects{}

spec := routing.Spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/devfile/devworkspace-operator/pkg/common"
"github.com/devfile/devworkspace-operator/pkg/constants"

devworkspace "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
corev1 "k8s.io/api/core/v1"

controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
Expand All @@ -42,7 +42,7 @@ func (s *ClusterSolver) Finalize(*controllerv1alpha1.DevWorkspaceRouting) error
return nil
}

func (s *ClusterSolver) GetSpecObjects(routing *controllerv1alpha1.DevWorkspaceRouting, workspaceMeta WorkspaceMetadata) (RoutingObjects, error) {
func (s *ClusterSolver) GetSpecObjects(routing *controllerv1alpha1.DevWorkspaceRouting, workspaceMeta DevWorkspaceMetadata) (RoutingObjects, error) {
spec := routing.Spec
services := getServicesForEndpoints(spec.Endpoints, workspaceMeta)
podAdditions := &controllerv1alpha1.PodAdditions{}
Expand Down Expand Up @@ -84,7 +84,7 @@ func (s *ClusterSolver) GetExposedEndpoints(

for machineName, machineEndpoints := range endpoints {
for _, endpoint := range machineEndpoints {
if endpoint.Exposure == devworkspace.NoneEndpointExposure {
if endpoint.Exposure == dw.NoneEndpointExposure {
continue
}
url, err := resolveServiceHostnameForEndpoint(endpoint, routingObj.Services)
Expand All @@ -103,9 +103,9 @@ func (s *ClusterSolver) GetExposedEndpoints(
return exposedEndpoints, true, nil
}

func resolveServiceHostnameForEndpoint(endpoint devworkspace.Endpoint, services []corev1.Service) (string, error) {
func resolveServiceHostnameForEndpoint(endpoint dw.Endpoint, services []corev1.Service) (string, error) {
for _, service := range services {
if service.Annotations[constants.WorkspaceDiscoverableServiceAnnotation] == "true" {
if service.Annotations[constants.DevWorkspaceDiscoverableServiceAnnotation] == "true" {
continue
}
for _, servicePort := range service.Spec.Ports {
Expand Down
Loading