From e5c774f7d8341ecfa9aa6264dc7d4bee31350823 Mon Sep 17 00:00:00 2001 From: Sergii Leshchenko Date: Thu, 8 Aug 2019 11:22:28 +0300 Subject: [PATCH] Fix fetching test route URL --- pkg/controller/che/k8s_helpers.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/controller/che/k8s_helpers.go b/pkg/controller/che/k8s_helpers.go index 9265ed958d..4e3d1ed4e9 100644 --- a/pkg/controller/che/k8s_helpers.go +++ b/pkg/controller/che/k8s_helpers.go @@ -16,6 +16,7 @@ import ( "context" "crypto/tls" "encoding/pem" + "errors" orgv1 "github.com/eclipse/che-operator/pkg/apis/org/v1" "github.com/eclipse/che-operator/pkg/deploy" "github.com/eclipse/che-operator/pkg/util" @@ -30,7 +31,6 @@ import ( "k8s.io/client-go/kubernetes" "net/http" "sigs.k8s.io/controller-runtime/pkg/client/config" - "time" ) type k8s struct { @@ -221,10 +221,9 @@ func (cl *k8s) GetEvents(deploymentName string, ns string) (list *corev1.EventLi } // GetLogs prints stderr or stdout from a selected pod. Log size is capped at 60000 bytes -func (cl *k8s) GetPodLogs(podName string, ns string) () { +func (cl *k8s) GetPodLogs(podName string, ns string) { var limitBytes int64 = 60000 - req := cl.clientset.CoreV1().Pods(ns).GetLogs(podName, &corev1.PodLogOptions{LimitBytes: &limitBytes}, - ) + req := cl.clientset.CoreV1().Pods(ns).GetLogs(podName, &corev1.PodLogOptions{LimitBytes: &limitBytes}) readCloser, err := req.Stream() if err != nil { logrus.Errorf("Pod error log: %v", err) @@ -257,23 +256,24 @@ func (cl *k8s) GetDeploymentPod(name string, ns string) (podName string, err err // There's an easier way which is to read tls secret in default (3.11) or openshift-ingress (4.0) namespace // which however requires extra privileges for operator service account func (r *ReconcileChe) GetEndpointTlsCrt(instance *orgv1.CheCluster, url string) (certificate []byte, err error) { - testRoute := &routev1.Route{} var requestURL string + var testRoute *routev1.Route if len(url) < 1 { - testRoute = deploy.NewTlsRoute(instance, "test", "test", 8080) - logrus.Infof("Creating a test route %s to extract router crt", testRoute.Name) - if err := r.CreateNewRoute(instance, testRoute); err != nil { - logrus.Errorf("Failed to create test route %s: %s", testRoute.Name, err) - return nil, err + testRoute := r.GetEffectiveRoute(instance, "test") + if testRoute == nil { + testRoute = deploy.NewTlsRoute(instance, "test", "test", 8080) + logrus.Infof("Creating a test route %s to extract router crt", testRoute.Name) + if err := r.CreateNewRoute(instance, testRoute); err != nil { + logrus.Errorf("Failed to create test route %s: %s", testRoute.Name, err) + return nil, err + } } - // sometimes timing conditions apply, and host isn't available right away + if len(testRoute.Spec.Host) < 1 { - time.Sleep(time.Duration(1) * time.Second) - testRoute := r.GetEffectiveRoute(instance, "test") - requestURL = "https://" + testRoute.Spec.Host + return nil, errors.New("Unable to get test route host for fetching certificate") } - requestURL = "https://" + testRoute.Spec.Host + requestURL = "https://" + testRoute.Spec.Host } else { requestURL = url }