|
|
@@ -76,8 +76,8 @@ func (app *App) HandleListNamespaces(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
// HandleCreateConfigMap deletes the pod given the name and namespace.
|
|
|
func (app *App) HandleCreateConfigMap(w http.ResponseWriter, r *http.Request) {
|
|
|
+ fmt.Println("CREATING CONFGIMAP")
|
|
|
vals, err := url.ParseQuery(r.URL.RawQuery)
|
|
|
-
|
|
|
if err != nil {
|
|
|
app.handleErrorFormDecoding(err, ErrReleaseDecode, w)
|
|
|
return
|
|
|
@@ -110,8 +110,8 @@ func (app *App) HandleCreateConfigMap(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
configMap := &forms.ConfigMapForm{}
|
|
|
|
|
|
- if err := json.NewDecoder(r.Body).Decode(form); err != nil {
|
|
|
- app.handleErrorFormDecoding(err, ErrEnvDecode, w)
|
|
|
+ if err := json.NewDecoder(r.Body).Decode(configMap); err != nil {
|
|
|
+ app.handleErrorFormDecoding(err, ErrUserDecode, w)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -122,14 +122,19 @@ func (app *App) HandleCreateConfigMap(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ if err := json.NewEncoder(w).Encode(configMap); err != nil {
|
|
|
+ app.handleErrorFormDecoding(err, ErrEnvDecode, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// HandleGetConfigMap retreives the configmap given the name and namespace.
|
|
|
-func (app *App) HandleGetConfigMap(w http.ResponseWriter, r *http.Request) {
|
|
|
+// HandleListConfigMaps lists all configmaps in a namespace.
|
|
|
+func (app *App) HandleListConfigMaps(w http.ResponseWriter, r *http.Request) {
|
|
|
vals, err := url.ParseQuery(r.URL.RawQuery)
|
|
|
-
|
|
|
+
|
|
|
if err != nil {
|
|
|
app.handleErrorFormDecoding(err, ErrReleaseDecode, w)
|
|
|
return
|
|
|
@@ -160,14 +165,57 @@ func (app *App) HandleGetConfigMap(w http.ResponseWriter, r *http.Request) {
|
|
|
agent, err = kubernetes.GetAgentOutOfClusterConfig(form.OutOfClusterConfig)
|
|
|
}
|
|
|
|
|
|
- cmForm := &forms.ConfigMapForm{}
|
|
|
+ configMaps, err := agent.ListConfigMaps(vals["namespace"][0])
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ app.handleErrorInternal(err, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- if err := json.NewDecoder(r.Body).Decode(cmForm); err != nil {
|
|
|
+ if err := json.NewEncoder(w).Encode(configMaps); err != nil {
|
|
|
app.handleErrorFormDecoding(err, ErrEnvDecode, w)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- configMap, err := agent.GetConfigMap(cmForm.Name, cmForm.Namespace)
|
|
|
+ w.WriteHeader(http.StatusOK)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// HandleGetConfigMap retreives the configmap given the name and namespace.
|
|
|
+func (app *App) HandleGetConfigMap(w http.ResponseWriter, r *http.Request) {
|
|
|
+ vals, err := url.ParseQuery(r.URL.RawQuery)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ app.handleErrorFormDecoding(err, ErrReleaseDecode, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // get the filter options
|
|
|
+ form := &forms.K8sForm{
|
|
|
+ OutOfClusterConfig: &kubernetes.OutOfClusterConfig{
|
|
|
+ Repo: app.Repo,
|
|
|
+ DigitalOceanOAuth: app.DOConf,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ form.PopulateK8sOptionsFromQueryParams(vals, app.Repo.Cluster)
|
|
|
+
|
|
|
+ // validate the form
|
|
|
+ if err := app.validator.Struct(form); err != nil {
|
|
|
+ app.handleErrorFormValidation(err, ErrK8sValidate, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // create a new agent
|
|
|
+ var agent *kubernetes.Agent
|
|
|
+
|
|
|
+ if app.ServerConf.IsTesting {
|
|
|
+ agent = app.TestAgents.K8sAgent
|
|
|
+ } else {
|
|
|
+ agent, err = kubernetes.GetAgentOutOfClusterConfig(form.OutOfClusterConfig)
|
|
|
+ }
|
|
|
+
|
|
|
+ configMap, err := agent.GetConfigMap(vals["name"][0], vals["namespace"][0])
|
|
|
|
|
|
if err != nil {
|
|
|
app.handleErrorInternal(err, w)
|
|
|
@@ -186,7 +234,6 @@ func (app *App) HandleGetConfigMap(w http.ResponseWriter, r *http.Request) {
|
|
|
// HandleDeleteConfigMap deletes the pod given the name and namespace.
|
|
|
func (app *App) HandleDeleteConfigMap(w http.ResponseWriter, r *http.Request) {
|
|
|
vals, err := url.ParseQuery(r.URL.RawQuery)
|
|
|
-
|
|
|
if err != nil {
|
|
|
app.handleErrorFormDecoding(err, ErrReleaseDecode, w)
|
|
|
return
|
|
|
@@ -217,14 +264,7 @@ func (app *App) HandleDeleteConfigMap(w http.ResponseWriter, r *http.Request) {
|
|
|
agent, err = kubernetes.GetAgentOutOfClusterConfig(form.OutOfClusterConfig)
|
|
|
}
|
|
|
|
|
|
- configMap := &forms.ConfigMapForm{}
|
|
|
-
|
|
|
- if err := json.NewDecoder(r.Body).Decode(configMap); err != nil {
|
|
|
- app.handleErrorFormDecoding(err, ErrEnvDecode, w)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- err = agent.DeleteConfigMap(configMap.Name, configMap.Namespace)
|
|
|
+ err = agent.DeleteConfigMap(vals["name"][0], vals["namespace"][0])
|
|
|
|
|
|
if err != nil {
|
|
|
app.handleErrorInternal(err, w)
|
|
|
@@ -283,6 +323,11 @@ func (app *App) HandleUpdateConfigMap(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ if err := json.NewEncoder(w).Encode(configMap); err != nil {
|
|
|
+ app.handleErrorFormDecoding(err, ErrEnvDecode, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
return
|
|
|
}
|