Ejemplo n.º 1
0
 def testContainerPortChangeNumberDefaultAndUnname(self):
   self.resource.template.container.ports = [
       self.serverless_messages.ContainerPort(name='h2c', containerPort=456)
   ]
   self.resource = config_changes.ContainerPortChange(
       port='default', use_http2=False).Adjust(self.resource)
   self.assertEqual(0, len(self.resource.template.container.ports))
Ejemplo n.º 2
0
 def testContainerPortChangeNumberDefault(self):
   self.resource.template.container.ports = [
       self.serverless_messages.ContainerPort(containerPort=456)
   ]
   self.resource = config_changes.ContainerPortChange(port='default').Adjust(
       self.resource)
   self.assertEqual(0, len(self.resource.template.container.ports))
Ejemplo n.º 3
0
 def testContainerPortChangeNumberNewPort(self):
   self.resource = config_changes.ContainerPortChange(port='123').Adjust(
       self.resource)
   self.assertEqual(1, len(self.resource.template.container.ports))
   self.assertIsNone(self.resource.template.container.ports[0].name)
   self.assertEqual(
       123, self.resource.template.container.ports[0].containerPort)
Ejemplo n.º 4
0
 def testContainerPortChangeNameNewPort(self):
   self.resource = config_changes.ContainerPortChange(use_http2=True).Adjust(
       self.resource)
   self.assertEqual(1, len(self.resource.template.container.ports))
   self.assertEqual(
       'h2c', self.resource.template.container.ports[0].name)
   self.assertEqual(
       8080, self.resource.template.container.ports[0].containerPort)
Ejemplo n.º 5
0
 def testContainerPortChangeUnnameExistingPort(self):
   self.resource.template.container.ports = [
       self.serverless_messages.ContainerPort(name='h2c', containerPort=456)
   ]
   self.resource = config_changes.ContainerPortChange(use_http2=False).Adjust(
       self.resource)
   self.assertEqual(1, len(self.resource.template.container.ports))
   self.assertIsNone(self.resource.template.container.ports[0].name)
   self.assertEqual(
       456, self.resource.template.container.ports[0].containerPort)
Ejemplo n.º 6
0
 def testContainerPortChangeNumberExistingPort(self):
   self.resource.template.container.ports = [
       self.serverless_messages.ContainerPort(containerPort=456)
   ]
   self.resource = config_changes.ContainerPortChange(port='123').Adjust(
       self.resource)
   self.assertEqual(1, len(self.resource.template.container.ports))
   self.assertIsNone(self.resource.template.container.ports[0].name)
   self.assertEqual(
       123, self.resource.template.container.ports[0].containerPort)
Ejemplo n.º 7
0
 def testContainerPortChangeNumberDefaultExistingName(self):
   self.resource.template.container.ports = [
       self.serverless_messages.ContainerPort(name='h2c', containerPort=456)
   ]
   self.resource = config_changes.ContainerPortChange(port='default').Adjust(
       self.resource)
   self.assertEqual(1, len(self.resource.template.container.ports))
   self.assertEqual(
       'h2c', self.resource.template.container.ports[0].name)
   self.assertEqual(
       8080, self.resource.template.container.ports[0].containerPort)
Ejemplo n.º 8
0
def GetConfigurationChanges(args):
  """Returns a list of changes to Configuration, based on the flags set."""
  changes = []
  changes.extend(_GetScalingChanges(args))
  if _HasEnvChanges(args):
    changes.append(_GetEnvChanges(args))

  if _HasTrafficChanges(args):
    changes.append(_GetTrafficChanges(args))

  if _HasCloudSQLChanges(args):
    region = GetRegion(args)
    project = (
        getattr(args, 'project', None) or
        properties.VALUES.core.project.Get(required=True))
    _CheckCloudSQLApiEnablement()
    changes.append(config_changes.CloudSQLChanges(project, region, args))

  if _HasSecretsChanges(args):
    changes.extend(_GetSecretsChanges(args))

  if _HasConfigMapsChanges(args):
    changes.extend(_GetConfigMapsChanges(args))

  if 'no_traffic' in args and args.no_traffic:
    changes.append(config_changes.NoTrafficChange())

  if 'cpu' in args and args.cpu:
    changes.append(config_changes.ResourceChanges(cpu=args.cpu))
  if 'memory' in args and args.memory:
    changes.append(config_changes.ResourceChanges(memory=args.memory))
  if 'concurrency' in args and args.concurrency:
    changes.append(config_changes.ConcurrencyChanges(
        concurrency=args.concurrency))
  if 'timeout' in args and args.timeout:
    try:
      # A bare number is interpreted as seconds.
      timeout_secs = int(args.timeout)
    except ValueError:
      timeout_duration = times.ParseDuration(args.timeout)
      timeout_secs = int(timeout_duration.total_seconds)
    if timeout_secs <= 0:
      raise ArgumentError(
          'The --timeout argument must be a positive time duration.')
    changes.append(config_changes.TimeoutChanges(timeout=timeout_secs))
  if 'service_account' in args and args.service_account:
    changes.append(
        config_changes.ServiceAccountChanges(
            service_account=args.service_account))
  if _HasLabelChanges(args):
    additions = (
        args.labels
        if _FlagIsExplicitlySet(args, 'labels') else args.update_labels)
    diff = labels_util.Diff(
        additions=additions,
        subtractions=args.remove_labels,
        clear=args.clear_labels)
    if diff.MayHaveUpdates():
      changes.append(config_changes.LabelChanges(diff))
  if 'revision_suffix' in args and args.revision_suffix:
    changes.append(config_changes.RevisionNameChanges(args.revision_suffix))
  if 'vpc_connector' in args and args.vpc_connector:
    changes.append(config_changes.VpcConnectorChange(args.vpc_connector))
  if 'clear_vpc_connector' in args and args.clear_vpc_connector:
    changes.append(config_changes.ClearVpcConnectorChange())
  if 'connectivity' in args and args.connectivity:
    if args.connectivity == 'internal':
      changes.append(config_changes.EndpointVisibilityChange(True))
    elif args.connectivity == 'external':
      changes.append(config_changes.EndpointVisibilityChange(False))
  if 'command' in args and args.command is not None:
    # Allow passing an empty string here to reset the field
    changes.append(config_changes.ContainerCommandChange(args.command))
  if 'args' in args and args.args is not None:
    # Allow passing an empty string here to reset the field
    changes.append(config_changes.ContainerArgsChange(args.args))
  if _FlagIsExplicitlySet(args, 'port'):
    changes.append(config_changes.ContainerPortChange(port=args.port))
  if _FlagIsExplicitlySet(args, 'use_http2'):
    changes.append(config_changes.ContainerPortChange(use_http2=args.use_http2))
  return changes
Ejemplo n.º 9
0
 def testContainerPortChangeUnnameNewPort(self):
   self.resource = config_changes.ContainerPortChange(use_http2=False).Adjust(
       self.resource)
   self.assertEqual(0, len(self.resource.template.container.ports))