Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
83d2544
don't create che-workspace serviceaccount and give needed permissions…
sparkoo Dec 3, 2019
3ade531
don't create roles and rolebindings when oauth enabled
sparkoo Dec 4, 2019
9e5bce3
Merge branch 'master' into che-workspace-rem
sparkoo Dec 4, 2019
3b1e777
grant more permissions to support running workspaces in pre-created n…
sparkoo Dec 5, 2019
6786dd5
add needed permissions to create namespace and run workspace in diffe…
sparkoo Dec 9, 2019
cd48a3c
license headers, cleanup
sparkoo Dec 9, 2019
aca6124
update permissions
sparkoo Dec 16, 2019
092a2d2
Merge branch 'master' of https://github.com/eclipse/che-operator into…
AndrienkoAleksandr Jan 27, 2020
e5dbf1e
Fix issue with Che 'update' namespace permission and other stuff
AndrienkoAleksandr Jan 27, 2020
9390c16
Fix issue with clusterrolebindings and clusterrole finalizers
AndrienkoAleksandr Jan 27, 2020
e7a29d9
Fix deploy Che using olm on the minikube Fix deploy Che using olm on …
AndrienkoAleksandr Feb 3, 2020
6baaa73
Address changes.
AndrienkoAleksandr Feb 4, 2020
1922ae6
Fix service account wrongly generated by operator-sdk for some cluste…
AndrienkoAleksandr Feb 5, 2020
caf9bd8
Merge branch 'master' of https://github.com/eclipse/che-operator into…
AndrienkoAleksandr Feb 5, 2020
aa4635f
Clean up.
AndrienkoAleksandr Feb 5, 2020
f5aab7c
Remove optional quotes
AndrienkoAleksandr Feb 6, 2020
ee5a7a6
Merge branch 'master' of https://github.com/eclipse/che-operator into…
AndrienkoAleksandr Feb 10, 2020
4cc7542
Move cluster role to the one clusterrole.
AndrienkoAleksandr Feb 11, 2020
d7fb5a9
Remove duplication, sort yaml in the same maner.
AndrienkoAleksandr Feb 12, 2020
b4fd750
Remove deploy_k8s.sh. We should use chectl or OLM instead of it.
AndrienkoAleksandr Feb 12, 2020
a014b45
Merge branch 'master' of https://github.com/eclipse/che-operator into…
AndrienkoAleksandr Feb 12, 2020
e4785fa
Clean up.
AndrienkoAleksandr Feb 12, 2020
fa65bf5
Merge remote-tracking branch 'origin' into CHE-15493
AndrienkoAleksandr Jan 4, 2021
b827d31
Add docs information about workspace strategy
AndrienkoAleksandr Jan 4, 2021
8371164
Fix permissions.
AndrienkoAleksandr Jan 10, 2021
a6802b0
Add finalizers. Code not stable yet.
AndrienkoAleksandr Jan 11, 2021
82315cf
Fix permission finalizer when user removed namespace.
AndrienkoAleksandr Jan 13, 2021
f9437bb
Split code. Add tests. Some code clean up.
AndrienkoAleksandr Jan 20, 2021
3d574eb
Turn back accidental removed code.
AndrienkoAleksandr Jan 20, 2021
ee2f180
Clean up.
AndrienkoAleksandr Jan 21, 2021
92c1e9f
Fix compilation.
AndrienkoAleksandr Jan 21, 2021
69f2f90
Improve custom signal handler.
AndrienkoAleksandr Jan 26, 2021
775a34c
Add permission fallback for workspace namespaces strategy.
AndrienkoAleksandr Jan 27, 2021
9d86be5
Merge branch 'master' of github.com:eclipse/che-operator into CHE-15493
AndrienkoAleksandr Jan 27, 2021
2e80bbd
Update csv files.
AndrienkoAleksandr Jan 27, 2021
d5c82d5
Merge branch 'master' of github.com:eclipse/che-operator into CHE-15493
AndrienkoAleksandr Jan 28, 2021
225c0df
Format code.
AndrienkoAleksandr Jan 28, 2021
b898ce6
Add more information about permission stuff.
AndrienkoAleksandr Jan 29, 2021
8c89ce6
Try to fix ci tests.
AndrienkoAleksandr Jan 31, 2021
04df9cd
Address code review changes.
AndrienkoAleksandr Feb 1, 2021
0c32fe3
Fix up.
AndrienkoAleksandr Feb 1, 2021
1e462c4
Update OLM bundle.
AndrienkoAleksandr Feb 1, 2021
7419030
Remove single workspaces namespace permissions, when differ workspace…
AndrienkoAleksandr Feb 1, 2021
42ff0e3
Handle code review changes.
AndrienkoAleksandr Feb 2, 2021
4a38bb6
Fix up.
AndrienkoAleksandr Feb 2, 2021
3093529
Fix up.
AndrienkoAleksandr Feb 2, 2021
c80c848
Handle one more review feedback.
AndrienkoAleksandr Feb 2, 2021
48bc5b9
Fix up.
AndrienkoAleksandr Feb 2, 2021
b230a72
Update pkg/util/util.go
AndrienkoAleksandr Feb 3, 2021
46f9545
Update pkg/controller/che/che_controller.go
AndrienkoAleksandr Feb 3, 2021
7aff08a
Update pkg/controller/che/che_controller.go
AndrienkoAleksandr Feb 3, 2021
44b1e88
Update pkg/controller/che/cluster_permissions_finalizer.go
AndrienkoAleksandr Feb 3, 2021
5d82eab
Update pkg/controller/che/workspace_namespace_permission.go
AndrienkoAleksandr Feb 3, 2021
e1bd915
Update pkg/controller/che/workspace_namespace_permission.go
AndrienkoAleksandr Feb 3, 2021
651b892
Handle code review changes.
AndrienkoAleksandr Feb 3, 2021
ee12aa7
Update pkg/controller/che/workspace_namespace_permission.go
AndrienkoAleksandr Feb 3, 2021
6344e94
Update pkg/controller/che/workspace_namespace_permission.go
AndrienkoAleksandr Feb 3, 2021
21b5820
Update pkg/controller/che/workspace_namespace_permission.go
AndrienkoAleksandr Feb 3, 2021
8aa5fb4
Update pkg/controller/che/workspace_namespace_permission.go
AndrienkoAleksandr Feb 3, 2021
57e4010
Update pkg/controller/che/workspace_namespace_permission.go
AndrienkoAleksandr Feb 3, 2021
2a3d12a
Update pkg/controller/che/workspace_namespace_permission.go
AndrienkoAleksandr Feb 3, 2021
668652a
Handle code review changes.
AndrienkoAleksandr Feb 3, 2021
a67ac77
Fix up. Clean up permissions when oauth enabled.
AndrienkoAleksandr Feb 3, 2021
622688f
Fix workspace starting for oauth enabled.
AndrienkoAleksandr Feb 4, 2021
31e97cc
Fix up.
AndrienkoAleksandr Feb 4, 2021
6a6a1c0
Fix up.
AndrienkoAleksandr Feb 4, 2021
55238ec
Fix up.
AndrienkoAleksandr Feb 4, 2021
b97794e
Fix workspace starting on the k8s, when Che installed via OLM.
AndrienkoAleksandr Feb 5, 2021
102dc51
Improve code.
AndrienkoAleksandr Feb 5, 2021
345f689
Add logs.
AndrienkoAleksandr Feb 5, 2021
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
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,35 @@ spec:
CHE_MULTIUSER: "false"
```

```
```bash
$ chectl server:update -n <ECLIPSE-CHE-NAMESPACE> --che-operator-cr-patch-yaml <PATH_TO_CR_PATCH_YAML>
```

