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

Include registries in Che deployment #51

Merged
merged 11 commits into from
Jul 19, 2019
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: checlusters.org.eclipse.che
spec:
group: org.eclipse.che
names:
kind: CheCluster
listKind: CheClusterList
plural: checlusters
singular: checluster
scope: Namespaced
version: v1
subresources:
status: {}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ channels:
- name: stable
currentCSV: eclipse-che-preview-kubernetes.v7.0.0-rc-2.0
- name: nightly
currentCSV: eclipse-che-preview-kubernetes.v9.9.9-nightly.1563282936
currentCSV: eclipse-che-preview-kubernetes.v9.9.9-nightly.1563539196
defaultChannel: stable
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: checlusters.org.eclipse.che
spec:
group: org.eclipse.che
names:
kind: CheCluster
listKind: CheClusterList
plural: checlusters
singular: checluster
scope: Namespaced
version: v1
subresources:
status: {}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ channels:
- name: stable
currentCSV: eclipse-che-preview-openshift.v7.0.0-rc-2.0
- name: nightly
currentCSV: eclipse-che-preview-openshift.v9.9.9-nightly.1563282936
currentCSV: eclipse-che-preview-openshift.v9.9.9-nightly.1563539196
defaultChannel: stable
2 changes: 2 additions & 0 deletions olm/release-olm-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ do
-e 's/imagePullPolicy: *Always/imagePullPolicy: IfNotPresent/' \
-e 's/"cheImageTag": *"nightly"/"cheImageTag": ""/' \
-e 's|"identityProviderImage": *"eclipse/che-keycloak:nightly"|"identityProviderImage": ""|' \
-e 's|"devfileRegistryImage": *"quay.io/eclipse/che-devfile-registry:nightly"|"devfileRegistryImage": ""|' \
-e 's|"pluginRegistryImage": *"quay.io/eclipse/che-plugin-registry:nighlty"|"pluginRegistryImage": ""|' \
-e "/^ replaces: ${packageName}.v.*/d" \
-e "s/^ version: ${lastPackageNightlyVersion}/ version: ${RELEASE}/" \
-e "/^ version: ${RELEASE}/i\ \ replaces: ${packageName}.v${lastPackagePreReleaseVersion}" \
Expand Down
29 changes: 29 additions & 0 deletions pkg/apis/org/v1/che_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1 "k8s.io/api/core/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down Expand Up @@ -52,8 +53,32 @@ type CheClusterSpecServer struct {
TlsSupport bool `json:"tlsSupport"`
// DevfileRegistryUrl is an endpoint serving sample ready-to-use devfiles. Defaults to https://che-devfile-registry.openshift.io
DevfileRegistryUrl string `json:"devfileRegistryUrl"`
// DevfileRegistryImage is image:tag used in Devfile registry deployment
DevfileRegistryImage string `json:"devfileRegistryImage"`
// DevfileRegistryImagePullPolicy is the image pull policy used in Devfile registry deployment
DevfileRegistryImagePullPolicy corev1.PullPolicy `json:"devfileRegistryPullPolicy"`
// DevfileRegistryMemoryLimit is the memory limit used in Devfile registry deployment
DevfileRegistryMemoryLimit string `json:"devfileRegistryMemoryLimit"`
// DevfileRegistryMemoryRequest is the memory request used in Devfile registry deployment
DevfileRegistryMemoryRequest string `json:"devfileRegistryMemoryRequest"`
// ExternalDevfileRegistry instructs operator on whether or not to deploy a dedicated Devfile registry server
// By default a dedicated devfile registry server is started.
// But if ExternalDevfileRegistry is `true`, then no such dedicated server will be started by the operator
ExternalDevfileRegistry bool `json:"externalDevfileRegistry"`
// PluginRegistryUrl is an endpoint serving plugin definitions. Defaults to https://che-plugin-registry.openshift.io
PluginRegistryUrl string `json:"pluginRegistryUrl"`
// PluginRegistryImage is image:tag used in Plugin registry deployment
PluginRegistryImage string `json:"pluginRegistryImage"`
// PluginRegistryImagePullPolicy is the image pull policy used in Plugin registry deployment
PluginRegistryImagePullPolicy corev1.PullPolicy `json:"pluginRegistryPullPolicy"`
// PluginRegistryMemoryLimit is the memory limit used in Plugin registry deployment
PluginRegistryMemoryLimit string `json:"pluginRegistryMemoryLimit"`
// PluginRegistryMemoryRequest is the memory request used in Plugin registry deployment
PluginRegistryMemoryRequest string `json:"pluginRegistryMemoryRequest"`
// ExternalPluginRegistry instructs operator on whether or not to deploy a dedicated Plugin registry server
// By default a dedicated plugin registry server is started.
// But if ExternalPluginRegistry is `true`, then no such dedicated server will be started by the operator
ExternalPluginRegistry bool `json:"externalPluginRegistry"`
// ProxyURL is protocol+hostname of a proxy server. Automatically added as JAVA_OPTS and https(s)_proxy
// to Che server and workspaces containers
ProxyURL string `json:"proxyURL"`
Expand Down Expand Up @@ -170,6 +195,10 @@ type CheClusterStatus struct {
CheURL string `json:"cheURL"`
// KeycloakURL is Keycloak protocol+route/ingress
KeycloakURL string `json:"keycloakURL"`
// DevfileRegistryURL is the Devfile registry protocol+route/ingress
DevfileRegistryURL string `json:"devfileRegistryURL"`
// PluginRegistryURL is the Plugin registry protocol+route/ingress
PluginRegistryURL string `json:"pluginRegistryURL"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
145 changes: 145 additions & 0 deletions pkg/controller/che/che_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}
}
}

cheFlavor := util.GetValue(instance.Spec.Server.CheFlavor, deploy.DefaultCheFlavor)
ingressStrategy := util.GetValue(instance.Spec.K8SOnly.IngressStrategy, deploy.DefaultIngressStrategy)
ingressDomain := instance.Spec.K8SOnly.IngressDomain
Expand All @@ -375,6 +376,150 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
if tlsSupport {
protocol = "https"
}

addRegistryRoute := func (registryType string) (string, error) {
registryName := "che-" + registryType + "-registry"
host := ""
if !isOpenShift {
ingress := deploy.NewIngress(instance, registryName, registryName, 8080)
if err := r.CreateNewIngress(instance, ingress); err != nil {
return "", err
}
host = ingressDomain
if ingressStrategy == "multi-host" {
host = registryName + "-" + instance.Namespace + "." + ingressDomain
}
} else {
route := deploy.NewRoute(instance, registryName, registryName, 8080)
if tlsSupport {
route = deploy.NewTlsRoute(instance, registryName, registryName, 8080)
}
if err := r.CreateNewRoute(instance, route); err != nil {
return "", err
}
host = route.Spec.Host
if len(host) < 1 {
cheRoute := r.GetEffectiveRoute(instance, route.Name)
host = cheRoute.Spec.Host
}
}
return protocol + "://" + host, nil
}

addRegistryDeployment := func (
registryType string,
registryImage string,
registryImagePullPolicy corev1.PullPolicy,
registryMemoryLimit string,
registryMemoryRequest string,
) (*reconcile.Result, error) {
registryName := "che-" + registryType + "-registry"

// Create a new registry service
registryLabels := deploy.GetLabels(instance, registryName)
registryService := deploy.NewService(instance, registryName, []string{"http"}, []int32{8080}, registryLabels)
if err := r.CreateService(instance,registryService); err != nil {
return &reconcile.Result{}, err
}
// Create a new registry deployment
registryDeployment := deploy.NewRegistryDeployment(
instance,
registryType,
registryImage,
registryImagePullPolicy,
registryMemoryLimit,
registryMemoryRequest,
)
if err := r.CreateNewDeployment(instance, registryDeployment); err != nil {
return &reconcile.Result{}, err
}
time.Sleep(time.Duration(1) * time.Second)
effectiveDeployment, err := r.GetEffectiveDeployment(instance, registryDeployment.Name)
if err != nil {
logrus.Errorf("Failed to get %s deployment: %s", registryDeployment.Name, err)
return &reconcile.Result{}, err
}
if !tests {
if effectiveDeployment.Status.AvailableReplicas != 1 {
scaled := k8sclient.GetDeploymentStatus(registryName, instance.Namespace)
if !scaled {
return &reconcile.Result{Requeue: true, RequeueAfter: time.Second * 5}, err
}
}
if effectiveDeployment.Spec.Template.Spec.Containers[0].Image != registryImage {
newDeployment := deploy.NewRegistryDeployment(
instance,
registryType,
registryImage,
registryImagePullPolicy,
registryMemoryLimit,
registryMemoryRequest,
)
logrus.Infof("Updating %s registry deployment with an image %s", registryType, registryImage)
if err := controllerutil.SetControllerReference(instance, newDeployment, r.scheme); err != nil {
logrus.Errorf("An error occurred: %s", err)
}
if err := r.client.Update(context.TODO(), newDeployment); err != nil {
logrus.Errorf("Failed to update %s registry deployment: %s", registryType, err)
}
}
}
return nil, nil
}

// Create Plugin registry resources unless an external registry is used
externalPluginRegistry := instance.Spec.Server.ExternalPluginRegistry
if !externalPluginRegistry {
pluginRegistryURL, err := addRegistryRoute("plugin")
if err != nil {
return reconcile.Result{}, err
}
if cheFlavor != "codeready" {
pluginRegistryURL += "/v3"
}
instance.Status.PluginRegistryURL = pluginRegistryURL
if err := r.UpdateCheCRStatus(instance, "status: Plugin Registry URL", pluginRegistryURL); err != nil {
instance, _ = r.GetCR(request)
return reconcile.Result{Requeue: true, RequeueAfter: time.Second * 1}, err
}

result, err := addRegistryDeployment(
"plugin",
util.GetValue(instance.Spec.Server.PluginRegistryImage, deploy.DefaultPluginRegistryImage),
corev1.PullPolicy(util.GetValue(string(instance.Spec.Server.PluginRegistryImagePullPolicy), deploy.DefaultPluginRegistryPullPolicy)),
util.GetValue(string(instance.Spec.Server.PluginRegistryMemoryLimit), deploy.DefaultPluginRegistryMemoryLimit),
util.GetValue(string(instance.Spec.Server.PluginRegistryMemoryRequest), deploy.DefaultPluginRegistryMemoryRequest),
)
if err != nil || result != nil {
return *result, err
}
}

// Create devfile registry resources unless an external registry is used
externalDevfileRegistry := instance.Spec.Server.ExternalDevfileRegistry
if !externalDevfileRegistry {
devfileRegistryURL, err := addRegistryRoute("devfile")
if err != nil {
return reconcile.Result{}, err
}
instance.Status.DevfileRegistryURL = devfileRegistryURL
if err := r.UpdateCheCRStatus(instance, "status: Devfile Registry URL", devfileRegistryURL); err != nil {
instance, _ = r.GetCR(request)
return reconcile.Result{Requeue: true, RequeueAfter: time.Second * 1}, err
}

result, err := addRegistryDeployment(
"devfile",
util.GetValue(instance.Spec.Server.DevfileRegistryImage, deploy.DefaultDevfileRegistryImage),
corev1.PullPolicy(util.GetValue(string(instance.Spec.Server.DevfileRegistryImagePullPolicy), deploy.DefaultDevfileRegistryPullPolicy)),
util.GetValue(string(instance.Spec.Server.DevfileRegistryMemoryLimit), deploy.DefaultDevfileRegistryMemoryLimit),
util.GetValue(string(instance.Spec.Server.DevfileRegistryMemoryRequest), deploy.DefaultDevfileRegistryMemoryRequest),
)
if err != nil || result != nil {
return *result, err
}
}

// create Che service and route
cheLabels := deploy.GetLabels(instance, util.GetValue(instance.Spec.Server.CheFlavor, deploy.DefaultCheFlavor))

Expand Down
10 changes: 0 additions & 10 deletions pkg/controller/che/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,17 +470,7 @@ func (r *ReconcileChe) GenerateAndSaveFields(instance *orgv1.CheCluster, request
return err
}
}
pluginRegistryUrl := util.GetValue(instance.Spec.Server.PluginRegistryUrl, deploy.DefaultUpstreamPluginRegistryUrl)
if cheFlavor == "codeready" {
pluginRegistryUrl = deploy.DefaultPluginRegistryUrl
}

if len(instance.Spec.Server.PluginRegistryUrl) < 1 {
instance.Spec.Server.PluginRegistryUrl = pluginRegistryUrl
if err := r.UpdateCheCRSpec(instance, "plugin registry URL", pluginRegistryUrl); err != nil {
return err
}
}
cheLogLevel := util.GetValue(instance.Spec.Server.CheLogLevel, deploy.DefaultCheLogLevel)
if len(instance.Spec.Server.CheLogLevel) < 1 {
instance.Spec.Server.CheLogLevel = cheLogLevel
Expand Down
11 changes: 7 additions & 4 deletions pkg/deploy/che_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ type CheConfigMap struct {
WorkspaceHttpProxy string `json:"CHE_WORKSPACE_HTTP__PROXY"`
WorkspaceHttpsProxy string `json:"CHE_WORKSPACE_HTTPS__PROXY"`
WorkspaceNoProxy string `json:"CHE_WORKSPACE_NO__PROXY"`
PluginRegistryUrl string `json:"CHE_WORKSPACE_PLUGIN__REGISTRY__URL"`
DevfileRegistryUrl string `json:"CHE_WORKSPACE_DEVFILE__REGISTRY__URL"`
PluginRegistryUrl string `json:"CHE_WORKSPACE_PLUGIN__REGISTRY__URL,omitempty"`
DevfileRegistryUrl string `json:"CHE_WORKSPACE_DEVFILE__REGISTRY__URL,omitempty"`
WebSocketEndpointMinor string `json:"CHE_WEBSOCKET_ENDPOINT__MINOR"`
}

Expand Down Expand Up @@ -156,8 +156,11 @@ func GetConfigMapData(cr *orgv1.CheCluster) (cheEnv map[string]string) {
keycloakClientId := util.GetValue(cr.Spec.Auth.KeycloakClientId, cheFlavor+"-public")
ingressStrategy := util.GetValue(cr.Spec.K8SOnly.IngressStrategy, DefaultIngressStrategy)
ingressClass := util.GetValue(cr.Spec.K8SOnly.IngressClass, DefaultIngressClass)
devfileRegistryUrl := util.GetValue(cr.Spec.Server.DevfileRegistryUrl, DefaultDevfileRegistryUrl)
pluginRegistryUrl := util.GetValue(cr.Spec.Server.PluginRegistryUrl, DefaultPluginRegistryUrl)
devfileRegistryUrl := cr.Status.DevfileRegistryURL
pluginRegistryUrl := cr.Status.PluginRegistryURL
if pluginRegistryUrl == "" && cheFlavor == "codeready" {
pluginRegistryUrl = DefaultCodereadyPluginRegistryUrl
}
cheLogLevel := util.GetValue(cr.Spec.Server.CheLogLevel, DefaultCheLogLevel)
cheDebug := util.GetValue(cr.Spec.Server.CheDebug, DefaultCheDebug)

Expand Down
66 changes: 36 additions & 30 deletions pkg/deploy/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,47 @@
package deploy

const (
DefaultCheServerImageRepo = "eclipse/che-server"
DefaultCodeReadyServerImageRepo = "registry.redhat.io/codeready-workspaces/server-rhel8"
DefaultCheServerImageTag = "7.0.0-RC-2.0"
DefaultCodeReadyServerImageTag = "1.2"
DefaultCheFlavor = "che"
DefaultChePostgresUser = "pgche"
DefaultChePostgresHostName = "postgres"
DefaultChePostgresPort = "5432"
DefaultChePostgresDb = "dbche"
DefaultPvcStrategy = "common"
DefaultPvcClaimSize = "1Gi"
DefaultIngressStrategy = "multi-host"
DefaultIngressClass = "nginx"
DefaultPluginRegistryUrl = "https://che-plugin-registry.openshift.io"
DefaultUpstreamPluginRegistryUrl = "https://che-plugin-registry.openshift.io/v3"
DefaultDevfileRegistryUrl = "https://che-devfile-registry.openshift.io"
DefaultKeycloakAdminUserName = "admin"
DefaultCheLogLevel = "INFO"
DefaultCheDebug = "false"
DefaultPvcJobsImage = "registry.redhat.io/ubi8-minimal:8.0-127"
DefaultPvcJobsUpstreamImage = "registry.access.redhat.com/ubi8-minimal:8.0-127"
DefaultPostgresImage = "registry.redhat.io/rhscl/postgresql-96-rhel7:1-40"
DefaultPostgresUpstreamImage = "centos/postgresql-96-centos7:9.6"
DefaultKeycloakImage = "registry.redhat.io/redhat-sso-7/sso73-openshift:1.0-11"
DefaultKeycloakUpstreamImage = "eclipse/che-keycloak:7.0.0-RC-2.0"
DefaultJavaOpts = "-XX:MaxRAMFraction=2 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 " +
DefaultCheServerImageRepo = "eclipse/che-server"
DefaultCodeReadyServerImageRepo = "registry.redhat.io/codeready-workspaces/server-rhel8"
DefaultCheServerImageTag = "7.0.0-RC-2.0"
nickboldt marked this conversation as resolved.
Show resolved Hide resolved
DefaultCodeReadyServerImageTag = "1.2"
DefaultCheFlavor = "che"
DefaultChePostgresUser = "pgche"
DefaultChePostgresHostName = "postgres"
DefaultChePostgresPort = "5432"
DefaultChePostgresDb = "dbche"
DefaultPvcStrategy = "common"
DefaultPvcClaimSize = "1Gi"
DefaultIngressStrategy = "multi-host"
DefaultIngressClass = "nginx"
DefaultPluginRegistryImage = "quay.io/eclipse/che-plugin-registry:7.0.0-RC-2.0"
DefaultPluginRegistryPullPolicy = "Always"
DefaultPluginRegistryMemoryLimit = "32Mi"
DefaultPluginRegistryMemoryRequest = "16Mi"
DefaultCodereadyPluginRegistryUrl = "https://che-plugin-registry.openshift.io"
DefaultDevfileRegistryImage = "quay.io/eclipse/che-devfile-registry:7.0.0-RC-2.0"
nickboldt marked this conversation as resolved.
Show resolved Hide resolved
DefaultDevfileRegistryPullPolicy = "Always"
DefaultDevfileRegistryMemoryLimit = "32Mi"
DefaultDevfileRegistryMemoryRequest = "16Mi"
DefaultKeycloakAdminUserName = "admin"
DefaultCheLogLevel = "INFO"
DefaultCheDebug = "false"
DefaultPvcJobsImage = "registry.redhat.io/ubi8-minimal:8.0-127"
DefaultPvcJobsUpstreamImage = "registry.access.redhat.com/ubi8-minimal:8.0-127"
DefaultPostgresImage = "registry.redhat.io/rhscl/postgresql-96-rhel7:1-40"
DefaultPostgresUpstreamImage = "centos/postgresql-96-centos7:9.6"
DefaultKeycloakImage = "registry.redhat.io/redhat-sso-7/sso73-openshift:1.0-11"
DefaultKeycloakUpstreamImage = "eclipse/che-keycloak:7.0.0-RC-2.0"
DefaultJavaOpts = "-XX:MaxRAMFraction=2 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 " +
"-XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 " +
"-XX:AdaptiveSizePolicyWeight=90 -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap " +
"-Dsun.zip.disableMemoryMapping=true -Xms20m"
DefaultWorkspaceJavaOpts = "-XX:MaxRAM=150m -XX:MaxRAMFraction=2 -XX:+UseParallelGC " +
"-XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 " +
"-Dsun.zip.disableMemoryMapping=true " +
"-Xms20m -Djava.security.egd=file:/dev/./urandom"
DefaultServerMemoryRequest = "512Mi"
DefaultServerMemoryLimit = "1Gi"
DefaultSecurityContextFsGroup = "1724"
DefaultSecurityContextRunAsUser = "1724"
DefaultServerMemoryRequest = "512Mi"
DefaultServerMemoryLimit = "1Gi"
DefaultSecurityContextFsGroup = "1724"
DefaultSecurityContextRunAsUser = "1724"
)
Loading