Skip to content

Commit

Permalink
UI: Delete ConfigMap with no Trial Templates (#1260)
Browse files Browse the repository at this point in the history
* Delete ConfigMap if there are no Trial Templates
Add snack box for Templates

* Not add empty ConfigMaps

* Fix e2e test
  • Loading branch information
andreyvelich authored Jul 10, 2020
1 parent 4145c4f commit f1393b9
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 119 deletions.
66 changes: 19 additions & 47 deletions pkg/mock/v1beta1/util/katibclient/katibclient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions pkg/ui/v1beta1/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func (k *KatibUIHandler) SubmitYamlJob(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = k.katibClient.CreateExperiment(&job)
err = k.katibClient.CreateRuntimeObject(&job)
if err != nil {
log.Printf("CreateExperiment from YAML failed: %v", err)
log.Printf("CreateRuntimeObject from YAML failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand All @@ -70,13 +70,13 @@ func (k *KatibUIHandler) SubmitParamsJob(w http.ResponseWriter, r *http.Request)
if data, ok := data["postData"]; ok {
jsonbody, err := json.Marshal(data)
if err != nil {
log.Printf("Marshal data for HP job failed: %v", err)
log.Printf("Marshal data for experiment failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
job := experimentv1beta1.Experiment{}
if err := json.Unmarshal(jsonbody, &job); err != nil {
log.Printf("Unmarshal HP job failed: %v", err)
log.Printf("Unmarshal experiment failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand All @@ -89,9 +89,9 @@ func (k *KatibUIHandler) SubmitParamsJob(w http.ResponseWriter, r *http.Request)
Name: dataMap["metadata"].(map[string]interface{})["name"].(string),
Namespace: dataMap["metadata"].(map[string]interface{})["namespace"].(string),
}
err = k.katibClient.CreateExperiment(&job)
err = k.katibClient.CreateRuntimeObject(&job)
if err != nil {
log.Printf("CreateExperiment for HP failed: %v", err)
log.Printf("CreateRuntimeObject from parameters failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -129,9 +129,9 @@ func (k *KatibUIHandler) DeleteExperiment(w http.ResponseWriter, r *http.Request
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = k.katibClient.DeleteExperiment(experiment)
err = k.katibClient.DeleteRuntimeObject(experiment)
if err != nil {
log.Printf("DeleteExperiment failed: %v", err)
log.Printf("DeleteRuntimeObject failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -255,8 +255,7 @@ func (k *KatibUIHandler) EditTemplate(w http.ResponseWriter, r *http.Request) {
w.Write(response)
}

// DeleteTemplate delete template in ConfigMap
// TODO: Add functionality to delete configMap if there is no templates
// DeleteTemplate deletes template in ConfigMap
func (k *KatibUIHandler) DeleteTemplate(w http.ResponseWriter, r *http.Request) {

var data map[string]interface{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { closeDialog, addTemplate, changeTemplate } from '../../../actions/templ

import { TEMPLATE_MODULE } from '../../../constants/constants';

const styles = theme => ({
const styles = () => ({
header: {
textAlign: 'center',
width: 650,
Expand Down Expand Up @@ -185,7 +185,11 @@ class AddDialog extends React.Component {
!this.props.updatedConfigMapPath ||
!this.props.updatedTemplateYaml ||
// Path can't contain spaces
this.props.updatedConfigMapPath.indexOf(' ') !== -1
this.props.updatedConfigMapPath.indexOf(' ') !== -1 ||
// Path in ConfigMap must be unique
this.props.trialTemplatesData[this.props.configMapNamespaceIndex].ConfigMaps[
this.props.configMapNameIndex
].Templates.some(t => t.Path === this.props.updatedConfigMapPath)
}
onClick={this.submitAddTemplate}
color={'primary'}
Expand All @@ -211,10 +215,18 @@ const mapStateToProps = state => {
return trialTemplate.ConfigMapNamespace === state[TEMPLATE_MODULE].updatedConfigMapNamespace;
});

let cmIndex;
if (nsIndex !== -1) {
cmIndex = templatesData[nsIndex].ConfigMaps.findIndex(function(configMap, i) {
return configMap.ConfigMapName === state[TEMPLATE_MODULE].updatedConfigMapName;
});
}

return {
addOpen: state[TEMPLATE_MODULE].addOpen,
trialTemplatesData: state[TEMPLATE_MODULE].trialTemplatesData,
trialTemplatesData: templatesData,
configMapNamespaceIndex: nsIndex,
configMapNameIndex: cmIndex,
updatedConfigMapNamespace: state[TEMPLATE_MODULE].updatedConfigMapNamespace,
updatedConfigMapName: state[TEMPLATE_MODULE].updatedConfigMapName,
updatedConfigMapPath: state[TEMPLATE_MODULE].updatedConfigMapPath,
Expand Down
36 changes: 36 additions & 0 deletions pkg/ui/v1beta1/frontend/src/reducers/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,42 @@ const generalReducer = (state = initialState, action) => {
filterStatus: statuses,
filteredExperiments: filteredExperiments,
};
case templateActions.ADD_TEMPLATE_SUCCESS:
return {
...state,
snackOpen: true,
snackText: 'Successfully added new Template',
};
case templateActions.DELETE_TEMPLATE_SUCCESS:
return {
...state,
snackOpen: true,
snackText: 'Successfully deleted Template',
};
case templateActions.EDIT_TEMPLATE_SUCCESS:
return {
...state,
snackOpen: true,
snackText: 'Successfully edited Template',
};
case templateActions.ADD_TEMPLATE_FAILURE:
return {
...state,
snackOpen: true,
snackText: 'Add Template failed: ' + action.error,
};
case templateActions.EDIT_TEMPLATE_FAILURE:
return {
...state,
snackOpen: true,
snackText: 'Edit Template failed: ' + action.error,
};
case templateActions.DELETE_TEMPLATE_FAILURE:
return {
...state,
snackOpen: true,
snackText: 'Delete Template failed: ' + action.error,
};
default:
return state;
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/ui/v1beta1/frontend/src/reducers/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const rootReducer = (state = initialState, action) => {
editOpen: false,
addOpen: false,
deleteOpen: false,
filteredConfigMapNamespace: 'All namespaces',
filteredConfigMapName: '',
};
case actions.OPEN_DIALOG:
switch (action.dialogType) {
Expand Down Expand Up @@ -89,8 +87,9 @@ const rootReducer = (state = initialState, action) => {
editOpen: false,
trialTemplatesData: action.trialTemplatesData,
filteredTrialTemplatesData: action.trialTemplatesData,
filteredConfigMapNamespace: 'All namespaces',
filteredConfigMapName: '',
};

case actions.ADD_TEMPLATE_FAILURE:
case actions.EDIT_TEMPLATE_FAILURE:
case actions.DELETE_TEMPLATE_FAILURE:
Expand All @@ -99,6 +98,8 @@ const rootReducer = (state = initialState, action) => {
addOpen: false,
deleteOpen: false,
editOpen: false,
filteredConfigMapNamespace: 'All namespaces',
filteredConfigMapName: '',
};
case actions.CHANGE_TEMPLATE:
return {
Expand Down
24 changes: 15 additions & 9 deletions pkg/ui/v1beta1/frontend/src/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ export const addTemplate = function*() {
} else {
yield put({
type: templateActions.ADD_TEMPLATE_FAILURE,
error: result.error,
});
}
} catch (err) {
Expand All @@ -508,9 +509,10 @@ const goAddTemplate = function*(
const result = yield call(axios.post, '/katib/add_template/', data);
return result;
} catch (err) {
yield put({
type: templateActions.ADD_TEMPLATE_FAILURE,
});
return {
status: 500,
error: err.response.data,
};
}
};

Expand All @@ -534,6 +536,7 @@ export const editTemplate = function*() {
} else {
yield put({
type: templateActions.EDIT_TEMPLATE_FAILURE,
error: result.error,
});
}
} catch (err) {
Expand Down Expand Up @@ -562,9 +565,10 @@ const goEditTemplate = function*(
const result = yield call(axios.post, '/katib/edit_template/', data);
return result;
} catch (err) {
yield put({
type: templateActions.EDIT_TEMPLATE_FAILURE,
});
return {
status: 500,
error: err.response.data,
};
}
};

Expand All @@ -586,6 +590,7 @@ export const deleteTemplate = function*() {
} else {
yield put({
type: templateActions.DELETE_TEMPLATE_FAILURE,
error: result.error,
});
}
} catch (err) {
Expand All @@ -610,9 +615,10 @@ const goDeleteTemplate = function*(
const result = yield call(axios.post, '/katib/delete_template/', data);
return result;
} catch (err) {
yield put({
type: templateActions.DELETE_TEMPLATE_FAILURE,
});
return {
status: 500,
error: err.response.data,
};
}
};

Expand Down
Loading

0 comments on commit f1393b9

Please sign in to comment.