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

Refactor deploy package #474

Merged
merged 6 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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 e2e/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func newOAuthConfig(c *rest.Config) (*OauthClient, error) {
return &OauthClient{restClient: client}, nil
}

func addKnownTypes(scheme *runtime.Scheme) (error) {
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&orgv1.CheCluster{},
&orgv1.CheClusterList{},
Expand Down
1 change: 0 additions & 1 deletion e2e/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package main

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

)

func deleteNamespace() (err error) {
Expand Down
3 changes: 1 addition & 2 deletions e2e/deserialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func deserializeOperatorRoleBinding() (operatorServiceAccountRoleBinding *rbac.R
return operatorServiceAccountRoleBinding, nil
}


func deserializeOperatorClusterRoleBinding() (operatorServiceAccountClusterRoleBinding *rbac.ClusterRoleBinding, err error) {
fileLocation, err := filepath.Abs("deploy/cluster_role_binding.yaml")
if err != nil {
Expand All @@ -140,4 +139,4 @@ func deserializeOperatorClusterRoleBinding() (operatorServiceAccountClusterRoleB
}
operatorServiceAccountClusterRoleBinding = object.(*rbac.ClusterRoleBinding)
return operatorServiceAccountClusterRoleBinding, nil
}
}
8 changes: 4 additions & 4 deletions e2e/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func getOauthClient(name string)(oAuthClient *oauth.OAuthClient, err error) {

func getOauthClient(name string) (oAuthClient *oauth.OAuthClient, err error) {
oAuthClient = &oauth.OAuthClient{}
err = oauthClientSet.restClient.Get().Name(name).Resource("oauthclients").Do().Into(oAuthClient)
if err != nil && errors.IsNotFound(err) {
return nil, err
}
return oAuthClient,nil
return oAuthClient, nil
}


func getConfigMap(cmName string) (cm *corev1.ConfigMap, err error) {

cm, err = client.clientset.CoreV1().ConfigMaps(namespace).Get(cmName, metav1.GetOptions{})
Expand All @@ -35,4 +35,4 @@ func getConfigMap(cmName string) (cm *corev1.ConfigMap, err error) {
}
return cm, nil

}
}
8 changes: 4 additions & 4 deletions e2e/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
func patchCustomResource(path string, value bool) (err error) {

type PatchSpec struct {
Operation string `json:"op"`
Path string `json:"path"`
Value bool `json:"value"`
Operation string `json:"op"`
Path string `json:"path"`
Value bool `json:"value"`
}

fields := make([]PatchSpec, 1)
Expand All @@ -42,4 +42,4 @@ func patchCustomResource(path string, value bool) (err error) {
}

return nil
}
}
2 changes: 0 additions & 2 deletions e2e/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,3 @@ func VerifyCheRunning(status string) (deployed bool, err error) {
}
}
}


