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/Edit env vars from secrets and config maps #1090

Merged
merged 2 commits into from
Feb 21, 2017
Merged

Add/Edit env vars from secrets and config maps #1090

merged 2 commits into from
Feb 21, 2017

Conversation

rhamilto
Copy link
Member

@rhamilto rhamilto commented Jan 9, 2017

TODOs:

  • Correct display of valueFrom values on edit/dc (the pickers don't populate with the values)
  • Make second add link function
  • Add link to config map or secret on readonly valueFrom if user has permissions to view them
  • Move altTextForValueFrom filter in to kve code so the use of the filter isn't optional and overlooked
  • Add to additional contexts:
    • create from image
    • deploy-image
    • deployment config custom type
    • edit lifecycle hook
  • clean cruft (e.g., valueFrom.selected) from entry object
  • BUG: after save of env vars, env var values become read only
  • BUG: a user may not have permission to view secrets or config maps
    • but a value may have been set by a user who does have permissions --> need readonly display for these values in the editable form
    • so (s)he should not see the link to add using config maps or secrets
  • BUG: unbroken strings cause faux-input-groups to grow
  • [NICE TO HAVE] What to do about the default case for valueFrom, and additional options like this:
- name: OTHER
   valueFrom:
   resourceFieldRef:
   resource: requests.cpu 
   divisor: '0'
  • [NICE TO HAVE] Add links to create a config map or secret (in a modal)

@rhamilto
Copy link
Member Author

rhamilto commented Jan 9, 2017

@benjaminapetersen, @jwforres, I need an assist getting KVE running. I'm not receiving any errors, but the editor isn't rendering. Not sure how to troubleshoot.

screen shot 2017-01-09 at 9 31 33 am

@spadgett
Copy link
Member

spadgett commented Jan 9, 2017

@rhamilto did you add the JS files to index.html?

@rhamilto
Copy link
Member Author

rhamilto commented Jan 9, 2017

Thanks, @spadgett. I had overlooked the addition.

@@ -286,6 +302,36 @@
}
});

var findReferenceValue = function(entry) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Think its possible to break this one down a bit? There are a lot of returns at various levels. Might be helpful to clarify (via function names) what is going on?

@rhamilto rhamilto changed the title [WIP]: Adding KVE code directly to the console [WIP]: Add/Edit env vars from secrets and config maps Jan 18, 2017
@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 19, 2017
@rhamilto rhamilto removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 31, 2017
}
};
console.log('configMapObj', configMapObj);
entry.valueAlt = 'Set to the key ' + from.key + ' in config map <a ng-if="\'configMaps\' | canI : \'get\'" ng-href="{{configMapObj | navigateResourceURL}}">' + from.name + '</a>';
Copy link
Member Author

Choose a reason for hiding this comment

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

@benjaminapetersen or @jwforres, this doesn't create a valid href, and I'm not sure why. Help?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking into using $compile to get the filters to render correctly.

@rhamilto
Copy link
Member Author

screen shot 2017-02-10 at 9 42 47 am

@jwforres, @spadgett Thoughts? We're currently checking to see if the user has access to config maps or secrets, but not if the config map or secret exists.

@rhamilto rhamilto changed the title [WIP]: Add/Edit env vars from secrets and config maps Add/Edit env vars from secrets and config maps Feb 10, 2017
Copy link
Member

@jwforres jwforres left a comment

Choose a reason for hiding this comment

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

did a rough pass through

secretsArray.unshift("");
});
});
// TODO: make valueFromObjects properly
Copy link
Member

Choose a reason for hiding this comment

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

can you explain this TODO better for someone else looking at this later

Copy link
Member Author

Choose a reason for hiding this comment

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

^ @benjaminapetersen, I'm thinking this comment can simply be deleted?

Copy link
Contributor

Choose a reason for hiding this comment

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

agree... i don't think that has meaning anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment removed.

