Skip to content

Use type URL for cluster factories #37144

Closed as not planned
Closed as not planned
@Stevenjin8

Description

Title: Use type URL for cluster factories

Description:

from #36353. We want to use type URL instead of names for cluster factories. That is refactor the following code

ClusterFactoryImplBase::create(const envoy::config::cluster::v3::Cluster& cluster,
Server::Configuration::ServerFactoryContext& server_context,
ClusterManager& cm, LazyCreateDnsResolver dns_resolver_fn,
Ssl::ContextManager& ssl_context_manager,
Outlier::EventLoggerSharedPtr outlier_event_logger,
bool added_via_api) {
std::string cluster_type;
if (!cluster.has_cluster_type()) {
switch (cluster.type()) {
PANIC_ON_PROTO_ENUM_SENTINEL_VALUES;
case envoy::config::cluster::v3::Cluster::STATIC:
cluster_type = "envoy.cluster.static";
break;
case envoy::config::cluster::v3::Cluster::STRICT_DNS:
cluster_type = "envoy.cluster.strict_dns";
break;
case envoy::config::cluster::v3::Cluster::LOGICAL_DNS:
cluster_type = "envoy.cluster.logical_dns";
break;
case envoy::config::cluster::v3::Cluster::ORIGINAL_DST:
cluster_type = "envoy.cluster.original_dst";
break;
case envoy::config::cluster::v3::Cluster::EDS:
cluster_type = "envoy.cluster.eds";
break;
}
} else {
cluster_type = cluster.cluster_type().name();
}
if (cluster.common_lb_config().has_consistent_hashing_lb_config() &&
cluster.common_lb_config().consistent_hashing_lb_config().use_hostname_for_hashing() &&
cluster.type() != envoy::config::cluster::v3::Cluster::STRICT_DNS) {
return absl::InvalidArgumentError(fmt::format(
"Cannot use hostname for consistent hashing loadbalancing for cluster of type: '{}'",
cluster_type));
}
ClusterFactory* factory = Registry::FactoryRegistry<ClusterFactory>::getFactory(cluster_type);
if (factory == nullptr) {
return absl::InvalidArgumentError(fmt::format(
"Didn't find a registered cluster factory implementation for name: '{}'", cluster_type));
}
ClusterFactoryContextImpl context(server_context, cm, dns_resolver_fn, ssl_context_manager,
std::move(outlier_event_logger), added_via_api);
return factory->create(cluster, context);
}

This is somewhat complex some cluster types (original dst, static), don't have type URLs, so we're probably going to need to create placeholder protos for them.

There is also a question for how much backcompatibility we want to preserve. For example, the following cluster is valid,

cluster_type:
  name: envoy.cluster.original_dst # or static
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.network.dns.v3.GetAddrInfo  # or anything else, but not empty

This means that if we want to be strict about backcompatibility, we will never be able to select cluster factories purely by type_url. However, I'd be pretty surprised if anybody is using a config like the one above, since it doesn't make a lot of sense.

[optional Relevant Links:]

Any extra documentation required to understand the issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiarea/clusterenhancementFeature requests. Not bugs or questions.stalestalebot believes this issue/PR has not been touched recently

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions