Skip to content
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

add "overwrite" option to attachPVC view #2176

Conversation

juanvallejo
Copy link
Contributor

Depends on: openshift/origin-web-common#203
Fixes #2045

Work in progress. Just wanted to begin gathering feedback.
Will post images.

cc @spadgett @benjaminapetersen

@@ -118,6 +118,51 @@ angular.module('openshiftConsole')
$scope.$watchGroup(['attach.resource', 'attach.allContainers'], updateMountPaths);
$scope.$watch('attach.containers', updateMountPaths, true);

var setVolumeMount = function(podTemplate, name, mountPath, subPath, readOnly) {
for (var i = 0; i < podTemplate.spec.containers.length; i++) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will switch to an angular.forEach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use Lodash _.each

https://lodash.com/docs/4.17.4#forEach

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, var isn't block scoped (inside if statements), switching to _.each(function() { }) will fix. It wouldn't error, but its a bit sketch. yay js 😄

containers[i].volumeMounts = [];
}

for (var idx = 0; idx < containers[i].volumeMounts.length; idx++) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will switch to angular.forEach

}
}

for (var mountIdx = 0; mountIdx < containers[i].volumeMounts.length; mountIdx++) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will also switch to angular.forEach

@@ -211,7 +225,7 @@ <h2 class="text-center">No persistent volume claims.</h2>
<button type="submit"
class="btn btn-primary btn-lg"
ng-click="attachPVC()"
ng-disabled="attachPVCForm.$invalid || disableInputs || !attachPVC">Add</button>
ng-disabled="(attachPVCForm.$invalid) || disableInputs || !attachPVC">Add</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shouldn't need the parens

volumeExists = true;
break;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use _.some to make this a one-liner:

var volumeExists = _.some(podTemplate.spec.volumes, { name: newVolume.name });

https://lodash.com/docs/4.17.4#some

@@ -83,6 +83,7 @@ <h2 class="text-center">No persistent volume claims.</h2>
ng-model="attach.mountPath"
ng-pattern="/^\/.*$/"
osc-unique="existingMountPaths"
osc-unique-disabled="attach.overwrite"
Copy link
Contributor

@benjaminapetersen benjaminapetersen Sep 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@juanvallejo
Copy link
Contributor Author

@spadgett thanks for the feedback, review comments addressed

@juanvallejo juanvallejo force-pushed the jvallejo/add-set-volume-overwrite-option branch from 2baea1f to d6cd77c Compare September 27, 2017 21:29
@benjaminapetersen
Copy link
Contributor

benjaminapetersen commented Sep 29, 2017

Verifying that checked in built files under dist match the source...
Built /dist does not match what is committed, run 'grunt build' and include the results in your commit.
diff --git a/dist/scripts/vendor.js b/dist/scripts/vendor.js

prob just a rebase & a bower install & a grunt build

@juanvallejo juanvallejo force-pushed the jvallejo/add-set-volume-overwrite-option branch 2 times, most recently from 8e44b7f to afc011f Compare October 2, 2017 16:52
@juanvallejo juanvallejo changed the title [WIP] add "overwrite" option to attachPVC view add "overwrite" option to attachPVC view Oct 2, 2017
@juanvallejo
Copy link
Contributor Author

@benjaminapetersen thanks, PR re-built and rebased

@juanvallejo
Copy link
Contributor Author

re[test]

@benjaminapetersen
Copy link
Contributor

Built /dist does not match what is committed, run 'grunt build' and include the results in your commit.

😄
try:

hack/clean-deps.sh
hack/install-deps.sh
grunt build 
// commit this stuff

@juanvallejo juanvallejo force-pushed the jvallejo/add-set-volume-overwrite-option branch from afc011f to f118eb1 Compare October 3, 2017 15:42
@juanvallejo
Copy link
Contributor Author

@benjaminapetersen thanks! that seems to have done the trick

@benjaminapetersen
Copy link
Contributor

Yup, now you just have the same e2e test errors that all of our other PRs are struggling with. Woohoo!

@benjaminapetersen
Copy link
Contributor

[test] since Jenkins file changed

@juanvallejo
Copy link
Contributor Author

@spadgett friendly ping

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 9, 2017
@juanvallejo
Copy link
Contributor Author

@spadgett per our conversation, went ahead and broke setVolumeMount into smaller functions f4f32b0

@juanvallejo juanvallejo force-pushed the jvallejo/add-set-volume-overwrite-option branch from f4f32b0 to bb9a408 Compare October 9, 2017 18:16
@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 9, 2017
@juanvallejo juanvallejo force-pushed the jvallejo/add-set-volume-overwrite-option branch from bb9a408 to 9d5d868 Compare October 9, 2017 18:50
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 9, 2017
success = false;
return success;
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this reads a little better and avoids needing a success flag.

var duplicateMount = _.find(container.volumeMounts, function(mount) {
  return mount.mountPath === newVolumeMount.mountPath && mount.name !== newVolumeMount.name;
});

if (duplicateMount) {
  displayError('The volume mount "' + duplicateMount.mountPath + '" with name "' + duplicateMount.name +'" already exists for container "' + container.name + '"');
  return false;
}

return true;

}
});

return didReplace;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var index = _.findIndex(container.volumeMounts, { name: newVolumeMount.name });
if (index === -1) {
  return false;
}

container.volumeMounts[index] = newVolumeMount;
return true;

Overwrite
</label>
<div id="overwrite-help" class="help-block">
Overwrite the volume mount config (if it already exists).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just say "Overwrite a volume mount if it already exists."


if (!$scope.attach.overwrite || ($scope.attach.overwrite && !volumeExists)) {
podTemplate.spec.volumes.push(newVolume);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct to continue if the volume exists and overwrite is not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct to continue if the volume exists and overwrite is not set?

Ah, no pushing a volume containing a duplicate name field would cause an error, however I think I was relying on the client-side checks that we currently have to stop a user from submitting the form if a duplicate name or mount path was found.

Will go ahead and update this to just be

if (!volumeExists) {
  podTemplate.spec.volumes.push(newVolume);
}

container.volumeMounts.push(newVolumeMount);
}
});
// angular.forEach(podTemplate.spec.containers, function(container) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code

@juanvallejo juanvallejo force-pushed the jvallejo/add-set-volume-overwrite-option branch from 9d5d868 to 9fe84ee Compare October 10, 2017 17:03
@juanvallejo
Copy link
Contributor Author

@spadgett thanks for the feedback, review comments addressed

@openshift-bot
Copy link

Evaluated for origin web console test up to 9fe84ee

@openshift-bot
Copy link

Origin Web Console Test Results: SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin_web_console/327/) (Base Commit: 45d17ff) (PR Branch Commit: 9fe84ee)

@spadgett
Copy link
Member

/test

@spadgett
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 13, 2017
@spadgett
Copy link
Member

/retest

@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue.

@openshift-merge-robot openshift-merge-robot merged commit ce05a60 into openshift:master Oct 13, 2017
@juanvallejo juanvallejo deleted the jvallejo/add-set-volume-overwrite-option branch October 13, 2017 15:31
openshift-merge-robot added a commit that referenced this pull request Oct 13, 2017
…volume-overwrite-option

Automatic merge from submit-queue.

Revert "add "overwrite" option to attachPVC view"

Reverts #2176

The change has introduced some bugs. Reverting for now. I've reopened the original issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants