aboutsummaryrefslogtreecommitdiffstats
path: root/src/dcm/api
diff options
context:
space:
mode:
authorRitu Sood <ritu.sood@intel.com>2020-09-30 23:48:26 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-30 23:48:26 +0000
commitd985f31655090d86e0536e35b60966d4f0f0bf57 (patch)
tree7a7d92a111ccfad36f1e5b24b513088931690112 /src/dcm/api
parent221bfef43b4589d52e57a72a85f2331a8b782e53 (diff)
parent8a25158d77311eec27d1fb3dc41e16bfbfceebcc (diff)
Merge "Implement Kubeconfig endpoint in DCM"
Diffstat (limited to 'src/dcm/api')
-rw-r--r--src/dcm/api/api.go15
-rw-r--r--src/dcm/api/clusterHandler.go41
2 files changed, 45 insertions, 11 deletions
diff --git a/src/dcm/api/api.go b/src/dcm/api/api.go
index 0f68a517..cd8589dd 100644
--- a/src/dcm/api/api.go
+++ b/src/dcm/api/api.go
@@ -71,18 +71,8 @@ func NewRouter(
lcRouter.HandleFunc(
"/logical-clouds/{logical-cloud-name}/terminate",
logicalCloudHandler.terminateHandler).Methods("POST")
- // To Do
- // get kubeconfig
- /*lcRouter.HandleFunc(
- "/logical-clouds/{name}/kubeconfig?cluster-reference={cluster}",
- logicalCloudHandler.getConfigHandler).Methods("GET")
- //get status
- lcRouter.HandleFunc(
- "/logical-clouds/{name}/cluster-references/",
- logicalCloudHandler.associateHandler).Methods("GET")*/
// Set up Cluster API
-
clusterHandler := clusterHandler{client: clusterClient}
clusterRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter()
clusterRouter.HandleFunc(
@@ -100,6 +90,10 @@ func NewRouter(
clusterRouter.HandleFunc(
"/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}",
clusterHandler.deleteHandler).Methods("DELETE")
+ // Get kubeconfig for cluster of logical cloud
+ clusterRouter.HandleFunc(
+ "/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}/kubeconfig",
+ clusterHandler.getConfigHandler).Methods("GET")
// Set up User Permission API
if userPermissionClient == nil {
@@ -121,7 +115,6 @@ func NewRouter(
userPermissionHandler.deleteHandler).Methods("DELETE")
// Set up Quota API
-
quotaHandler := quotaHandler{client: quotaClient}
quotaRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter()
quotaRouter.HandleFunc(
diff --git a/src/dcm/api/clusterHandler.go b/src/dcm/api/clusterHandler.go
index d0c1e62c..db110399 100644
--- a/src/dcm/api/clusterHandler.go
+++ b/src/dcm/api/clusterHandler.go
@@ -168,3 +168,44 @@ func (h clusterHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
}
+
+// getConfigHandler handles GET operations on kubeconfigs
+// Returns a kubeconfig file
+func (h clusterHandler) getConfigHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ 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)
+ if err != nil {
+ if err.Error() == "Cluster Reference does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ } else {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ }
+ return
+ }
+
+ ret, 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)
+ } else if err.Error() == "Logical Cloud hasn't been applied yet" {
+ http.Error(w, err.Error(), http.StatusBadRequest)
+ } else {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ }
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/yaml")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(ret)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+}