### Workspace namespace strategy

Workspace namespace strategy defines default namespace in which user's workspaces are created.
It's possible to use <username>, <userid> and <workspaceid> placeholders (e.g.: che-workspace-<username>).
In that case, new namespace will be created for each user (or workspace).
For OpenShift infrastructure this property used to specify Project (instead of namespace conception).

To set up namespace workspace strategy use command line:

```bash
$ kubectl patch checluster/eclipse-che -n <ECLIPSE-CHE-NAMESPACE> --type=merge -p '{"spec":{"server": {"customCheProperties": {"CHE_INFRA_KUBERNETES_NAMESPACE_DEFAULT": "che-workspace-<username>"}}}}'
```

or create `cr-patch.yaml` and use it with chectl:

```yaml
spec:
server:
customCheProperties:
CHE_INFRA_KUBERNETES_NAMESPACE_DEFAULT: "che-workspace-<username>"
```

```bash
$ chectl server:update -n <ECLIPSE-CHE-NAMESPACE> --che-operator-cr-patch-yaml <PATH_TO_CR_PATCH_YAML>

### OpenShift OAuth

OpenShift clusters include a built-in OAuth server. Che operator supports this authentication method. It's enabled by default.
Expand All @@ -176,7 +201,7 @@ spec:
openShiftoAuth: false
```

