]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: server: lookup defaults section on "from srv:"
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 23 Nov 2026 08:53:09 +0000 (09:53 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 23 Nov 2026 13:54:31 +0000 (14:54 +0100)
When defining a server, notation 'from srv:<bename>/<srvname>' can be
specified to inherit from a server or default-server defined in another
backend instance.

Extend this to also look up in defaults sections. This is safe as
proxies and defaults sections cannot have the same name since 3.3.

Without this patch, a named default-server in a named defaults section
is unusable as it cannot be referenced by the existing syntax.

doc/configuration.txt
reg-tests/server/from_keyword.vtc
src/server.c

index 67754a261a49df5a04e07e75df437c2ffe9c59ed..7065b72a040f01214e9513ce92a91f3fe09de12e 100644 (file)
@@ -19320,11 +19320,14 @@ from <origin>
       is mostly useful for dynamic servers created on the CLI which by default
       ignore any default-server, which is equivalent to the "none" value.
   - srv:[<bename>/]<srvname>
-      instructs to reuse the settings from the designated backend's server or named
-      default-server resulting from the processing of all its default-server
-      directives using the same name. The backend name is optional. If unset,
-      this designates the proxy where the currently newly defined server will
-      be attached.
+      instructs to reuse the settings from the designated backend's server or
+      named default-server resulting from the processing of all its
+      default-server directives using the same name. The backend name is
+      optional. If unset, this designates the proxy where the currently newly
+      defined server will be attached. Alternatively, a named defaults section
+      can also be specified to inherit from a named default-server. Only a
+      server or named default-server directly declared in the target backend or
+      defaults section can be specified; inherited entries are not resolved.
 
 The currently supported server settings are the following ones. Note that all
 these settings are supported both by "server" and "default-server" keywords,
index 78a5e95708abf6a7363c152316f1fad91466b8c2..e138d6cafb18a1c113372def8f5ed2b5bf7a7ca0 100644 (file)
@@ -14,6 +14,9 @@ haproxy h1 -conf {
                thread-groups 1
        .endif
 
+       defaults defpx
+               default-server name srv weight 20
+
        defaults
                mode http
                timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
@@ -55,6 +58,9 @@ haproxy h1 -conf {
                default-server name other weight 5
                server srvconf7 ${s1_addr}:${s1_port} from srv:other
 
+               # inherit from a defaults section
+               server srvconf8 ${s1_addr}:${s1_port} from srv:defpx/srv
+
        backend be_defempty
                default-server check
                # reset default-server will be purged on post parsing
@@ -88,6 +94,9 @@ haproxy h1 -cli {
 
        send "get weight be/srvconf7"
        expect ~ "5 \\(initial 5\\)"
+
+       send "get weight be/srvconf8"
+       expect ~ "20 \\(initial 20\\)"
 }
 
 # dynamic servers
index 86918ce04a8f977f69c083738985ec12ccb7f642..4129e8223c4f72a829313032a78e1747f2809443 100644 (file)
@@ -4061,13 +4061,18 @@ static struct server *lookup_srv_be_arg(struct ist sv_name,
 {
        struct server *srv;
        struct ist be_name;
+       const char *be_name0;
        struct proxy *px = curproxy;
 
        if (istchr(sv_name, '/')) {
                be_name = istsplit(&sv_name, '/');
-               px = proxy_be_by_name(ist0(be_name));
+               be_name0 = ist0(be_name);
+
+               px = proxy_be_by_name(be_name0);
+               if (!px)
+                       px = proxy_find_by_name(be_name0, PR_CAP_DEF, 0);
                if (!px) {
-                       memprintf(msg, "unknown backend '%s'", istptr(be_name));
+                       memprintf(msg, "unknown backend or defaults '%s'", istptr(be_name));
                        return NULL;
                }
        }