Skip to content

Commit

Permalink
Fixes to unit tests and improve scripts descriptions
Browse files Browse the repository at this point in the history
Signed-off-by: Flavius Lacatusu <flacatus@redhat.com>
  • Loading branch information
flacatus committed Jul 27, 2021
1 parent c73db2a commit 052abd2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ Before installing Eclipse Che using channel `stable-all-namespaces` we need to c
* To update to stable-all-namespaces channel you need first to remove all subscriptions created for che installed from nightly or stable
channels. IMPORTANT: Removing subscriptions doesn’t 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 enabled from channels nightly or stable you need to uninstall DevWorkspace completely from the cluster and then install the Che Operator using stable-all-namespaces channel.
* In case if you have already installed Che with DevWorkspace engine enabled from channels nightly or stable you need to remove all DevWorkspace resources from the cluster following the next [scripts](https://github.com/devfile/devworkspace-operator/blob/main/build/make/deploy.mk#L77).
* `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 stable-all-namespaces channel from OperatorHub or using the new channel you need to perform next chectl command:

```bash
chectl server:deploy --installer=olm --platform=openshift --olm-channel=stable-all-namespaces
chectl server:deploy --installer=olm --platform=openshift --olm-channel=stable-all-namespaces
```

### Deploy Che operator using operator-sdk
Expand Down
5 changes: 4 additions & 1 deletion olm/prepare-community-operators-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ do
if [[ "${lastPackagePreReleaseVersion}" == "${lastPublishedPackageVersion}" ]] && [[ "${FORCE}" == "" ]]; then
echo "#### ERROR ####"
echo "Release ${lastPackagePreReleaseVersion} already exists in the '${platformSubFolder}/eclipse-che' package !"
#exit 1
exit 1
fi
echo $lastPackagePreReleaseVersion
echo $platform
Expand All @@ -152,14 +152,17 @@ do
sed -e "s/${lastPublishedPackageVersion}/${lastPackagePreReleaseVersion}/" "${destinationPackageFilePath}" > "${destinationPackageFilePath}.new"
echo

# Append to community operators the stable channel csv version: https://github.com/operator-framework/community-operators/blob/master/community-operators/eclipse-che/eclipse-che.package.yaml
if [[ $channel == "stable" ]]; then
mv "${destinationPackageFilePath}.new" "${destinationPackageFilePath}"
fi

# Append to community operators the stable-all-namespaces channel csv version: https://github.com/operator-framework/community-operators/blob/master/community-operators/eclipse-che/eclipse-che.package.yaml
if [[ $channel == "stable-all-namespaces" ]]; then
yq -riY ".channels[1] = { \"currentCSV\": \"eclipse-che.v${lastPackagePreReleaseVersion}\", \"name\": \"$channel\"}" $destinationPackageFilePath
fi
done
# Make by default stable channel in the community operators eclipse-che.package.yaml
yq -Yi '.defaultChannel |= "stable"' ${destinationPackageFilePath}

# NOTE: if you update this file, you need to submit a PR against these two files:
Expand Down
6 changes: 3 additions & 3 deletions pkg/deploy/dev-workspace/dev_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func ReconcileDevWorkspace(deployContext *deploy.DeployContext) (bool, error) {
}

// Check if exists devworkspace operator csv is already installed
devWorkspaceOperatorCSVExists := devWorkspaceControllerCSVExists(deployContext)
devWorkspaceOperatorCSVExists := isDevWorkspaceControllerCSVExists(deployContext)
if devWorkspaceOperatorCSVExists {
return true, nil
}
Expand Down Expand Up @@ -161,14 +161,14 @@ func ReconcileDevWorkspace(deployContext *deploy.DeployContext) (bool, error) {
return true, nil
}

func devWorkspaceControllerCSVExists(deployContext *deploy.DeployContext) bool {
func isDevWorkspaceControllerCSVExists(deployContext *deploy.DeployContext) bool {
// If clusterserviceversions resource doesn't exist in cluster DWO as well will not be present
if !util.HasK8SResourceObject(deployContext.ClusterAPI.DiscoveryClient, ClusterServiceVersionResourceName) {
return false
}

csvList := &operatorsv1alpha1.ClusterServiceVersionList{}
err := deployContext.ClusterAPI.NonCachedClient.List(context.TODO(), csvList, &client.ListOptions{})
err := deployContext.ClusterAPI.Client.List(context.TODO(), csvList, &client.ListOptions{})
if err != nil {
return false
}
Expand Down
19 changes: 15 additions & 4 deletions pkg/deploy/dev-workspace/dev_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
package devworkspace

import (
"context"

orgv1 "github.com/eclipse-che/che-operator/api/v1"
"github.com/eclipse-che/che-operator/pkg/deploy"
"github.com/eclipse-che/che-operator/pkg/util"
Expand All @@ -21,6 +23,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
fakeDiscovery "k8s.io/client-go/discovery/fake"
"sigs.k8s.io/controller-runtime/pkg/client"

"testing"
)
Expand Down Expand Up @@ -212,12 +215,14 @@ func TestReconcileDevWorkspaceCheckIfCSVExists(t *testing.T) {

deployContext := deploy.GetTestDeployContext(cheCluster, []runtime.Object{})
deployContext.ClusterAPI.Scheme.AddKnownTypes(operatorsv1alpha1.SchemeGroupVersion, &operatorsv1alpha1.ClusterServiceVersion{})
deployContext = deploy.GetTestDeployContext(cheCluster, []runtime.Object{devWorkspaceCSV})
deployContext.ClusterAPI.Scheme.AddKnownTypes(admissionregistrationv1.SchemeGroupVersion, &admissionregistrationv1.MutatingWebhookConfiguration{})
deployContext.ClusterAPI.Scheme.AddKnownTypes(operatorsv1alpha1.SchemeGroupVersion, &operatorsv1alpha1.ClusterServiceVersionList{})
deployContext.ClusterAPI.Client.Create(context.TODO(), devWorkspaceCSV)
deployContext.ClusterAPI.DiscoveryClient.(*fakeDiscovery.FakeDiscovery).Fake.Resources = []*metav1.APIResourceList{
{
APIResources: []metav1.APIResource{
{Name: ClusterServiceVersionResourceName},
{
Name: ClusterServiceVersionResourceName,
},
},
},
}
Expand All @@ -227,7 +232,13 @@ func TestReconcileDevWorkspaceCheckIfCSVExists(t *testing.T) {
reconciled, _ := ReconcileDevWorkspace(deployContext)

if !reconciled {
t.Fatalf("Test Failed... DevWorkspace CSV is expected to be craeted")
t.Fatalf("Failed to reconcile DevWorkspace")
}

// Get Devworkspace namespace. If error is thrown means devworkspace is not anymore installed if CSV is detected
err := deployContext.ClusterAPI.Client.Get(context.TODO(), client.ObjectKey{Name: DevWorkspaceNamespace}, &corev1.Namespace{})
if err == nil {
t.Fatal("Failed to reconcile DevWorkspace when DWO CSV is exptected to be created")
}
}

Expand Down

0 comments on commit 052abd2

Please sign in to comment.