diff options
author | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-10-02 01:40:09 +0000 |
---|---|---|
committer | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-10-02 23:24:52 +0000 |
commit | e70a776fd2d16d7d386af0354afd3e086068ef00 (patch) | |
tree | 9bfc8337356052c9fa3d856ab632b13234219e92 | |
parent | 8eceef201a6252aeab9a5c2410423642b3726910 (diff) |
DCM E2E testing fixes
A set of small fixes after discovery during DCM's end-to-end testing:
- properly detect that a cert hasn't been issued yet (don't crash)
- in Monitor, don't pass namespace when querying for CSRs
- fixed incorrect /kubeconfig file encoding from yaml to json
Issue-ID: MULTICLOUD-1143
Change-Id: Ie813e377070b0751f0bfdabac8da50e3288090de
Signed-off-by: Igor D.C <igor.duarte.cardoso@intel.com>
-rw-r--r-- | src/dcm/api/clusterHandler.go | 7 | ||||
-rw-r--r-- | src/dcm/pkg/module/cluster.go | 4 | ||||
-rw-r--r-- | src/monitor/pkg/controller/resourcebundlestate/controller.go | 2 |
3 files changed, 8 insertions, 5 deletions
diff --git a/src/dcm/api/clusterHandler.go b/src/dcm/api/clusterHandler.go index 427a4262..1201611f 100644 --- a/src/dcm/api/clusterHandler.go +++ b/src/dcm/api/clusterHandler.go @@ -190,10 +190,9 @@ func (h clusterHandler) getConfigHandler(w http.ResponseWriter, r *http.Request) project := vars["project-name"] logicalCloud := vars["logical-cloud-name"] name := vars["cluster-reference"] - var ret interface{} var err error - ret, err = h.client.GetCluster(project, logicalCloud, name) + _, err = h.client.GetCluster(project, logicalCloud, name) if err != nil { if err.Error() == "Cluster Reference does not exist" { http.Error(w, err.Error(), http.StatusNotFound) @@ -203,7 +202,7 @@ func (h clusterHandler) getConfigHandler(w http.ResponseWriter, r *http.Request) return } - ret, err = h.client.GetClusterConfig(project, logicalCloud, name) + cfg, err := h.client.GetClusterConfig(project, logicalCloud, name) if err != nil { if err.Error() == "The certificate for this cluster hasn't been issued yet. Please try later." { http.Error(w, err.Error(), http.StatusAccepted) @@ -217,7 +216,7 @@ func (h clusterHandler) getConfigHandler(w http.ResponseWriter, r *http.Request) w.Header().Set("Content-Type", "application/yaml") w.WriteHeader(http.StatusOK) - err = json.NewEncoder(w).Encode(ret) + _, err = io.WriteString(w, cfg) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/src/dcm/pkg/module/cluster.go b/src/dcm/pkg/module/cluster.go index 253b37a3..33de7acf 100644 --- a/src/dcm/pkg/module/cluster.go +++ b/src/dcm/pkg/module/cluster.go @@ -315,6 +315,10 @@ func (v *ClusterClient) GetClusterConfig(project, logicalCloud, clusterReference return "", pkgerrors.Wrap(err, "An error occurred while parsing the cluster status.") } + if len(rbstatus.CsrStatuses) == 0 { + return "", pkgerrors.New("The certificate for this cluster hasn't been issued yet. Please try later.") + } + // validate that we indeed obtained a certificate before persisting it in the database: approved := false for _, c := range rbstatus.CsrStatuses[0].Status.Conditions { diff --git a/src/monitor/pkg/controller/resourcebundlestate/controller.go b/src/monitor/pkg/controller/resourcebundlestate/controller.go index 5351ea99..c2695552 100644 --- a/src/monitor/pkg/controller/resourcebundlestate/controller.go +++ b/src/monitor/pkg/controller/resourcebundlestate/controller.go @@ -365,7 +365,7 @@ func (r *reconciler) updateCsrs(rbstate *v1alpha1.ResourceBundleState, // Update the CR with the csrs tracked csrList := &certsapi.CertificateSigningRequestList{} - err := listResources(r.client, rbstate.Namespace, selectors, csrList) + err := listResources(r.client, "", selectors, csrList) if err != nil { log.Printf("Failed to list csrs: %v", err) return err |