Skip to content

Commit

Permalink
Merge pull request #247 from eclipse/movedefaultstoenv
Browse files Browse the repository at this point in the history
Move some defaults to env
  • Loading branch information
tolusha authored May 13, 2020
2 parents 0c671d8 + b9942aa commit c50bfa5
Show file tree
Hide file tree
Showing 26 changed files with 173 additions and 109 deletions.
12 changes: 10 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "0.2.0",
"configurations": [

{
"name": "Launch Current File",
"type": "go",
Expand All @@ -27,7 +27,15 @@
"mode": "auto",
"program": "${workspaceFolder}/cmd/manager/main.go",
"env": {
"WATCH_NAMESPACE": "che"
"WATCH_NAMESPACE": "che",
"CHE_FLAVOR": "che",
"CONSOLE_LINK_NAME": "che",
"CONSOLE_LINK_DISPLAY_NAME": "Eclipse Che",
"CONSOLE_LINK_SECTION": "Red Hat Applications",
"CONSOLE_LINK_IMAGE": "/dashboard/assets/branding/loader.svg",
"CHE_IDENTITY_SECRET": "che-identity-secret",
"CHE_IDENTITY_POSTGRES_SECRET": "che-identity-postgres-secret",
"CHE_POSTGRES_SECRET": "che-postgres-secret"
},
"cwd": "${workspaceFolder}",
"args": [
Expand Down
16 changes: 16 additions & 0 deletions deploy/operator-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,19 @@ spec:
value: quay.io/eclipse/che-plugin-artifacts-broker:v3.1.2
- name: IMAGE_default_che_server_secure_exposer_jwt_proxy_image
value: quay.io/eclipse/che-jwtproxy:fd94e60
- name: CHE_FLAVOR
value: che
- name: CONSOLE_LINK_NAME
value: che
- name: CONSOLE_LINK_DISPLAY_NAME
value: "Eclipse Che"
- name: CONSOLE_LINK_SECTION
value: "Red Hat Applications"
- name: CONSOLE_LINK_IMAGE
value: "/dashboard/assets/branding/loader.svg"
- name: CHE_IDENTITY_SECRET
value: che-identity-secret
- name: CHE_IDENTITY_POSTGRES_SECRET
value: che-identity-postgres-secret
- name: CHE_POSTGRES_SECRET
value: che-postgres-secret
16 changes: 16 additions & 0 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ spec:
value: quay.io/eclipse/che-plugin-artifacts-broker:v3.1.2
- name: IMAGE_default_che_server_secure_exposer_jwt_proxy_image
value: quay.io/eclipse/che-jwtproxy:fd94e60
- name: CHE_FLAVOR
value: che
- name: CONSOLE_LINK_NAME
value: che
- name: CONSOLE_LINK_DISPLAY_NAME
value: "Eclipse Che"
- name: CONSOLE_LINK_SECTION
value: "Red Hat Applications"
- name: CONSOLE_LINK_IMAGE
value: "/dashboard/assets/branding/loader.svg"
- name: CHE_IDENTITY_SECRET
value: che-identity-secret
- name: CHE_IDENTITY_POSTGRES_SECRET
value: che-identity-postgres-secret
- name: CHE_POSTGRES_SECRET
value: che-postgres-secret
restartPolicy: Always
serviceAccountName: che-operator
terminationGracePeriodSeconds: 5
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ require (
golang.org/x/tools v0.0.0-20190107155254-e063def13b29 // indirect
google.golang.org/appengine v1.4.0 // indirect
gopkg.in/inf.v0 v0.9.0 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
gopkg.in/yaml.v2 v2.2.2
k8s.io/api v0.0.0-20181126151915-b503174bad59
k8s.io/apimachinery v0.0.0-20181126123746-eddba98df674
k8s.io/client-go v0.0.0-20181126152608-d082d5923d3c
Expand Down
2 changes: 2 additions & 0 deletions local-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ command -v operator-sdk >/dev/null 2>&1 || { echo -e $RED"operator-sdk is not in

CHE_NAMESPACE=che



set +e
kubectl create namespace $CHE_NAMESPACE
set -e
Expand Down
3 changes: 1 addition & 2 deletions make-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ createPRToMasterBranch() {
resetChanges master
local tmpBranch=${RELEASE}-to-master
git checkout -B $tmpBranch
git diff refs/heads/${BRANCH}...refs/heads/${RELEASE} ':(exclude)deploy/operator-local.yaml' ':(exclude)deploy/operator.yaml' ':(exclude)pkg/deploy/defaults_test.go'
git diff refs/heads/${BRANCH}...refs/heads/${RELEASE} ':(exclude)deploy/operator-local.yaml' ':(exclude)deploy/operator.yaml'
git add -A
git commit -m "Copy "$RELEASE" csv to master" --signoff
git push origin $tmpBranch
Expand All @@ -251,7 +251,6 @@ createPRToMasterBranch() {
. ${RELEASE_DIR}/replace-images-tags.sh nightly master
git add deploy/operator.yaml
git add deploy/operator-local.yaml
git add pkg/deploy/defaults_test.go
git commit -m "Update images tags" --signoff
git push origin $tmpBranch
hub pull-request --base master --head ${tmpBranch} --browse -m "Update images tags in master branch"
Expand Down
13 changes: 6 additions & 7 deletions pkg/controller/che/che_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
return reconcile.Result{Requeue: true}, nil
}

cheFlavor := util.GetValue(instance.Spec.Server.CheFlavor, deploy.DefaultCheFlavor)
cheFlavor := deploy.DefaultCheFlavor(instance)
cheDeploymentName := cheFlavor
if isOpenShift {
// create a secret with router tls cert when on OpenShift infra and router is configured with a self signed certificate
Expand Down Expand Up @@ -1185,27 +1185,26 @@ func createConsoleLink(isOpenShift4 bool, protocol string, instance *orgv1.CheCl
// console link is supported only with https
return nil
}
cheFlavor := instance.Spec.Server.CheFlavor
cheHost := instance.Spec.Server.CheHost
preparedConsoleLink := &consolev1.ConsoleLink{
ObjectMeta: metav1.ObjectMeta{
Name: deploy.DefaultConsoleLinkName,
Name: deploy.DefaultConsoleLinkName(),
},
Spec: consolev1.ConsoleLinkSpec{
Link: consolev1.Link{
Href: protocol + "://" + cheHost,
Text: deploy.DefaultConsoleLinkDisplayName(cheFlavor)},
Text: deploy.DefaultConsoleLinkDisplayName()},
Location: consolev1.ApplicationMenu,
ApplicationMenu: &consolev1.ApplicationMenuSpec{
Section: deploy.DefaultConsoleLinkSection,
ImageURL: fmt.Sprintf("%s://%s%s", protocol, cheHost, deploy.DefaultConsoleLinkImage),
Section: deploy.DefaultConsoleLinkSection(),
ImageURL: fmt.Sprintf("%s://%s%s", protocol, cheHost, deploy.DefaultConsoleLinkImage()),
},
},
}

existingConsoleLink := &consolev1.ConsoleLink{}

if getErr := r.nonCachedClient.Get(context.TODO(), client.ObjectKey{Name: deploy.DefaultConsoleLinkName}, existingConsoleLink); getErr == nil {
if getErr := r.nonCachedClient.Get(context.TODO(), client.ObjectKey{Name: deploy.DefaultConsoleLinkName()}, existingConsoleLink); getErr == nil {
// if found, update existing one. We need ResourceVersion from current one.
preparedConsoleLink.ResourceVersion = existingConsoleLink.ResourceVersion
logrus.Debugf("Updating the object: ConsoleLink, name: %s", existingConsoleLink.Name)
Expand Down
17 changes: 15 additions & 2 deletions pkg/controller/che/che_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ package che

import (
"context"
"io/ioutil"
"os"
"time"

"github.com/eclipse/che-operator/pkg/deploy"
Expand All @@ -25,6 +27,7 @@ import (
routev1 "github.com/openshift/api/route/v1"
userv1 "github.com/openshift/api/user/v1"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacapi "k8s.io/api/rbac/v1"
Expand All @@ -40,8 +43,18 @@ import (
"testing"
)

func TestCheController(t *testing.T) {
func init() {
operator := &appsv1.Deployment{}
data, err := ioutil.ReadFile("../../../deploy/operator.yaml")
yaml.Unmarshal(data, operator)
if err == nil {
for _, env := range operator.Spec.Template.Spec.Containers[0].Env {
os.Setenv(env.Name, env.Value)
}
}
}

func TestCheController(t *testing.T) {
// Set the logger to development mode for verbose logs.
logf.SetLogger(logf.ZapLogger(true))

Expand Down Expand Up @@ -196,7 +209,7 @@ func TestCheController(t *testing.T) {
if cm.Data["CHE_INFRA_OPENSHIFT_TLS__ENABLED"] != "true" {
t.Errorf("ConfigMap wasn't updated. Extecting true, got: %s", cm.Data["CHE_INFRA_OPENSHIFT_TLS__ENABLED"])
}
if err := cl.Get(context.TODO(), types.NamespacedName{Name: deploy.DefaultCheFlavor, Namespace: cheCR.Namespace}, route); err != nil {
if err := cl.Get(context.TODO(), types.NamespacedName{Name: deploy.DefaultCheFlavor(cheCR), Namespace: cheCR.Namespace}, route); err != nil {
t.Errorf("Route %s not found: %s", cm.Name, err)
}
if route.Spec.TLS.Termination != "edge" {
Expand Down
9 changes: 4 additions & 5 deletions pkg/controller/che/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ func (r *ReconcileChe) CreateTLSSecret(instance *orgv1.CheCluster, url string, n
}

func (r *ReconcileChe) GenerateAndSaveFields(instance *orgv1.CheCluster, request reconcile.Request) (err error) {

cheFlavor := util.GetValue(instance.Spec.Server.CheFlavor, deploy.DefaultCheFlavor)
cheFlavor := deploy.DefaultCheFlavor(instance)
if len(instance.Spec.Server.CheFlavor) < 1 {
instance.Spec.Server.CheFlavor = cheFlavor
if err := r.UpdateCheCRSpec(instance, "installation flavor", cheFlavor); err != nil {
Expand All @@ -170,7 +169,7 @@ func (r *ReconcileChe) GenerateAndSaveFields(instance *orgv1.CheCluster, request
if cheMultiUser == "true" {
if len(instance.Spec.Database.ChePostgresSecret) < 1 {
if len(instance.Spec.Database.ChePostgresUser) < 1 || len(instance.Spec.Database.ChePostgresPassword) < 1 {
chePostgresSecret := deploy.DefaultChePostgresSecret
chePostgresSecret := deploy.DefaultChePostgresSecret()
r.CreateSecret(instance, map[string][]byte{"user": []byte(deploy.DefaultChePostgresUser), "password": []byte(util.GeneratePasswd(12))}, chePostgresSecret)
instance.Spec.Database.ChePostgresSecret = chePostgresSecret
if err := r.UpdateCheCRSpec(instance, "Postgres Secret", chePostgresSecret); err != nil {
Expand Down Expand Up @@ -201,7 +200,7 @@ func (r *ReconcileChe) GenerateAndSaveFields(instance *orgv1.CheCluster, request
}

if len(instance.Spec.Auth.IdentityProviderPostgresPassword) < 1 {
identityPostgresSecret := deploy.DefaultCheIdentityPostgresSecret
identityPostgresSecret := deploy.DefaultCheIdentityPostgresSecret()
r.CreateSecret(instance, map[string][]byte{"password": []byte(keycloakPostgresPassword)}, identityPostgresSecret)
instance.Spec.Auth.IdentityProviderPostgresSecret = identityPostgresSecret
if err := r.UpdateCheCRSpec(instance, "Identity Provider Postgres Secret", identityPostgresSecret); err != nil {
Expand All @@ -223,7 +222,7 @@ func (r *ReconcileChe) GenerateAndSaveFields(instance *orgv1.CheCluster, request
}

if len(instance.Spec.Auth.IdentityProviderAdminUserName) < 1 || len(instance.Spec.Auth.IdentityProviderPassword) < 1 {
identityProviderSecret := deploy.DefaultCheIdentitySecret
identityProviderSecret := deploy.DefaultCheIdentitySecret()
r.CreateSecret(instance, map[string][]byte{"user": []byte(keycloakAdminUserName), "password": []byte(keycloakAdminPassword)}, identityProviderSecret)
instance.Spec.Auth.IdentityProviderSecret = identityProviderSecret
if err := r.UpdateCheCRSpec(instance, "Identity Provider Secret", identityProviderSecret); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/che/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package che
import (
orgv1 "github.com/eclipse/che-operator/pkg/apis/org/v1"
"github.com/eclipse/che-operator/pkg/deploy"
"github.com/eclipse/che-operator/pkg/util"
"github.com/sirupsen/logrus"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
Expand All @@ -26,7 +25,7 @@ const (
)

func (r *ReconcileChe) SetCheAvailableStatus(instance *orgv1.CheCluster, request reconcile.Request, protocol string, cheHost string) (err error) {
cheFlavor := util.GetValue(instance.Spec.Server.CheFlavor, deploy.DefaultCheFlavor)
cheFlavor := deploy.DefaultCheFlavor(instance)
name := "Eclipse Che"
if cheFlavor == "codeready" {
name = "CodeReady Workspaces"
Expand Down
11 changes: 5 additions & 6 deletions pkg/deploy/che_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,18 @@ func GetConfigMapData(cr *orgv1.CheCluster) (cheEnv map[string]string) {
if err != nil {
logrus.Errorf("Failed to get current infra: %s", err)
}
cheFlavor := util.GetValue(cr.Spec.Server.CheFlavor, DefaultCheFlavor)
cheFlavor := DefaultCheFlavor(cr)
infra := "kubernetes"
if isOpenShift {
infra = "openshift"
}
tls := "false"
openShiftIdentityProviderId := "NULL"
openshiftOAuth := cr.Spec.Auth.OpenShiftoAuth
defaultTargetNamespaceDefault := cr.Namespace // By default Che SA has right in the namespace where Che in installed ...
defaultTargetNamespaceDefault := cr.Namespace // By default Che SA has right in the namespace where Che in installed ...
if openshiftOAuth && isOpenShift {
// ... But if the workspace is created under the openshift identity of the end-user,
// Then we'll have rights to create any new namespace
// Then we'll have rights to create any new namespace
defaultTargetNamespaceDefault = "<username>-" + cheFlavor
openShiftIdentityProviderId = "openshift-v3"
if isOpenshift4 {
Expand Down Expand Up @@ -220,7 +220,7 @@ func GetConfigMapData(cr *orgv1.CheCluster) (cheEnv map[string]string) {
cheLogLevel := util.GetValue(cr.Spec.Server.CheLogLevel, DefaultCheLogLevel)
cheDebug := util.GetValue(cr.Spec.Server.CheDebug, DefaultCheDebug)
cheMetrics := strconv.FormatBool(cr.Spec.Metrics.Enable)
cheLabels := util.MapToKeyValuePairs(GetLabels(cr, util.GetValue(cr.Spec.Server.CheFlavor, DefaultCheFlavor)))
cheLabels := util.MapToKeyValuePairs(GetLabels(cr, cheFlavor))
cheMultiUser := GetCheMultiUser(cr)

data := &CheConfigMap{
Expand Down Expand Up @@ -297,8 +297,7 @@ func GetConfigMapData(cr *orgv1.CheCluster) (cheEnv map[string]string) {
}

func GetSpecConfigMap(checluster *orgv1.CheCluster, cheEnv map[string]string, clusterAPI ClusterAPI) (*corev1.ConfigMap, error) {
cheFlavor := util.GetValue(checluster.Spec.Server.CheFlavor, DefaultCheFlavor)
labels := GetLabels(checluster, cheFlavor)
labels := GetLabels(checluster, DefaultCheFlavor(checluster))
configMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
Expand Down
48 changes: 31 additions & 17 deletions pkg/deploy/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ var (
)

const (
DefaultCheFlavor = "che"
DefaultChePostgresUser = "pgche"
DefaultChePostgresHostName = "postgres"
DefaultChePostgresPort = "5432"
DefaultChePostgresDb = "dbche"
DefaultChePostgresSecret = "che-postgres-secret"
DefaultPvcStrategy = "common"
DefaultPvcClaimSize = "1Gi"
DefaultIngressStrategy = "multi-host"
Expand All @@ -68,7 +66,7 @@ const (
DefaultCheVolumeClaimName = "che-data-volume"
DefaultPostgresVolumeClaimName = "postgres-data"

DefaultJavaOpts = "-XX:MaxRAMPercentage=85.0"
DefaultJavaOpts = "-XX:MaxRAMPercentage=85.0"
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 " +
Expand All @@ -88,15 +86,6 @@ const (
OldDefaultCodeReadyServerImageRepo = "registry.redhat.io/codeready-workspaces/server-rhel8"
OldDefaultCodeReadyServerImageTag = "1.2"
OldCrwPluginRegistryUrl = "https://che-plugin-registry.openshift.io"

// ConsoleLink default
DefaultConsoleLinkName = "che"
DefaultConsoleLinkSection = "Red Hat Applications"
DefaultConsoleLinkImage = "/dashboard/assets/branding/loader.svg"
DefaultCheIdentitySecret = "che-identity-secret"
DefaultCheIdentityPostgresSecret = "che-identity-postgres-secret"
defaultConsoleLinkUpstreamDisplayName = "Eclipse Che"
defaultConsoleLinkDisplayName = "CodeReady Workspaces"
)

func InitDefaults(defaultsPath string) {
Expand Down Expand Up @@ -180,11 +169,36 @@ func MigratingToCRW2_0(cr *orgv1.CheCluster) bool {
return false
}

func DefaultConsoleLinkDisplayName(cheFlavor string) string {
if cheFlavor == "codeready" {
return defaultConsoleLinkDisplayName
}
return defaultConsoleLinkUpstreamDisplayName
func DefaultCheFlavor(cr *orgv1.CheCluster) string {
return util.GetValue(cr.Spec.Server.CheFlavor, getDefaultFromEnv("CHE_FLAVOR"))
}

func DefaultConsoleLinkName() string {
return getDefaultFromEnv("CONSOLE_LINK_NAME")
}

func DefaultConsoleLinkDisplayName() string {
return getDefaultFromEnv("CONSOLE_LINK_DISPLAY_NAME")
}

func DefaultConsoleLinkSection() string {
return getDefaultFromEnv("CONSOLE_LINK_SECTION")
}

func DefaultConsoleLinkImage() string {
return getDefaultFromEnv("CONSOLE_LINK_IMAGE")
}

func DefaultCheIdentitySecret() string {
return getDefaultFromEnv("CHE_IDENTITY_SECRET")
}

func DefaultCheIdentityPostgresSecret() string {
return getDefaultFromEnv("CHE_IDENTITY_POSTGRES_SECRET")
}

func DefaultChePostgresSecret() string {
return getDefaultFromEnv("CHE_POSTGRES_SECRET")
}

func DefaultCheVersion() string {
Expand Down
Loading

0 comments on commit c50bfa5

Please sign in to comment.