Skip to content
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

feat: support workspace defaults #1395

Merged
merged 6 commits into from
Jun 22, 2022
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 @@ -658,7 +658,7 @@ download-opm: ## Download opm tool

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
download-controller-gen: ## Download controller-gen tool
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
download-kustomize: ## Download kustomize tool
Expand Down
9 changes: 9 additions & 0 deletions api/checluster_conversion_from_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 @@ -333,6 +334,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 @@ -449,6 +456,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
39 changes: 24 additions & 15 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,21 +162,27 @@ func TestConvertTo(t *testing.T) {
CheClusterRoles: "CheClusterRoles_1,CheClusterRoles_2",
CheWorkspaceClusterRole: "CheWorkspaceClusterRole",
WorkspaceNamespaceDefault: "WorkspaceNamespaceDefault",
ServerTrustStoreConfigMapName: "ServerTrustStoreConfigMapName",
GitSelfSignedCert: true,
DashboardImage: "DashboardImage",
DashboardImagePullPolicy: "Always",
DashboardMemoryLimit: "200Mi",
DashboardMemoryRequest: "100Mi",
DashboardCpuLimit: "2",
DashboardCpuRequest: "1",
DevfileRegistryImage: "DevfileRegistryImage",
DevfileRegistryPullPolicy: "Always",
DevfileRegistryMemoryLimit: "200Mi",
DevfileRegistryMemoryRequest: "100Mi",
DevfileRegistryCpuLimit: "2",
DevfileRegistryCpuRequest: "1",
ExternalDevfileRegistry: true,
WorkspaceDefaultEditor: "WorkspaceDefaultEditor",
WorkspaceDefaultComponents: []devfile.Component{
{
Name: "universal-developer-image",
},
},
ServerTrustStoreConfigMapName: "ServerTrustStoreConfigMapName",
GitSelfSignedCert: true,
DashboardImage: "DashboardImage",
DashboardImagePullPolicy: "Always",
DashboardMemoryLimit: "200Mi",
DashboardMemoryRequest: "100Mi",
DashboardCpuLimit: "2",
DashboardCpuRequest: "1",
DevfileRegistryImage: "DevfileRegistryImage",
DevfileRegistryPullPolicy: "Always",
DevfileRegistryMemoryLimit: "200Mi",
DevfileRegistryMemoryRequest: "100Mi",
DevfileRegistryCpuLimit: "2",
DevfileRegistryCpuRequest: "1",
ExternalDevfileRegistry: true,
ExternalDevfileRegistries: []chev1.ExternalDevfileRegistries{
{
Url: "ExternalDevfileRegistries_1",
Expand Down Expand Up @@ -330,6 +337,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
8 changes: 8 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions api/v2/checluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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 @@ -80,6 +81,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` format.
// The URI must start from `http://` or `https://`.
// +optional
DefaultEditor string `json:"defaultEditor,omitempty"`
// Default components applied to DevWorkspaces.
// These default components are meant to be used when a Devfile, that does not contain any components.
// +optional
DefaultComponents []devfile.Component `json:"defaultComponents,omitempty"`
olexii4 marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +88 to +92
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l0rd please, take a look at the final structure we are planning to have in place:

devEnvironments:
  (...)
  defaultComponents [ ] 
  defaultEditor: ""

Any concerns?

}

// Che components configuration.
Expand Down
8 changes: 8 additions & 0 deletions api/v2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ metadata:
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/eclipse-che/che-operator
support: Eclipse Foundation
name: eclipse-che-preview-openshift.v7.50.0-606.next
name: eclipse-che-preview-openshift.v7.50.0-611.next
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -1387,7 +1387,7 @@ spec:
maturity: stable
provider:
name: Eclipse Foundation
version: 7.50.0-606.next
version: 7.50.0-611.next
webhookdefinitions:
- admissionReviewVersions:
- v1
Expand Down
Loading