Skip to content

Commit

Permalink
feat: support workspace defaults
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Jun 17, 2022
1 parent 08de5aa commit 3bfa497
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/checluster_conversion_from_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
chev1 "github.com/eclipse-che/che-operator/api/v1"
chev2 "github.com/eclipse-che/che-operator/api/v2"
"github.com/stretchr/testify/assert"
devfile "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -331,6 +332,12 @@ func TestConvertFrom(t *testing.T) {
Plugins: []string{"Plugins_1", "Plugins_2"},
},
},
DefaultEditor: "DefaultEditor",
DefaultComponents: []devfile.Component{
{
Name: "universal-developer-image",
},
},
NodeSelector: map[string]string{"a": "b", "c": "d"},
Tolerations: []corev1.Toleration{{
Key: "Key",
Expand Down Expand Up @@ -445,6 +452,8 @@ func TestConvertFrom(t *testing.T) {
assert.Equal(t, checlusterv1.Spec.Server.SingleHostGatewayConfigSidecarImage, "ConfigSidecarImage")
assert.Equal(t, checlusterv1.Spec.Server.SingleHostGatewayImage, "GatewayImage")
assert.Equal(t, checlusterv1.Spec.Server.WorkspaceNamespaceDefault, "WorkspaceNamespaceName")
assert.Equal(t, checlusterv1.Spec.Server.WorkspaceDefaultEditor, "DefaultEditor")
assert.Equal(t, checlusterv1.Spec.Server.WorkspaceDefaultComponents, []devfile.Component{{Name: "universal-developer-image",}})
assert.Equal(t, checlusterv1.Spec.Server.WorkspacePodNodeSelector, map[string]string{"a": "b", "c": "d"})
assert.Equal(t, checlusterv1.Spec.Server.WorkspacePodTolerations, []corev1.Toleration{
{
Expand Down
9 changes: 9 additions & 0 deletions api/checluster_conversion_to_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"k8s.io/apimachinery/pkg/api/resource"

devfile "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
chev1 "github.com/eclipse-che/che-operator/api/v1"
chev2 "github.com/eclipse-che/che-operator/api/v2"
Expand Down Expand Up @@ -161,6 +162,12 @@ func TestConvertTo(t *testing.T) {
CheClusterRoles: "CheClusterRoles_1,CheClusterRoles_2",
CheWorkspaceClusterRole: "CheWorkspaceClusterRole",
WorkspaceNamespaceDefault: "WorkspaceNamespaceDefault",
WorkspaceDefaultEditor: "WorkspaceDefaultEditor",
WorkspaceDefaultComponents: []devfile.Component{
{
Name: "universal-developer-image",
},
},
ServerTrustStoreConfigMapName: "ServerTrustStoreConfigMapName",
GitSelfSignedCert: true,
DashboardImage: "DashboardImage",
Expand Down Expand Up @@ -326,6 +333,8 @@ func TestConvertTo(t *testing.T) {
assert.Equal(t, checlusterv2.Spec.Components.CheServer.Proxy.Port, "ProxyPort")
assert.Equal(t, checlusterv2.Spec.Components.CheServer.Proxy.Url, "ProxyURL")
assert.Equal(t, checlusterv2.Spec.DevEnvironments.DefaultNamespace.Template, "WorkspaceNamespaceDefault")
assert.Equal(t, checlusterv2.Spec.DevEnvironments.DefaultEditor, "WorkspaceDefaultEditor")
assert.Equal(t, checlusterv2.Spec.DevEnvironments.DefaultComponents, []devfile.Component{{Name: "universal-developer-image"}})
assert.Equal(t, checlusterv2.Spec.DevEnvironments.NodeSelector, map[string]string{"a": "b", "c": "d"})
assert.Equal(t, checlusterv2.Spec.DevEnvironments.Tolerations, []corev1.Toleration{{
Key: "Key",
Expand Down
3 changes: 3 additions & 0 deletions api/v1/checluster_conversion_from.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func (dst *CheCluster) convertFrom_Server(src *chev2.CheCluster) error {
})
}

dst.Spec.Server.WorkspaceDefaultEditor = src.Spec.DevEnvironments.DefaultEditor
dst.Spec.Server.WorkspaceDefaultComponents = src.Spec.DevEnvironments.DefaultComponents

if len(src.Spec.Components.CheServer.Deployment.Containers) != 0 {
cheServerImageAndTag := strings.Split(src.Spec.Components.CheServer.Deployment.Containers[0].Image, ":")
dst.Spec.Server.CheImage = strings.Join(cheServerImageAndTag[0:len(cheServerImageAndTag)-1], ":")
Expand Down
3 changes: 3 additions & 0 deletions api/v1/checluster_conversion_to.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func (src *CheCluster) convertTo_DevEnvironments(dst *chev2.CheCluster) error {
})
}

dst.Spec.DevEnvironments.DefaultEditor = src.Spec.Server.WorkspaceDefaultEditor
dst.Spec.DevEnvironments.DefaultComponents = src.Spec.Server.WorkspaceDefaultComponents

if err := src.convertTo_Workspaces_Storage(dst); err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions api/v1/checluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strings"

chev1alpha1 "github.com/che-incubator/kubernetes-image-puller-operator/api/v1alpha1"
devfile "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -356,6 +357,15 @@ type CheClusterSpecServer struct {
WorkspacePodNodeSelector map[string]string `json:"workspacePodNodeSelector,omitempty"`
// The pod tolerations put on the workspace pods to limit where the workspace pods can run.
WorkspacePodTolerations []corev1.Toleration `json:"workspacePodTolerations,omitempty"`
// The default editor to workspace create with. It could be a plugin ID or a URI.
// The plugin ID must have `publisher/plugin/version`.
// The URI must start from `http`.
// +optional
WorkspaceDefaultEditor string `json:"workspaceDefaultEditor,omitempty"`
// Default components applied to DevWorkspaces.
// These default components are meant to be used when a Devfile does not contain any components.
// +optional
WorkspaceDefaultComponents []devfile.Component `json:"workspaceDefaultComponents,omitempty"`
}

// +k8s:openapi-gen=true
Expand Down
10 changes: 10 additions & 0 deletions api/v2/checluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"

imagepullerv1alpha1 "github.com/che-incubator/kubernetes-image-puller-operator/api/v1alpha1"
devfile "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -72,6 +73,15 @@ type CheClusterDevEnvironments struct {
// Trusted certificate settings.
// +optional
TrustedCerts TrustedCerts `json:"trustedCerts,omitempty"`
// The default editor to workspace create with. It could be a plugin ID or a URI.
// The plugin ID must have `publisher/plugin/version`.
// The URI must start from `http`.
// +optional
DefaultEditor string `json:"defaultEditor,omitempty"`
// Default components applied to DevWorkspaces.
// These default components are meant to be used when a Devfile does not contain any components.
// +optional
DefaultComponents []devfile.Component `json:"defaultComponents,omitempty"`
}

// Che components configuration.
Expand Down

0 comments on commit 3bfa497

Please sign in to comment.