-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should not be able to add the same secret or config map to an application twice #2249
Conversation
@@ -26,12 +26,35 @@ | |||
var ctrl = this; | |||
var humanizeKind = $filter('humanizeKind'); | |||
|
|||
var checkContainerForRef = function(container) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benjaminapetersen what about "There is not any application with containers to add secret to"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to show all apps in the list, but show an error with a disabled save button when the user tries to pick one that already has the secret. Otherwise it might seem like a bug that their app isn't showing up, and it's not obvious why.
@benjaminapetersen as suggested by @spadgett I've reworked the logic so the selectbox will list all the applications but we will throw an warning and disable the Save button if the ref is already present in the application containers. PTAL |
Nice, I'm good with that! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jhadvig, a few comments
var checkContainerForRef = function(container) { | ||
var addRefName = ctrl.apiObject.metadata.name; | ||
if (ctrl.apiObject.kind === "ConfigMap") { | ||
return _.find(container.envFrom, {configMapRef: {name: addRefName}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use _.some
instead of _.find
if you are just checking if it exists.
if (ctrl.apiObject.kind === "ConfigMap") { | ||
return _.find(container.envFrom, {configMapRef: {name: addRefName}}); | ||
} else { | ||
return _.find(container.envFrom, {secretRef: {name: addRefName}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_.some
@@ -25,6 +25,26 @@ | |||
function AddConfigToApplication($filter, $scope, APIService, ApplicationsService, DataService, Navigate, NotificationsService, StorageService) { | |||
var ctrl = this; | |||
var humanizeKind = $filter('humanizeKind'); | |||
ctrl.canAddRefToApplication = false; | |||
|
|||
var checkContainerForRef = function(container) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest conatinerHasRef
ctrl.canAddRefToApplication = true; | ||
return false; | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be shortened to.
var containers = _.get(application, 'spec.template.spec.containers');
ctrl.canAddRefToApplication = !_.every(containers, checkContainerForRef);
@@ -5,10 +5,14 @@ | |||
<div class="dialog-body"> | |||
<form name="addToApplicationForm" novalidate> | |||
<fieldset ng-disabled="disableInputs"> | |||
<div class="alert alert-warning" ng-if="ctrl.addType === 'env' && ctrl.application && !ctrl.canAddRefToApplication"> | |||
<span class="pficon pficon-warning-triangle-o" aria-hidden="true"></span> | |||
<strong>Containers of the selected application already contain this {{ctrl.apiObject.kind | humanizeKind}}.</strong> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just
<strong>The {{ctrl.apiObject.kind | humanizeKind}} has already been added to this application.</strong>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest using the help-block / has-error style (instead of an alert) and moving it below the select.
@spadgett I've update the PR based on your comments :) |
Looks good. A couple small comments:
|
@spadgett comments addressed PTAL |
@@ -108,7 +111,7 @@ | |||
class="btn btn-primary" | |||
ng-class="{'dialog-btn': isDialog}" | |||
ng-click="ctrl.addToApplication()" | |||
ng-disabled="ctrl.addType === 'volume' && addToApplicationForm.$invalid || !ctrl.application" | |||
ng-disabled="(ctrl.addType === 'volume' && addToApplicationForm.$invalid) || (ctrl.addType === 'env' && !ctrl.canAddRefToApplication)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like you might be able to submit the form now while "applications" is still loading? canAddRefToApplication
is initialized to true and the invalid check is skipped.
I'm guessing we're only checking addToApplicationForm.$invalid
to keep the form submittable when mount path is invalid, but addType === 'env'
. It would be better to disable the mount path input, however, and just check
ng-disabled="addToApplicationForm.$invalid || (ctrl.addType === 'env' && !ctrl.canAddRefToApplication)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you still need to ensure an application is selected either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeff-phillips-18 I've update the mount path input with the check if the application was selected as @spadgett suggested. This will force user to pick the application in order to make the form valid. Added separate commit so the changes are obvious.
PTAL
@jhadvig Looks like a dist mismatch |
@spadgett will rebase and regenerate dist |
/lgtm |
Automatic merge from submit-queue. |
The
Add to Application
modal will only show applications which DC's won't contain the secret/configMap that user wants to add. In case one of the containers won't contain the secret/configMap the application will be shown in the dropbox, but the ref will be added only to the containers that don't contain the it.Unfortunately if, in case of multiple container DC, user chooses to specify a specific container, the checkbox of the container that already contains the ref wont be pre-selected, cause that could mislead the user that by unchecking the checkbox he could remove the ref from that specific container. Other option would be to pre-select the checkbox and also disable it, but that would require add the disable logic to the
select-container
directive. Wasn't sure if we need that ATM...@jeff-phillips-18 @spadgett PTAL
Closes #2226