You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/09/13 01:05:17 UTC

[GitHub] [apisix] zhixiongdu027 commented on a diff in pull request #7895: feat: support multiple kubernets clusters discovery

zhixiongdu027 commented on code in PR #7895:
URL: https://github.com/apache/apisix/pull/7895#discussion_r969049507


##########
apisix/discovery/kubernetes/schema.lua:
##########
@@ -28,113 +28,228 @@ local port_patterns = {
 local namespace_pattern = [[^[a-z0-9]([-a-z0-9_.]*[a-z0-9])?$]]
 local namespace_regex_pattern = [[^[\x21-\x7e]*$]]
 
+local shared_pattern = [[^[1-9][0-9]?m$]]
+
 return {
-    type = "object",
-    properties = {
-        service = {
+    anyOf = {
+        {
             type = "object",
             properties = {
-                schema = {
-                    type = "string",
-                    enum = { "http", "https" },
-                    default = "https",
+                service = {
+                    type = "object",
+                    properties = {
+                        schema = {
+                            type = "string",
+                            enum = { "http", "https" },
+                            default = "https",
+                        },
+                        host = {
+                            type = "string",
+                            default = "${KUBERNETES_SERVICE_HOST}",
+                            oneOf = host_patterns,
+                        },
+                        port = {
+                            type = "string",
+                            default = "${KUBERNETES_SERVICE_PORT}",
+                            oneOf = port_patterns,
+                        },
+                    },
+                    default = {
+                        schema = "https",
+                        host = "${KUBERNETES_SERVICE_HOST}",
+                        port = "${KUBERNETES_SERVICE_PORT}",
+                    }
                 },
-                host = {
-                    type = "string",
-                    default = "${KUBERNETES_SERVICE_HOST}",
-                    oneOf = host_patterns,
+                client = {
+                    type = "object",
+                    properties = {
+                        token = {
+                            type = "string",
+                            oneOf = {
+                                { pattern = [[\${[_A-Za-z]([_A-Za-z0-9]*[_A-Za-z])*}$]] },
+                                { pattern = [[^[A-Za-z0-9+\/._=-]{0,4096}$]] },
+                            },
+                        },
+                        token_file = {
+                            type = "string",
+                            pattern = [[^[^\:*?"<>|]*$]],
+                            minLength = 1,
+                            maxLength = 500,
+                        }
+                    },
+                    default = {
+                        token_file = "/var/run/secrets/kubernetes.io/serviceaccount/token"
+                    },
+                    ["if"] = {
+                        ["not"] = {
+                            anyOf = {
+                                { required = { "token" } },
+                                { required = { "token_file" } },
+                            }
+                        }
+                    },
+                    ["then"] = {
+                        properties = {
+                            token_file = {
+                                default = "/var/run/secrets/kubernetes.io/serviceaccount/token"
+                            }
+                        }
+                    }
                 },
-                port = {
-                    type = "string",
-                    default = "${KUBERNETES_SERVICE_PORT}",
-                    oneOf = port_patterns,
+                default_weight = {
+                    type = "integer",
+                    default = 50,
+                    minimum = 0,
                 },
-            },
-            default = {
-                schema = "https",
-                host = "${KUBERNETES_SERVICE_HOST}",
-                port = "${KUBERNETES_SERVICE_PORT}",
-            }
-        },
-        client = {
-            type = "object",
-            properties = {
-                token = {
-                    type = "string",
+                namespace_selector = {
+                    type = "object",
+                    properties = {
+                        equal = {
+                            type = "string",
+                            pattern = namespace_pattern,
+                        },
+                        not_equal = {
+                            type = "string",
+                            pattern = namespace_pattern,
+                        },
+                        match = {
+                            type = "array",
+                            items = {
+                                type = "string",
+                                pattern = namespace_regex_pattern
+                            },
+                            minItems = 1
+                        },
+                        not_match = {
+                            type = "array",
+                            items = {
+                                type = "string",
+                                pattern = namespace_regex_pattern
+                            },
+                            minItems = 1
+                        },
+                    },
                     oneOf = {
-                        { pattern = [[\${[_A-Za-z]([_A-Za-z0-9]*[_A-Za-z])*}$]] },
-                        { pattern = [[^[A-Za-z0-9+\/._=-]{0,4096}$]] },
+                        { required = {} },
+                        { required = { "equal" } },
+                        { required = { "not_equal" } },
+                        { required = { "match" } },
+                        { required = { "not_match" } }
                     },
                 },
-                token_file = {
+                label_selector = {
+                    type = "string",
+                },
+                shared_size = {
                     type = "string",
-                    pattern = [[^[^\:*?"<>|]*$]],
-                    minLength = 1,
-                    maxLength = 500,
+                    pattern = shared_pattern,
+                    default = "1m",
                 }
             },
-            oneOf = {
-                { required = { "token" } },
-                { required = { "token_file" } },
-            },
-            default = {
-                token_file = "/var/run/secrets/kubernetes.io/serviceaccount/token"
-            }
         },
-        default_weight = {
-            type = "integer",
-            default = 50,
-            minimum = 0,
-        },
-        namespace_selector = {
-            type = "object",
-            properties = {
-                equal = {
-                    type = "string",
-                    pattern = namespace_pattern,
-                },
-                not_equal = {
-                    type = "string",
-                    pattern = namespace_pattern,
-                },
-                match = {
-                    type = "array",
-                    items = {
+        {
+            type = "array",
+            minItems = 1,
+            items = {
+                type = "object",
+                properties = {
+                    id = {
                         type = "string",
-                        pattern = namespace_regex_pattern
+                        pattern = [[^[a-z0-9]{1,6}$]]
                     },
-                    minItems = 1
-                },
-                not_match = {
-                    type = "array",
-                    items = {
+                    service = {

Review Comment:
   Maybe not a good idea , because service had default value in single mode but no default value in multiple mode .
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org