Esempio n. 1
0
def _GetConfigMapsChanges(args):
  """Return config map env var and volume changes for given args."""
  volume_kwargs = {}
  env_kwargs = {}

  update = args.update_config_maps or args.set_config_maps
  if update:
    volume_update = {k: v for k, v in update.items() if _IsVolumeMountKey(k)}
    if volume_update:
      volume_kwargs['mounts_to_update'] = volume_update
    env_update = {k: v for k, v in update.items() if not _IsVolumeMountKey(k)}
    if env_update:
      env_kwargs['env_vars_to_update'] = env_update

  remove = args.remove_config_maps
  if remove:
    volume_remove = [k for k in remove if _IsVolumeMountKey(k)]
    if volume_remove:
      volume_kwargs['mounts_to_remove'] = volume_remove
    env_remove = [k for k in remove if not _IsVolumeMountKey(k)]
    if env_remove:
      env_kwargs['env_vars_to_remove'] = env_remove

  if args.set_config_maps or args.clear_config_maps:
    env_kwargs['clear_others'] = True
    volume_kwargs['clear_others'] = True

  secret_changes = []
  if env_kwargs:
    secret_changes.append(config_changes.ConfigMapEnvVarChanges(**env_kwargs))
  if volume_kwargs:
    secret_changes.append(
        config_changes.ConfigMapVolumeChanges(**volume_kwargs))
  return secret_changes
Esempio n. 2
0
 def testVolumeRemove(self):
   self.template.volumes.secrets.update({
       'secret1-abc': self._MakeSecretVolumeSource('secret1'),
   })
   self.template.volumes.config_maps.update({
       'config1-abc': self._MakeConfigMapVolumeSource('config1'),
       'config2-def': self._MakeConfigMapVolumeSource('config2'),
   })
   self.template.volume_mounts.secrets.update({
       '/path1': 'secret1-abc',
   })
   self.template.volume_mounts.config_maps.update({
       '/path2': 'config1-abc',
       '/path3': 'config2-def',
   })
   volume_change = config_changes.ConfigMapVolumeChanges(
       mounts_to_remove=['/path2'])
   self.resource = volume_change.Adjust(self.resource)
   self.assertDictEqual({
       'secret1-abc': self._MakeSecretVolumeSource('secret1'),
   }, dict(self.template.volumes.secrets))
   self.assertDictEqual({
       'config2-def': self._MakeConfigMapVolumeSource('config2'),
   }, dict(self.template.volumes.config_maps))
   self.assertDictEqual({
       '/path1': 'secret1-abc',
   }, dict(self.template.volume_mounts.secrets))
   self.assertDictEqual({
       '/path3': 'config2-def',
   }, dict(self.template.volume_mounts.config_maps))
Esempio n. 3
0
 def testVolumeUpdateFailsIfWrongType(self):
   self.template.volumes.secrets.update({
       'secret1-abc': self._MakeSecretVolumeSource('secret1'),
   })
   self.template.volume_mounts.secrets.update({
       '/path1': 'secret1-abc',
   })
   volume_change = config_changes.ConfigMapVolumeChanges(
       mounts_to_update={
           '/path1': 'config1',
       })
   with self.assertRaises(exceptions.ConfigurationError):
     volume_change.Adjust(self.resource)
Esempio n. 4
0
 def testRemoveSilentlyFailsIfDoesntExist(self):
   self.template.volumes.secrets.update({
       'secret1-abc': self._MakeSecretVolumeSource('secret1'),
   })
   self.template.volume_mounts.secrets.update({
       '/path1': 'secret1-abc',
   })
   volume_change = config_changes.ConfigMapVolumeChanges(
       mounts_to_remove=['/path1', '/path2'])
   self.resource = volume_change.Adjust(self.resource)
   self.assertDictEqual({
       'secret1-abc': self._MakeSecretVolumeSource('secret1'),
   }, dict(self.template.volumes.secrets))
   self.assertDictEqual({
       '/path1': 'secret1-abc',
   }, dict(self.template.volume_mounts.secrets))
Esempio n. 5
0
def _GetConfigMapsChanges(args):
    """Return config_changes.ConfigMapVolumeChanges for given args."""
    kwargs = {}

    update = args.update_config_maps or args.set_config_maps
    if update:
        kwargs['mounts_to_update'] = update

    remove = args.remove_config_maps
    if remove:
        kwargs['mounts_to_remove'] = remove

    if args.set_config_maps or args.clear_config_maps:
        kwargs['clear_others'] = True

    return config_changes.ConfigMapVolumeChanges(**kwargs)