Go to file
nickboldt e27980a7aa chore: Update from ubi8-minimal:8.4-210 to ubi8-minimal:8.5-204
Change-Id: I38432dd8d8f44469e9067e26e6ffcd4f787ae6d6
Signed-off-by: nickboldt <nboldt@redhat.com>
2021-11-15 08:53:30 -04:00
.ci feat: switch devworkspace happy path test to remote launch 2021-10-19 17:35:56 +03:00
.github feat: Add DEPENDENCIES.md github action check. (#1148) 2021-10-19 16:20:23 +03:00
.vscode feat: Update controller runtime (#1064) 2021-10-01 14:54:37 +03:00
api feat: Update controller runtime (#1064) 2021-10-01 14:54:37 +03:00
bundle ci: Release version 7.38.2 (#1162) 2021-11-04 12:23:25 +02:00
config ci: Release version 7.38.2 (#1162) 2021-11-04 12:23:25 +02:00
controllers checontroller refactoring (#1138) 2021-10-19 10:56:49 +03:00
hack feat: Newer operator sdk (#826) 2021-07-19 14:29:11 +03:00
mocks feat: Newer operator sdk (#826) 2021-07-19 14:29:11 +03:00
olm ci: don't update csv in tech-preview-stable-all-namespaces channel since it is copied from next-all-namespaces and contain all neccessary info (#1114) 2021-10-01 09:19:04 +03:00
pkg checontroller refactoring (#1138) 2021-10-19 10:56:49 +03:00
templates fix: Add UPDDATE_PASSWORD action for admin user (#1091) 2021-09-27 18:47:02 +03:00
vendor fix: update go.sum and vendor folder 2021-10-06 12:56:46 +03:00
version ci: Release version 7.38.2 (#1162) 2021-11-04 12:23:25 +02:00
.dockerignore fix: Check identity providers for oauth instead of check amount users. (#248) 2020-05-15 11:43:58 +03:00
.gitignore feat: Rename stable-all-namespaces channel to tech-preview-stable-all-namespaces 2021-09-06 09:42:32 +02:00
DEPENDENCIES.md feat: Add DEPENDENCIES.md github action check. (#1148) 2021-10-19 16:20:23 +03:00
Dockerfile chore: Update from ubi8-minimal:8.4-210 to ubi8-minimal:8.5-204 2021-11-15 08:53:30 -04:00
LICENSE Adding EPL 2.0 LICENSE file 2020-02-24 11:17:49 +01:00
Makefile Add init containers to start Che correctly after node restart (#1139) 2021-10-13 16:15:11 +03:00
PROJECT fix: Improve Che presentation on the OperatorHub ui. (#1042) 2021-09-04 17:15:15 +03:00
README.md feat: Add `Dependencies.md` with list of runtime dependencies (#1121) 2021-10-05 15:12:57 +03:00
RELEASE.md fix: Update --push-olm-bundles documentation (#882) 2021-07-07 09:32:23 +03:00
REQUIREMENTS feat: Newer operator sdk (#826) 2021-07-19 14:29:11 +03:00
devfile.yaml feat: Newer operator sdk (#826) 2021-07-19 14:29:11 +03:00
go.mod fix: Upgrade dwo go dep to the latest available 2021-10-06 12:56:46 +03:00
go.sum fix: update go.sum and vendor folder 2021-10-06 12:56:46 +03:00
main.go checontroller refactoring (#1138) 2021-10-19 10:56:49 +03:00
make-release.sh ci: fix release process (#1111) 2021-10-01 00:07:54 +03:00
tools.go Operator sdk 0.15.2 (#515) 2020-11-11 11:15:55 -06:00

README.md

Che/CodeReady Workspaces Operator

codecov

Che/CodeReady workspaces operator uses Operator SDK and Go Kube client to deploy, update and manage K8S/OpenShift resources that constitute a single or multi-user Eclipse Che/CodeReady Workspaces cluster.

The operator watches for a Custom Resource of Kind CheCluster, and operator controller executes its business logic when a new Che object is created, namely:

  • creates k8s/OpenShift objects
  • verifies successful deployment of Postgres, Keycloak, Devfile/Plugin registries and Che server
  • runs exec into Postgres and Keycloak pods to provisions databases, users, realm and clients
  • updates CR spec and status (passwords, URLs, provisioning statuses etc.)
  • continuously watches CR, update Che ConfigMap accordingly and schedule a new Che deployment
  • changes state of certain objects depending on CR fields:
    • turn on/off TLS mode (reconfigure routes, update ConfigMap)
    • turn on/off OpenShift oAuth (login with OpenShift in Che) (create identity provider, oAuth client, update Che ConfigMap)
  • etc

Che operator is implemented using operator framework and the Go programming language. Eclipse Che configuration defined using a custom resource definition object and stored in the custom Kubernetes resource named checluster(or plural checlusters) in the Kubernetes API group org.eclipse.che. Che operator extends Kubernetes API to embed Eclipse Che to Kubernetes cluster in a native way.

CheCluster custom resource

Che operator deploys Eclipse Che using configuration stored in the Kubernetes custom resource(CR). CR object structure defined in the code using api/v1/checluster_types.go file. Field name defined using the serialization tag json, for example json:"openShiftoAuth". Che operator default CR sample is stored in the config/samples/org.eclipse.che_v1_checluster.yaml. This file should be directly modified if you want to apply new fields with default values, or in case of changing default values for existing fields. Also, you can apply in the field comments Openshift UI annotations: to display some interactive information about these fields on the Openshift UI. For example:

	// +operator-sdk:csv:customresourcedefinitions:type=status
	// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Eclipse Che URL"
	// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors="urn:alm:descriptor:org.w3:link"

This comment-annotations displays clickable link on the Openshift ui with a text "Eclipse Che URL"

It is mandatory to update the OLM bundle after modification of the CR sample to deploy Eclipse Che using OLM.

Build and push custom Che operator image

  1. Export globally environment variables:
$ export IMAGE_REGISTRY_USER_NAME=<IMAGE_REGISTRY_USER_NAME> && \
  export IMAGE_REGISTRY_HOST=<IMAGE_REGISTRY_HOST>

Where:

  • IMAGE_REGISTRY_USER_NAME - docker image registry account name.
  • IMAGE_REGISTRY_HOST - docker image registry hostname, for example: "docker.io", "quay.io". Host could be with a non default port: localhost:5000, 127.0.0.1:3000 and etc.
  1. Run VSCode task Build and push custom che-operator image or use the terminal:
$ make docker-build docker-push IMG="${IMAGE_REGISTRY_HOST}/${IMAGE_REGISTRY_USER_NAME}/che-operator:next"

Deploy Che operator using make

che-operator MAKE file provides ability to install che-operator(VSCode task Deploy che-operator):

$ make deploy IMG=\"${IMAGE_REGISTRY_HOST}/${IMAGE_REGISTRY_USER_NAME}/che-operator:next\"

$ kubectl apply -f config/samples/org.eclipse.che_v1_checluster.yaml -n <NAMESPACE>

Undeploy che-operator(VSCode task UnDeploy che-operator):

$ make undeploy

Deploy Che operator with chectl

To deploy Che operator you can use chectl. It has got two installer types corresponding to Che operator: operator and olm. With the --installer operator chectl reuses copies of Che operator deployment and roles (cluster roles) YAMLs, CR, CRD from the deploy directory of the project. With --installer olm chectl uses catalog source index image with olm bundles from the bundle directory.

Deploy Che operator with chectl using --installer operator flag

  1. Build your custom operator image, see How to Build che-operator Image.

  2. Deploy Eclipse Che on a running k8s cluster:

$ chectl server:deploy --installer operator -p <PLATFORM> --che-operator-image=${IMAGE_REGISTRY_HOST}/${IMAGE_REGISTRY_USER_NAME}/che-operator:next

Where:

  • PLATFORM - k8s platform supported by chectl.

If you have changed Che operator deployment, roles, cluster roles, CRD or CR then you must use --templates flag to point chectl to modified Che operator templates. Use make command to prepare chectl templates folder:

$ make chectl-templ TARGET=<SOME_PATH>/che-operator

Execute chectl:

$ chectl server:deploy --installer operator -p <PLATFORM> --che-operator-image=${IMAGE_REGISTRY_HOST}/${IMAGE_REGISTRY_USER_NAME}/che-operator:next --templates <SOME_PATH>/templates

Deploy Che operator with chectl using --installer olm flag

  1. Build your custom operator image, see How to Build Che operator Image.

  2. Update OLM files:

$ make update-resources -s
  1. Build catalog source and bundle images:
$ olm/buildAndPushBundleImages.sh -p <openshift|kubernetes> -c "next"
  1. Create a custom catalog source yaml (update strategy is workaround for https://github.com/operator-framework/operator-lifecycle-manager/issues/903):
apiVersion:  operators.coreos.com/v1alpha1
kind:         CatalogSource
metadata:
  name:         eclipse-che-preview-custom
  namespace:    che-namespace
spec:
  image:        <IMAGE_REGISTRY_HOST>/<IMAGE_REGISTRY_USER_NAME>/eclipse-che-<openshift|kubernetes>-opm-catalog:preview
  sourceType:  grpc
  updateStrategy:
    registryPoll:
      interval: 5m
  1. Deploy Che operator:
$ chectl server:deploy --installer=olm --platform=<CHECTL_SUPPORTED_PLATFORM> --catalog-source-yaml <PATH_TO_CUSTOM_CATALOG_SOURCE_YAML> --olm-channel=next --package-manifest-name=eclipse-che-preview-<openshift|kubernetes>

Deploy stable Che operator in Cluster Wide Availability

Eclipse Che introduced a new channel which installs Eclipse Che in AllNamespace mode with Devworkspace Operator like an OLM dependency. More info about DevWorkspace Operator can be found here.

Before installing Eclipse Che using channel tech-preview-stable-all-namespaces we need to consider the following:

  • It is not possible to have Eclipse Che installed in single Namespace (currently the default one) and then try to install Che in All Namespace mode using the new channel tech-preview-stable-all-namespaces.
  • To update to tech-preview-stable-all-namespaces channel you need first to remove all subscriptions created for Che installed from next or stable channels. IMPORTANT: Removing subscriptions doesnt mean Eclipse Che operands(che-server, keycloak or roles) will be removed from the cluster.
  • DevWorkspace engine will be by default enabled in the new channel.
  • In case if you have already installed Che with DevWorkspace engine enabled from channels next or stable you need to remove all DevWorkspace resources from the cluster following the next scripts.
  • tech-preview-stable-all-namespaces channel is supported only in OpenShift.

If the OpenShift Cluster already have all these considerations done you can proceed to install the Eclipse Che using tech-preview-stable-all-namespaces channel from OperatorHub or using the new channel you need to perform the following chectl command:

chectl server:deploy --installer=olm --platform=openshift --olm-channel=tech-preview-stable-all-namespaces

Deploy Che operator using operator-sdk

WARNING: Cluster Admin privileges are required

If you don't have operator-sdk, then you can use make command to install it:

$ make download-operator-sdk
$ sudo mv operator-sdk /usr/local/bin

Prepare bundle:

$ export BUNDLE_IMG="${IMAGE_REGISTRY_HOST}/${IMAGE_REGISTRY_USER_NAME}/che-operator-bundle:v0.0.1"
$ export PLATFORM=<kubernetes|openshift>

$ make bundle IMG="${BUNDLE_IMG}" platform="${PLATFORM}"

$ make bundle-build bundle-push BUNDLE_IMG="${BUNDLE_IMG}" platform="${PLATFORM}"

Also for this purpose you can use VSCode tast Build test bundle Kubernetes platform or Build test bundle Openshift platform.

Install che-operator and apply custom resource file/files(corresponding VSCode task: Install che-operator via OLM):

$ operator-sdk run bundle "${BUNDLE_IMG}" --namespace "${NAMESPACE}";

$ make -s apply-cr-crd ECLIPSE_CHE_NAMESPACE="${NAMESPACE}"

To uninstall Che operator(corresponding VSCode task is UnInstall che-operator via OLM Openshift or UnInstall che-operator via OLM Kubernetes):

$ operator-sdk cleanup eclipse-che-preview-<kubernetes|openshift>

Deploy Che operator for different usecases

Workspace namespace strategy

Workspace namespace strategy defines default namespace in which user's workspaces are created. It's possible to use , and placeholders (e.g.: che-workspace-). 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:

$ 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:

spec:
  server:
    customCheProperties:
      CHE_INFRA_KUBERNETES_NAMESPACE_DEFAULT: "che-workspace-<username>"
$ 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.

To disable OpenShift OAuth use command line:

```bash
$ kubectl patch checluster/eclipse-che -n <ECLIPSE-CHE-NAMESPACE> --type=merge -p '{"spec":{"auth":{"openShiftoAuth": false}}}'

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

spec:
  auth:
    openShiftoAuth: false
$ chectl server:update -n <ECLIPSE-CHE-NAMESPACE> --che-operator-cr-patch-yaml <PATH_TO_CR_PATCH_YAML>

TLS

TLS is enabled by default. Turning it off is not recommended as it will cause malfunction of some components. But for development purposes you can do that:

$ kubectl patch checluster/eclipse-che -n <ECLIPSE-CHE-NAMESPACE> --type=merge -p '{"spec":{"server":{"tlsSupport": false}}}'

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

spec:
  server:
    tlsSupport: false
$ chectl server:update -n <ECLIPSE-CHE-NAMESPACE> --che-operator-cr-patch-yaml <PATH_TO_CR_PATCH_YAML>

TLS with OpenShift

When the cluster is configured to use self-signed certificates for the router, the certificate is automatically propagated to Che components as trusted. If cluster router uses certificate signed by self-signed one, then parent/root CA certificate should be added into corresponding config map of additional trusted certificates (see serverTrustStoreConfigMapName option).

TLS with K8S

By default self-signed certificates for Che will be generated automatically. If it is needed to use your own certificates, create che-tls secret (see k8s.tlsSecretName option) with key.crt and tls.crt fields. In case of self-signed certificate self-signed-certificate secret should be created with the public part of CA certificate under ca.crt key in secret data. It is possible to use default certificate of Kubernetes cluster by passing empty string as a value of tlsSecretName:

spec:
  k8s:
    tlsSecretName: ''

Update Che operator deployment

Edit checluster custom resource using a command-line interface (terminal)

You can modify any Kubernetes object using the UI (for example OpenShift web console) or you can also modify Kubernetes objects using the terminal:

$ kubectl edit checluster eclipse-che -n <ECLIPSE-CHE-NAMESPACE>

or:

$ kubectl patch checluster/eclipse-che --type=merge -p '<PATCH_JSON>' -n <ECLIPSE-CHE-NAMESPACE>

Update checluster using chectl

You can update Che configuration using the chectl server:update command providing --cr-patch flag. See chectl for more details.

Development

Debug Che operator

You can run/debug this operator on your local machine (without deploying to a k8s cluster).

Go client grabs kubeconfig either from InClusterConfig or ~/.kube locally. Make sure your current kubectl context points to a target cluster and namespace and a current user can create objects in a target namespace.

`make debug ECLIPSE_CHE_NAMESPACE=<ECLIPSE-CHE-NAMESPACE> ECLIPSE_CHE_CR=<CUSTOM_RESOURCE_PATH>

Where:

  • ECLIPSE-CHE-NAMESPACE - namespace name to deploy Che operator into, default is che
  • CUSTOM_RESOURCE - path to custom resource yaml, default is ./config/samples/org.eclipse.che_v1_checluster.yaml

Use VSCode debug configuration Che Operator to attach to the running process.

To uninstall che-operator use:

$ make uninstall

And then interrupt debug process by CTRL+C.

Run unit tests

Che operator covered with unit tests. Some of them uses mocks. To run tests use VSCode task Run che-operator tests or run in the terminal in the root of the project:

$ go test -mod=vendor -v ./...

Compile Che operator code

The operator will be compiled to the binary /tmp/che-operator/che-operator. This command is useful to make sure that che-operator is still compiling after your changes. Run VSCode task: Compile che-operator code or use the terminal:

$ GOOS=linux GOARCH=${ARCH} CGO_ENABLED=0 GO111MODULE=on go build -mod=vendor -a -o /tmp/che-operator/che-operator main.go

Format code

Run the VSCode task: Format che-operator code or use the terminal:

$ go fmt ./...

Fix imports

Run the VSCode task: Fix che-operator imports or use the terminal:

$ find . -not -path \"./vendor/*\" -name '*.go' -exec goimports -l -w {} \\;

Update golang dependencies

Che operator uses Go modules and a vendor folder. Run the VSCode task: Update che-operator dependencies or use the terminal:

$ go mod tidy
$ go mod vendor

New golang dependencies in the vendor folder should be committed and included in the pull request.

Notice: freeze all new transitive dependencies using "replaces" go.mod file section to prevent CQ issues.

Updating Custom Resource Definition file

Che cluster custom resource definition (CRD) defines Eclipse CheCluster custom resource object. It contains information about object structure, field types, field descriptions. CRD file is a YAML definition located in the folder config/crd/bases. These files are auto-generated, so do not edit it directly to update them. If you want to add new fields or fix descriptions in the CRDs, make your changes in the file api/v1/checluster_types.go and run VSCode task Update CR/CRDs or use the terminal:

$ make generate; make manifests

This command will update CRD files:

  • config/crd/bases/org_v1_che_crd.yaml
  • config/crd/bases/org_v1_che_crd-v1beta1.yaml
  • config/crd/bases/org.eclipse.che_chebackupserverconfigurations_crd-v1beta1.yaml
  • config/crd/bases/org.eclipse.che_chebackupserverconfigurations_crd.yaml
  • config/crd/bases/org.eclipse.che_checlusterbackups_crd-v1beta1.yaml
  • config/crd/bases/org.eclipse.che_checlusterbackups_crd.yaml
  • config/crd/bases/org.eclipse.che_checlusterrestores_crd-v1beta1.yaml
  • config/crd/bases/org.eclipse.che_checlusterrestores_crd.yaml

CRD beta yamls should be used for back compatibility with Openshift 3.

Update OLM bundle

Sometimes, during development, you need to modify some YAML definitions in the config folder or Che cluster custom resource. There are most frequently changes which should be included to the new OLM bundle:

  • operator deployment config/manager/manager.yaml
  • operator roles/cluster roles permissions. They are defined like role/rolebinding or cluster role/rolebinding yamls in the config folder.
  • operator custom resource CR config/crd/bases/org_v1_che_cr.yaml. This file contains the default CheCluster sample. Also this file is the default OLM CheCluster sample.
  • Che cluster custom resource definition api/v1/checluster_types.go. For example you want to fix some properties description or apply new Che type properties with default values. These changes affect CRD config/crd/bases/org_v1_che_crd.yaml.
  • add Openshift ui annotations for Che types properties (api/v1/checluster_types.go) to display information or interactive elements on the Openshift user interface.

For all these cases it's a necessary to generate a new OLM bundle to make these changes working with OLM. Run the VSCode tasks Update resources or use the terminal:

$ make update-resources -s

Every changes will be included to the bundle folder and will override all previous changes. OLM bundle changes should be committed to the pull request.

To update a bundle without version incrementation and time update you can use env variables NO_DATE_UPDATE and NO_INCREMENT. For example, during development you need to update bundle a lot of times with changed che-operator deployment or role, rolebinding and etc, but you don't want to increment the bundle version and time creation, when all desired changes were completed:

$ make update-resources NO_DATE_UPDATE="true" NO_INCREMENT="true" -s

Che operator PR checks

Documentation about all Che operator test cases can be found here

Generate go mocks.

Install mockgen tool:

$ GO111MODULE=on go get github.com/golang/mock/mockgen@v1.4.4

Generate new mock for go interface. Example:

$ mockgen -source=pkg/util/process.go -destination=mocks/pkg/util/process_mock.go -package mock_util

$ mockgen -source=pkg/controller/che/oauth_initial_htpasswd_provider.go \
          -destination=mocks/pkg/controller/che/oauth_initial_htpasswd_provider_mock.go \
          -package mock_che

See more: https://github.com/golang/mock/blob/master/README.md

Validation licenses for runtime dependencies

che-operator is an Eclipse Foundation project. So we have to use only open source runtime dependencies with Eclipse compatible license https://www.eclipse.org/legal/licenses.php. Runtime dependencies license validation process described here: https://www.eclipse.org/projects/handbook/#ip-third-party To merge code with third party dependencies you have to follow process: https://www.eclipse.org/projects/handbook/#ip-prereq-diligence When you are using new golang dependencies you have to validate the license for transitive dependencies too. You can skip license validation for test dependencies. All new dependencies you can find using git diff in the go.sum file.

Sometimes in the go.sum file you can find few versions for the same dependency:

...
github.com/go-openapi/analysis v0.18.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik=
github.com/go-openapi/analysis v0.19.2/go.mod h1:3P1osvZa9jKjb8ed2TPng3f0i/UY9snX6gxi44djMjk=
...

In this case will be used only one version(the highest) in the runtime, so you need to validate license for only one of them(the latest). But also you can find module path https://golang.org/ref/mod#module-path with major version suffix in the go.sum file:

...
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.1.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
...

In this case we have the same dependency, but with different major versions suffix. Main project module uses both these versions in runtime. So both of them should be validated.

Also there is some useful golang commands to take a look full list dependencies:

$ go list -mod=mod -m all

This command returns all test and runtime dependencies. Like mentioned above, you can skip test dependencies.

If you want to know dependencies relation you can build dependencies graph:

$ go mod graph

IMPORTANT: Dependencies validation information should be stored in the DEPENDENCIES.md file.