Add Che CR validator (#221)

* Add Che CR validator

Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
pull/222/head
Mykola Morhun 2020-04-16 15:03:10 +03:00 committed by GitHub
parent a8c155409d
commit 56c6806b20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -255,6 +255,14 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
logrus.Errorf("An error occurred when detecting current infra: %s", err)
}
// Check Che CR correctness
if err := ValidateCheCR(instance, isOpenShift); err != nil {
// Che cannot be deployed with current configuration.
// Print error message in logs and wait until the configuration is changed.
logrus.Error(err)
return reconcile.Result{}, nil
}
if isOpenShift {
// delete oAuthClient before CR is deleted
doInstallOpenShiftoAuthProvider := instance.Spec.Auth.OpenShiftoAuth

View File

@ -0,0 +1,33 @@
//
// Copyright (c) 2012-2019 Red Hat, Inc.
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//
// Contributors:
// Red Hat, Inc. - initial API and implementation
//
package che
import (
"fmt"
orgv1 "github.com/eclipse/che-operator/pkg/apis/org/v1"
)
// ValidateCheCR checks Che CR configuration.
// It should detect:
// - configurations which miss required field(s) to deploy Che
// - self-contradictory configurations
// - configurations with which it is impossible to deploy Che
func ValidateCheCR(checluster *orgv1.CheCluster, isOpenshift bool) error {
if !isOpenshift {
if checluster.Spec.K8s.IngressDomain == "" {
return fmt.Errorf("Required field \"spec.K8s.IngressDomain\" is not set")
}
}
return nil
}