40 changes: 23 additions & 17 deletions pkg/controller/che/che_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ package che
import (
"context"
"fmt"
"github.com/eclipse/che-operator/pkg/deploy/devfile-registry"
"github.com/eclipse/che-operator/pkg/deploy/gateway"
"github.com/eclipse/che-operator/pkg/deploy/identity-provider"
"github.com/eclipse/che-operator/pkg/deploy/plugin-registry"
"github.com/eclipse/che-operator/pkg/deploy/postgres"
"github.com/eclipse/che-operator/pkg/deploy/server"
"strconv"
"time"

Expand Down Expand Up @@ -615,11 +621,11 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
externalDB := instance.Spec.Database.ExternalDb
if !externalDB {
if cheMultiUser == "false" {
if util.K8sclient.IsDeploymentExists(deploy.PostgresDeploymentName, instance.Namespace) {
util.K8sclient.DeleteDeployment(deploy.PostgresDeploymentName, instance.Namespace)
if util.K8sclient.IsDeploymentExists(postgres.PostgresDeploymentName, instance.Namespace) {
util.K8sclient.DeleteDeployment(postgres.PostgresDeploymentName, instance.Namespace)
}
} else {
postgresLabels := deploy.GetLabels(instance, deploy.PostgresDeploymentName)
postgresLabels := deploy.GetLabels(instance, postgres.PostgresDeploymentName)

// Create a new postgres service
serviceStatus := deploy.SyncServiceToCluster(deployContext, "postgres", []string{"postgres"}, []int32{5432}, postgresLabels)
Expand Down Expand Up @@ -648,10 +654,10 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}

// Create a new Postgres deployment
deploymentStatus := deploy.SyncPostgresDeploymentToCluster(deployContext)
deploymentStatus := postgres.SyncPostgresDeploymentToCluster(deployContext)
if !tests {
if !deploymentStatus.Continue {
logrus.Infof("Waiting on deployment '%s' to be ready", deploy.PostgresDeploymentName)
logrus.Infof("Waiting on deployment '%s' to be ready", postgres.PostgresDeploymentName)
if deploymentStatus.Err != nil {
logrus.Error(deploymentStatus.Err)
}
Expand All @@ -671,11 +677,11 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}
identityProviderPostgresPassword = password
}
pgCommand := deploy.GetPostgresProvisionCommand(identityProviderPostgresPassword)
pgCommand := identity_provider.GetPostgresProvisionCommand(identityProviderPostgresPassword)
dbStatus := instance.Status.DbProvisoned
// provision Db and users for Che and Keycloak servers
if !dbStatus {
podToExec, err := util.K8sclient.GetDeploymentPod(deploy.PostgresDeploymentName, instance.Namespace)
podToExec, err := util.K8sclient.GetDeploymentPod(postgres.PostgresDeploymentName, instance.Namespace)
if err != nil {
return reconcile.Result{}, err
}
Expand Down Expand Up @@ -705,7 +711,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}

// create Che service and route
serviceStatus := deploy.SyncCheServiceToCluster(deployContext)
serviceStatus := server.SyncCheServiceToCluster(deployContext)
if !tests {
if !serviceStatus.Continue {
logrus.Infof("Waiting on service '%s' to be ready", deploy.CheServiceName)
Expand Down Expand Up @@ -766,7 +772,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}

// create and provision Keycloak related objects
provisioned, err := deploy.SyncIdentityProviderToCluster(deployContext, cheHost, protocol, cheFlavor)
provisioned, err := identity_provider.SyncIdentityProviderToCluster(deployContext, cheHost, protocol, cheFlavor)
if !tests {
if !provisioned {
if err != nil {
Expand All @@ -776,7 +782,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}
}

provisioned, err = deploy.SyncDevfileRegistryToCluster(deployContext, cheHost)
provisioned, err = devfile_registry.SyncDevfileRegistryToCluster(deployContext, cheHost)
if !tests {
if !provisioned {
if err != nil {
Expand All @@ -786,7 +792,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}
}

provisioned, err = deploy.SyncPluginRegistryToCluster(deployContext, cheHost)
provisioned, err = plugin_registry.SyncPluginRegistryToCluster(deployContext, cheHost)
if !tests {
if !provisioned {
if err != nil {
Expand All @@ -805,10 +811,10 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e

// create Che ConfigMap which is synced with CR and is not supposed to be manually edited
// controller will reconcile this CM with CR spec
cheConfigMap, err := deploy.SyncCheConfigMapToCluster(deployContext)
cheConfigMap, err := server.SyncCheConfigMapToCluster(deployContext)
if !tests {
if cheConfigMap == nil {
logrus.Infof("Waiting on config map '%s' to be created", deploy.CheConfigMapName)
logrus.Infof("Waiting on config map '%s' to be created", server.CheConfigMapName)
if err != nil {
logrus.Error(err)
}
Expand All @@ -820,19 +826,19 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
// which will automatically trigger Che rolling update
var cmResourceVersion string
if tests {
cmResourceVersion = r.GetEffectiveConfigMap(instance, deploy.CheConfigMapName).ResourceVersion
cmResourceVersion = r.GetEffectiveConfigMap(instance, server.CheConfigMapName).ResourceVersion
} else {
cmResourceVersion = cheConfigMap.ResourceVersion
}

err = deploy.SyncGatewayToCluster(deployContext)
err = gateway.SyncGatewayToCluster(deployContext)
if err != nil {
logrus.Errorf("Failed to create the Server Gateway: %s", err)
return reconcile.Result{}, err
}

// Create a new che deployment
deploymentStatus := deploy.SyncCheDeploymentToCluster(deployContext, cmResourceVersion)
deploymentStatus := server.SyncCheDeploymentToCluster(deployContext, cmResourceVersion)
if !tests {
if !deploymentStatus.Continue {
logrus.Infof("Waiting on deployment '%s' to be ready", cheFlavor)
Expand Down Expand Up @@ -1007,7 +1013,7 @@ func getDefaultCheHost(deployContext *deploy.DeployContext) (string, error) {

func getServerExposingServiceName(cr *orgv1.CheCluster) string {
if cr.Spec.Server.ServerExposureStrategy == "single-host" && deploy.GetSingleHostExposureType(cr) == "gateway" {
return deploy.GatewayServiceName
return gateway.GatewayServiceName
}
return deploy.CheServiceName
}
3 changes: 2 additions & 1 deletion pkg/controller/che/che_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package che

import (
"context"
identity_provider "github.com/eclipse/che-operator/pkg/deploy/identity-provider"
"io/ioutil"
"os"
"time"
Expand Down Expand Up @@ -189,7 +190,7 @@ func TestCheController(t *testing.T) {
if err = r.client.Get(context.TODO(), types.NamespacedName{Name: cheCR.Name, Namespace: cheCR.Namespace}, cheCR); err != nil {
t.Errorf("Failed to get the Che custom resource %s: %s", cheCR.Name, err)
}
if err = deploy.CreateIdentityProviderItems(deployContext, "che"); err != nil {
if err = identity_provider.CreateIdentityProviderItems(deployContext, "che"); err != nil {
t.Errorf("Failed to create the items for the identity provider: %s", err)
}
oAuthClientName := cheCR.Spec.Auth.OAuthClientName
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/che/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package che

import (
"context"
"github.com/eclipse/che-operator/pkg/deploy/server"

orgv1 "github.com/eclipse/che-operator/pkg/apis/org/v1"
"github.com/eclipse/che-operator/pkg/deploy"
Expand Down Expand Up @@ -55,6 +56,6 @@ func (r *ReconcileChe) putOpenShiftCertsIntoConfigMap(deployContext *deploy.Depl
}
}

certConfigMap, err := deploy.SyncTrustStoreConfigMapToCluster(deployContext)
certConfigMap, err := server.SyncTrustStoreConfigMapToCluster(deployContext)
return certConfigMap != nil, err
}
4 changes: 2 additions & 2 deletions pkg/controller/che/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ package che

import (
"context"
identity_provider "github.com/eclipse/che-operator/pkg/deploy/identity-provider"

orgv1 "github.com/eclipse/che-operator/pkg/apis/org/v1"
"github.com/eclipse/che-operator/pkg/deploy"
"github.com/eclipse/che-operator/pkg/util"
oauth "github.com/openshift/api/oauth/v1"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -51,7 +51,7 @@ func (r *ReconcileChe) ReconcileIdentityProvider(instance *orgv1.CheCluster, isO
if err := r.client.Get(context.TODO(), types.NamespacedName{Name: "keycloak", Namespace: instance.Namespace}, keycloakDeployment); err != nil {
logrus.Errorf("Deployment %s not found: %s", keycloakDeployment.Name, err)
}
deleteOpenShiftIdentityProviderProvisionCommand := deploy.GetDeleteOpenShiftIdentityProviderProvisionCommand(instance, isOpenShift4)
deleteOpenShiftIdentityProviderProvisionCommand := identity_provider.GetDeleteOpenShiftIdentityProviderProvisionCommand(instance, isOpenShift4)
podToExec, err := util.K8sclient.GetDeploymentPod(keycloakDeployment.Name, instance.Namespace)
if err != nil {
logrus.Errorf("Failed to retrieve pod name. Further exec will fail")
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions pkg/deploy/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func SyncConfigMapToCluster(deployContext *DeployContext, specConfigMap *corev1.ConfigMap) (*corev1.ConfigMap, error) {
clusterConfigMap, err := getClusterConfigMap(specConfigMap.Name, specConfigMap.Namespace, deployContext.ClusterAPI.Client)
clusterConfigMap, err := GetClusterConfigMap(specConfigMap.Name, specConfigMap.Namespace, deployContext.ClusterAPI.Client)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func GetSpecConfigMap(
return configMap, nil
}

func getClusterConfigMap(name string, namespace string, client runtimeClient.Client) (*corev1.ConfigMap, error) {
func GetClusterConfigMap(name string, namespace string, client runtimeClient.Client) (*corev1.ConfigMap, error) {
configMap := &corev1.ConfigMap{}
namespacedName := types.NamespacedName{
Namespace: namespace,
Expand Down
9 changes: 9 additions & 0 deletions pkg/deploy/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package deploy
Copy link
Contributor

Choose a reason for hiding this comment

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

Add licence header, please.


const (
DevfileRegistry = "devfile-registry"
)

const (
PluginRegistry = "plugin-registry"
)
6 changes: 3 additions & 3 deletions pkg/deploy/data_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ type ProvisioningStatus struct {
}

type DeployContext struct {
CheCluster *orgv1.CheCluster
ClusterAPI ClusterAPI
Proxy *Proxy
CheCluster *orgv1.CheCluster
ClusterAPI ClusterAPI
Proxy *Proxy
DefaultCheHost string
}

Expand Down
Loading