示例#1
0
def process(schema, values, deployer_image, deployer_entrypoint, version_repo,
            image_pull_secret):
  props = {}
  manifests = []
  app_name = get_name(schema, values)
  namespace = get_namespace(schema, values)

  # Inject DEPLOYER_IMAGE property values if not already present.
  values = inject_deployer_image_properties(values, schema, deployer_image)

  # Handle provisioning of reporting secrets from storage if a URI
  # is provided.
  for key, value in values.items():
    if key not in schema.properties:
      continue
    if not schema.properties[key].reporting_secret:
      continue
    if '://' in value:
      value, storage_manifests = provision_from_storage(
          key, value, app_name=app_name, namespace=namespace)
      values[key] = value
      manifests += storage_manifests

  for prop in schema.properties.values():
    if prop.name in values:
      # The value has been explicitly specified. Skip.
      continue
    if prop.service_account:
      value, sa_manifests = provision_service_account(
          schema,
          prop,
          app_name=app_name,
          namespace=namespace,
          image_pull_secret=image_pull_secret)
      props[prop.name] = value
      manifests += sa_manifests
    elif prop.storage_class:
      value, sc_manifests = provision_storage_class(
          schema, prop, app_name=app_name, namespace=namespace)
      props[prop.name] = value
      manifests += sc_manifests
    elif prop.xtype == config_helper.XTYPE_ISTIO_ENABLED:
      # TODO: Really populate this value.
      props[prop.name] = False
    elif prop.xtype == config_helper.XTYPE_INGRESS_AVAILABLE:
      # TODO(#360): Really populate this value.
      props[prop.name] = True
    elif prop.password:
      props[prop.name] = property_generator.generate_password(prop.password)
    elif prop.tls_certificate:
      props[prop.name] = property_generator.generate_tls_certificate()

  # Merge input and provisioned properties.
  app_params = dict(list(values.iteritems()) + list(props.iteritems()))

  use_kalm = False
  if (schema.is_v2() and
      schema.x_google_marketplace.managed_updates.kalm_supported):
    if version_repo:
      use_kalm = True
    else:
      log.warn('The deployer supports KALM but no --version-repo specified. '
               'Falling back to provisioning the deployer job only.')

  if use_kalm:
    manifests += provision_kalm(
        schema,
        version_repo=version_repo,
        app_name=app_name,
        namespace=namespace,
        deployer_image=deployer_image,
        image_pull_secret=image_pull_secret,
        app_params=app_params)
  else:
    manifests += provision_deployer(
        schema,
        app_name=app_name,
        namespace=namespace,
        deployer_image=deployer_image,
        deployer_entrypoint=deployer_entrypoint,
        image_pull_secret=image_pull_secret,
        app_params=app_params)
  return manifests
示例#2
0
def expand(values_dict, schema, app_uid=''):
    """Returns the expanded values according to schema."""
    schema.validate()

    valid_property_names = set(schema.properties.keys())
    valid_property_names.add(_IMAGE_REPO_PREFIX_PROPERTY_NAME)

    for k in values_dict:
        if k not in valid_property_names:
            raise InvalidProperty(
                'No such property defined in schema: {}'.format(k))

    # Captures the final property name-value mappings.
    # This has both properties directly specified under schema's `properties` and
    # generated properties. See below for details about generated properties.
    result = {}
    # Captures only the generated properties. These are not directly specified in
    # the schema under `properties`. Rather, their name are specified in special
    # `generatedProperties` fields under each property's `x-google-marketplace`.
    # Note that properties with generated values are NOT generated properties.
    generated = {}

    if schema.is_v2():
        # Handles the images section of the schema.
        generate_v2_image_properties(schema, values_dict, generated)

    # Copy explicitly specified values and generate values into result.
    for k, prop in schema.properties.items():
        v = values_dict.get(k, None)

        # The value is not explicitly specified and
        # thus is eligible for auto-generation.
        if v is None:
            if prop.password:
                v = property_generator.generate_password(prop.password)
            elif prop.application_uid:
                v = app_uid or ''
            elif prop.tls_certificate:
                v = property_generator.generate_tls_certificate()
            elif prop.xtype == config_helper.XTYPE_ISTIO_ENABLED:
                # For backward compatibility.
                v = False
            elif prop.xtype == config_helper.XTYPE_INGRESS_AVAILABLE:
                # For backward compatibility.
                v = True
            elif prop.xtype == config_helper.XTYPE_DEPLOYER_IMAGE:
                v = maybe_derive_deployer_image(schema, values_dict)
            elif prop.default is not None:
                v = prop.default

        # Generate additional properties from this property.
        if v is not None:
            if prop.image:
                if not isinstance(v, str):
                    raise InvalidProperty(
                        'Invalid value for IMAGE property {}: {}'.format(k, v))
                generate_v1_properties_for_image(prop, v, generated)
            elif prop.string:
                if not isinstance(v, str):
                    raise InvalidProperty(
                        'Invalid value for STRING property {}: {}'.format(
                            k, v))
                generate_properties_for_string(prop, v, generated)
            elif prop.tls_certificate:
                if not isinstance(v, str):
                    raise InvalidProperty(
                        'Invalid value for TLS_CERTIFICATE property {}: {}'.
                        format(k, v))
                generate_properties_for_tls_certificate(prop, v, generated)
            elif prop.application_uid:
                generate_properties_for_appuid(prop, v, generated)

        if v is not None:
            result[k] = v

    validate_value_types(result, schema)
    validate_required_props(result, schema)

    # Copy generated properties into result, validating no collisions.
    for k, v in generated.items():
        if k in result:
            raise InvalidProperty(
                'The property is to be generated, but already has a value: {}'.
                format(k))
        result[k] = v
    return result