```
```bash
$ chectl server:update -n <ECLIPSE-CHE-NAMESPACE> --che-operator-cr-patch-yaml <PATH_TO_CR_PATCH_YAML>
```

Expand All @@ -196,7 +221,7 @@ spec:
tlsSupport: false
```

```
```bash
$ chectl server:update -n <ECLIPSE-CHE-NAMESPACE> --che-operator-cr-patch-yaml <PATH_TO_CR_PATCH_YAML>
```

Expand Down Expand Up @@ -292,6 +317,7 @@ Run the VSCode task: `Format che-operator code` or use the terminal:
```bash
$ go fmt ./...
```
> Notice: if you don't have redhat subscription, use public image registry.access.redhat.com/devtools/go-toolset-rhel7:latest

### Update golang dependencies

Expand Down
7 changes: 5 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import (
"context"
"flag"
"fmt"

"os"
"runtime"

image_puller_api "github.com/che-incubator/kubernetes-image-puller-operator/pkg/apis"
"github.com/eclipse/che-operator/cmd/manager/signal"
"github.com/eclipse/che-operator/pkg/util"
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
Expand All @@ -37,7 +39,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)

var (
Expand Down Expand Up @@ -170,7 +171,9 @@ func main() {
logrus.Info("Starting the Cmd")

// Start the Cmd
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
period := signal.GetTerminationGracePeriodSeconds(mgr.GetAPIReader(), namespace)
logrus.Info("Create manager")
if err := mgr.Start(signal.SetupSignalHandler(period)); err != nil {
logrus.Error(err, "Manager exited non-zero")
os.Exit(1)
}
Expand Down
94 changes: 94 additions & 0 deletions cmd/manager/signal/signal_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//
// Copyright (c) 2012-2020 Red Hat, Inc.
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//
// Contributors:
// Red Hat, Inc. - initial API and implementation
//

package signal

import (
"context"
"os"
"os/signal"
"syscall"
"time"

"github.com/sirupsen/logrus"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// SetupSignalHandler set up custom signal handler for main process.
func SetupSignalHandler(terminationPeriod int64) (stopCh <-chan struct{}) {
logrus.Info("Set up process signal handler")
var shutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGINT}

stop := make(chan struct{})
c := make(chan os.Signal, 1)
signal.Notify(c, shutdownSignals...)
go func() {
sig := <-c
printSignal(sig)

// We need provide more time for Che controller go routing to complete finalizers logic.
// Otherwise resource won't be clean up gracefully
// and Che custom resource will stay with non empty "finalizers" field.
time.Sleep(time.Duration(terminationPeriod) * time.Second)
logrus.Info("Stop and exit operator.")
// Stop Che controller
close(stop)
// Exit from main process directly.
os.Exit(1)
}()

return stop
}

func printSignal(signal os.Signal) {
switch signal {
case syscall.SIGHUP:
logrus.Info("Signal SIGHUP")

case syscall.SIGINT:
logrus.Println("Signal SIGINT (ctrl+c)")

case syscall.SIGTERM:
logrus.Println("Signal SIGTERM stop")

case syscall.SIGQUIT:
logrus.Println("Signal SIGQUIT (top and core dump)")

default:
logrus.Println("Unknown signal")
}
}

func GetTerminationGracePeriodSeconds(k8sClient client.Reader, namespace string) int64 {
cheFlavor := os.Getenv("CHE_FLAVOR")
if cheFlavor == "" {
cheFlavor = "che"
}
defaultTerminationGracePeriodSeconds := int64(20)

deployment := &appsv1.Deployment{}
namespacedName := types.NamespacedName{Namespace: namespace, Name: cheFlavor + "-operator"}
if err := k8sClient.Get(context.TODO(), namespacedName, deployment); err != nil {
logrus.Warnf("Unable to find '%s' deployment in namespace '%s', err: %s", cheFlavor+"-operator", namespace, err.Error())
} else {
terminationPeriod := deployment.Spec.Template.Spec.TerminationGracePeriodSeconds
if terminationPeriod != nil {
logrus.Infof("Use 'terminationGracePeriodSeconds' %d sec. from operator deployment.", *terminationPeriod)
return *terminationPeriod
}
}

logrus.Infof("Use default 'terminationGracePeriodSeconds' %d sec.", defaultTerminationGracePeriodSeconds)
return defaultTerminationGracePeriodSeconds
}
183 changes: 183 additions & 0 deletions deploy/cluster_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,186 @@ rules:
- create
- watch
- update
- get
- delete
- apiGroups:
- rbac.authorization.k8s.io
resources:
- clusterroles
verbs:
- list
- create
- watch
- update
- get
- delete
- apiGroups:
- authorization.openshift.io
resources:
- roles
verbs:
- get
- create
- delete
- apiGroups:
- authorization.openshift.io
resources:
- rolebindings
verbs:
- get
- create
- update
- delete
- apiGroups:
- rbac.authorization.k8s.io
resources:
- roles
verbs:
- get
- create
- delete
- apiGroups:
- rbac.authorization.k8s.io
resources:
- rolebindings
verbs:
- get
- create
- update
- delete
- apiGroups:
- org.eclipse.che
resources:
- checlusters
- checlusters/finalizers
verbs:
- '*'
- apiGroups:
- project.openshift.io
resources:
- projectrequests
verbs:
- create
- update
- apiGroups:
- ""
resources:
- namespaces
verbs:
- get
- create
- update
- apiGroups:
- project.openshift.io
resources:
- projects
verbs:
- get
- apiGroups:
- ''
resources:
- serviceaccounts
verbs:
- get
- create
- watch
- apiGroups:
- ''
resources:
- pods/exec
verbs:
- create
- apiGroups:
- apps
resources:
- secrets
verbs:
- list
- apiGroups:
- ''
resources:
- secrets
verbs:
- list
- create
- delete
- apiGroups:
- ''
resources:
- persistentvolumeclaims
verbs:
- create
- get
- list
- watch
- apiGroups:
- ''
resources:
- pods
verbs:
- get
- list
- create
- watch
- delete
- apiGroups:
- apps
resources:
- deployments
verbs:
- get
- list
- create
- patch
- watch
- delete
- apiGroups:
- ''
resources:
- services
verbs:
- list
- create
- delete
- apiGroups:
- ''
resources:
- configmaps
verbs:
- get
- create
- delete
- list
- apiGroups:
- route.openshift.io
resources:
- routes
verbs:
- list
- create
- delete
- apiGroups:
- ''
resources:
- events
verbs:
- watch
- apiGroups:
- apps
resources:
- replicasets
verbs:
- list
- get
- patch
- delete
- apiGroups:
- extensions
resources:
- ingresses
verbs:
- list
- create
- watch
- get
- delete
2 changes: 1 addition & 1 deletion deploy/crds/org_v1_che_cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spec:
# sets mem limit for server deployment. Defaults to 1Gi
serverMemoryLimit: ''
# sets default namespace where new workspaces will be created
workspaceNamespaceDefault: ''
workspaceNamespaceDefault: "<username>-che"
# defines if user is able to specify namespace different from the default
allowUserDefinedWorkspaceNamespaces: false
# Sets the server and workspaces exposure type. Possible values are "multi-host", "single-host", "default-host".
Expand Down
2 changes: 2 additions & 0 deletions deploy/namespaces_cluster_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ rules:
- namespaces
verbs:
- update
- list
- create
- get
Loading