return _.isArray(input) ?
input :
_.map(input, function(value, key){
return {name: key, value: value};
Copy link
Member

Choose a reason for hiding this comment

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

how is this handling valueFrom? same question in applicationGenerator

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This is just a switch for backwards compatibility.

  • if it gets a hash, this is the "old way" that needs to transform into [{name:'',value:''}, etc]
  • If it gets an array, return the array (input arg). We've already

Off the top of my head I'm not sure why it received a hash of {'<name>': '<value>'} to begin with.

@@ -112,6 +124,7 @@ angular.module('openshiftConsole')
$scope.loaded = true;
$scope.deployment = deployment;
updateHPAWarnings();
EnvironmentService.toggleReadonlyForContainerEnvsValueFrom(_.get($scope.deployment, 'spec.template.spec.containers'), envSecretAndConfigMapAreReadonly);
Copy link
Member

Choose a reason for hiding this comment

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

Is the purpose of all of these calls to toggleReadonly just to wait until secrets/configmaps are loaded before letting you touch the dropdowns? If so I want to discuss a different approach tomorrow. I'm not a fan of adding more gorp to the model data, I already don't like how much extra stuff we are adding that doesn't need to be getting sent to the server.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good word, gorp. We have keyValueEditorUtils.cleanEntries() setup to clean off all the gorp & went through it pretty thoroughly to ensure we didn't miss anything. Agree its a bit clunky & i'd love to fix it. Thought about kve_ prefixing all the stuff we add so it would be easier to clean off, but there might be a better way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Other than the gorp, looking @ the toggle again per our discussion to see if we can clean up.

Copy link
Contributor

Choose a reason for hiding this comment

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

We considered moving the DataService.list("secrets") and DataService.list("configmaps") into the directive & eliminating the controller noise... might be a good way to fix this.

@@ -10,6 +10,8 @@ angular.module("openshiftConsole")
hookParams: "=model",
availableVolumes: "=",
availableContainers: "=",
availableSecrets: "=",
availableConfigmaps: "=",
Copy link
Member

Choose a reason for hiding this comment

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

availableConfigMaps

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Fixed.


<div ng-if="(!entry.valueFrom)">
<input
ng-if="(!entry.valueAlt)"
Copy link
Member

Choose a reason for hiding this comment

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

is this ng-if still needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

<span ng-switch-when="configMapKeyRef">
Set to the key {{entry.valueFrom.configMapKeyRef.key}} in config map
<span
ng-if="entry.isReadonlyValue">
Copy link
Member

Choose a reason for hiding this comment

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

why is the appearance of the name as a link dependent on whether the value is readonly? shouldn't the appearance of the link depend on whether the user has rights to view secrets / view config maps using a canI check?

Copy link
Member Author

@rhamilto rhamilto Feb 15, 2017

Choose a reason for hiding this comment

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

We are using canI to check if the user has rights to view config maps or secrets, we're just using a single scope parameter (entry.isReadonlyValue) to track multiple conditions as this was easier than having multiple params. The thought being it was better to keep this logic in the controller and have one less key to clean off entry. Yea/nay?

  1. If the user can get config maps or secrets and the kve instance is NOT read only, we show the ui-selects for config maps and secrets.

screen shot 2017-02-15 at 9 03 35 am

  1. If the user can get config maps or secrets and the kve instance is read only, we show the faux input with the link.

screen shot 2017-02-15 at 9 03 46 am

  1. If the user can NOT get config maps or secrets and the kve instance is NOT read only, we show the faux input without the link.

screen shot 2017-02-15 at 9 11 42 am

  1. If the user can NOT get config maps or secrets and the kve instance is read only, we show the faux input without the link.

screen shot 2017-02-15 at 9 11 36 am

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we doc this somewhere? Comments @ the top of the directive for future reference?

<div ng-if="(!isReadonlyAny) && (!entry.isReadonlyValue)">
<div class="ui-select">
<ui-select ng-model="entry.selectedValueFrom" ng-required="true" on-select="valueFromObjectSelected(entry, $select.selected)">
<ui-select-match placeholder="Select config map or secret">
Copy link
Member

Choose a reason for hiding this comment

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

we made the link configurable to support other options down the road, but then hardcoded this one into the editor. We made the list of objects generic to support other types, would this be better off as just "Select a resource" or something.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Changed to "Select a resource"

@jwforres
Copy link
Member

jwforres commented Feb 17, 2017 via email

@jwforres
Copy link
Member

jwforres commented Feb 17, 2017 via email

@benjaminapetersen
Copy link
Contributor

  • Everything is being cleaned, either via compact() or directly.

@benjaminapetersen
Copy link
Contributor

benjaminapetersen commented Feb 17, 2017

@jwforres I believe we did it to reduce template logic, we began in the view file but ended up branching/copy paste more than we liked. Doing the check up front simplified the branching.

@benjaminapetersen
Copy link
Contributor

@jwforres isReadonly still just controls wether or not you get the select pickers. In the readonly state, we use canI to render either plain text, or text with a link, based on if you have perms to work with secrets/configmaps (outlined in this comment).

role="button"
aria-label="Add row"
ng-click="onAddRow()">{{ addRowLink }}</a>
<span
Copy link
Member Author

@rhamilto rhamilto Feb 17, 2017

Choose a reason for hiding this comment

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

Moar simpler: a single span wrapping both the pipe and the link with ng-if="valueFromSelectorOptions.length"

Copy link
Member Author

Choose a reason for hiding this comment

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

Moar simpler: a single span wrapping both the pipe and the link with ng-if="valueFromSelectorOptions.length"

Done.

<span ng-switch-when="secretKeyRef">
Set to the key {{entry.valueFrom.secretKeyRef.key}} in secret
<span
ng-if="entry.isReadonlyValue">
Copy link
Member Author

Choose a reason for hiding this comment

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

canI is much clearer to anyone reading the template. Let's use it instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

canI is much clearer to anyone reading the template. Let's use it instead.

Done

@benjaminapetersen
Copy link
Contributor

@jwforres gonna jot down the flow here quick as well, with deployments as an example. It will explain the odd envSecretAndConfigMapAreReadonly variable. I'm open to improvements.

  • the DataService.get('deployments') is called initially & sets envSecretAndConfigMapAreReadonly to true since we don't have secrets/configmaps yet. Nothing should be editable.
  • then the DataService.watchObject('deployments') is called, along with DataService.list('configmaps') and DataService.list('secrets'). We don't know which will return first, which is why we have the quirky logic.
  • If the DataService.watchObject('deployments') happens to fire, envSecretAndConfigMapAreReadonly does not flip, there is no new info for us to toggle state (we already had this). This watch, if fired, needs to regenerate the state as it is, not knowing if it has secrets/configmaps or not.
  • But, if either DataService.list("configmaps") or DataService.list("secrets") return first, we do flip the bit, and we can now show the pickers.
  • Since the watch may update many times, we need it to just trust the state of envSecretAndConfigMapAreReadonly wherever it has landed based on the other 3 calls.

Hopefully that makes sense... and moves along some discussion about simplifying if we can make it happen!

data-toggle="tooltip"
data-placement="top"
data-original-title="{{entry.valueIconTooltip || valueIconTooltip}}"
title="{{entry.valueIconTooltip || valueIconTooltip}}"></span>
Copy link
Member

Choose a reason for hiding this comment

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

while we are fixing things... can you remove the extra title attribute here, it is causing https://bugzilla.redhat.com/show_bug.cgi?id=1395079

@jwforres
Copy link
Member

[merge]

1 similar comment
@jwforres
Copy link
Member

[merge]

@jwforres
Copy link
Member

take three [merge]

rhamilto and others added 2 commits February 21, 2017 14:39
- add valueFromSelectorOptions checks in kve to detect readonly state
- add isValueFromEditable fn to clean up view
- remove redundant title= attrs
@jwforres
Copy link
Member

[merge]

1 similar comment
@jwforres
Copy link
Member

[merge]

@openshift-bot
Copy link

Evaluated for origin web console merge up to 7d79245

@openshift-bot
Copy link

openshift-bot commented Feb 21, 2017

Origin Web Console Merge Results: SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_web_console/1030/) (Base Commit: abb2505)

@openshift-bot openshift-bot merged commit 8c3bb14 into openshift:master Feb 21, 2017
@rhamilto rhamilto deleted the kve branch February 22, 2017 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants