From 51eac0b335bf3ba1941a49241a2aa81d05abb07b Mon Sep 17 00:00:00 2001 From: lixiaoyuner <35456895+lixiaoyuner@users.noreply.github.com> Date: Mon, 17 Oct 2022 15:58:09 +0800 Subject: [PATCH] Add k8s master table yang model (#12331) * Add k8s master table yang model Signed-off-by: Yun Li --- src/sonic-yang-models/doc/Configuration.md | 22 ++++++ src/sonic-yang-models/setup.py | 2 + .../tests/files/sample_config_db.json | 8 ++ .../tests/kubernetes_master.json | 27 +++++++ .../tests_config/kubernetes_master.json | 74 +++++++++++++++++++ .../yang-models/sonic-kubernetes_master.yang | 62 ++++++++++++++++ 6 files changed, 195 insertions(+) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/kubernetes_master.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/kubernetes_master.json create mode 100644 src/sonic-yang-models/yang-models/sonic-kubernetes_master.yang diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index 060751ab4d70..f30a2c8c5f23 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -28,6 +28,7 @@ Table of Contents * [DSCP_TO_TC_MAP](#dscp_to_tc_map) * [FLEX_COUNTER_TABLE](#flex_counter_table) * [KDUMP](#kdump) + * [Kubernetes Master](#kubernetes-master) * [L2 Neighbors](#l2-neighbors) * [Loopback Interface](#loopback-interface) * [LOSSLESS_TRAFFIC_PATTERN](#LOSSLESS_TRAFFIC_PATTERN) @@ -936,6 +937,27 @@ instance is supported in SONiC. ``` +### Kubernetes Master + +Kubernetes Master related configurations are stored in +**KUBERNETES_MASTER** table. These configurations are used mainly +for CTRMGR service. CTRMGR service will interactive with +kubernetes master according to these configurations. + +``` +{ + "KUBERNETES_MASTER": { + "SERVER": { + "disable": "False", + "insecure": "True", + "ip": "k8s.apiserver.com", + "port": "6443" + } + } +} + +``` + ### L2 Neighbors The L2 neighbor and connection information can be configured in diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index db9fb9d4f56b..b620438451ac 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -112,6 +112,7 @@ def run(self): './yang-models/sonic-system-defaults.yang', './yang-models/sonic-interface.yang', './yang-models/sonic-kdump.yang', + './yang-models/sonic-kubernetes_master.yang', './yang-models/sonic-loopback-interface.yang', './yang-models/sonic-lossless-traffic-pattern.yang', './yang-models/sonic-mgmt_interface.yang', @@ -185,6 +186,7 @@ def run(self): './cvlyang-models/sonic-system-defaults.yang', './cvlyang-models/sonic-interface.yang', './cvlyang-models/sonic-kdump.yang', + './cvlyang-models/sonic-kubernetes_master.yang', './cvlyang-models/sonic-loopback-interface.yang', './cvlyang-models/sonic-mgmt_interface.yang', './cvlyang-models/sonic-mgmt_port.yang', diff --git a/src/sonic-yang-models/tests/files/sample_config_db.json b/src/sonic-yang-models/tests/files/sample_config_db.json index 79110704046a..9dec93b52037 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -2062,6 +2062,14 @@ "nexthop": "10.184.229.212", "nexthop-vrf": "default" } + }, + "KUBERNETES_MASTER": { + "SERVER": { + "disable": "True", + "insecure": "False", + "ip": "kubernetes.apiserver.com", + "port": "6443" + } } }, "SAMPLE_CONFIG_DB_UNKNOWN": { diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/kubernetes_master.json b/src/sonic-yang-models/tests/yang_model_tests/tests/kubernetes_master.json new file mode 100644 index 000000000000..6518f425da16 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/kubernetes_master.json @@ -0,0 +1,27 @@ +{ + "KUBERNETES_MASTER_WITH_CORRECT_VALUES_IP": { + "desc": "CONFIG KUBERNETES_MASTER TABLE WITH ALL THE CORRECT VALUES" + }, + "KUBERNETES_MASTER_WITH_CORRECT_VALUES_DNS": { + "desc": "CONFIG KUBERNETES_MASTER TABLE WITH ALL THE CORRECT VALUES" + }, + "KUBERNETES_MASTER_WITH_INVALID_BOOLEAN_TYPE" : { + "desc": "Referring invalid kubernetes_master boolean types.", + "eStrKey": "Pattern", + "eStr": ["false|true|False|True"] + }, + "KUBERNETES_MASTER_INVALID_PORT": { + "desc": "Configure invalid PORT in kubernetes_master.", + "eStrKey": "InvalidValue" + }, + "KUBERNETES_MASTER_INVALID_IP" : { + "desc": "Configure invalid IP in kubernetes_master.", + "eStrKey": "InvalidValue", + "eStr": ["ip"] + }, + "KUBERNETES_MASTER_INVALID_DNS" : { + "desc": "Configure invalid DNS in kubernetes_master.", + "eStrKey": "InvalidValue", + "eStr": ["ip"] + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/kubernetes_master.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/kubernetes_master.json new file mode 100644 index 000000000000..096cea0ee365 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/kubernetes_master.json @@ -0,0 +1,74 @@ +{ + "KUBERNETES_MASTER_WITH_CORRECT_VALUES_IP": { + "sonic-kubernetes_master:sonic-kubernetes_master": { + "sonic-kubernetes_master:KUBERNETES_MASTER": { + "sonic-kubernetes_master:SERVER": { + "ip": "192.168.122.11", + "port": "6443", + "disable": "False", + "insecure": "True" + } + } + } + }, + "KUBERNETES_MASTER_WITH_CORRECT_VALUES_DNS": { + "sonic-kubernetes_master:sonic-kubernetes_master": { + "sonic-kubernetes_master:KUBERNETES_MASTER": { + "sonic-kubernetes_master:SERVER": { + "ip": "k8s.apiserver.com", + "port": "6443", + "disable": "False", + "insecure": "True" + } + } + } + }, + "KUBERNETES_MASTER_WITH_INVALID_BOOLEAN_TYPE": { + "sonic-kubernetes_master:sonic-kubernetes_master": { + "sonic-kubernetes_master:KUBERNETES_MASTER": { + "sonic-kubernetes_master:SERVER": { + "ip": "192.168.122.11", + "port": "6443", + "disable": "FAlse", + "insecure": "True" + } + } + } + }, + "KUBERNETES_MASTER_INVALID_PORT": { + "sonic-kubernetes_master:sonic-kubernetes_master": { + "sonic-kubernetes_master:KUBERNETES_MASTER": { + "sonic-kubernetes_master:SERVER": { + "ip": "192.168.122.11", + "port": "65536", + "disable": "False", + "insecure": "True" + } + } + } + }, + "KUBERNETES_MASTER_INVALID_IP": { + "sonic-kubernetes_master:sonic-kubernetes_master": { + "sonic-kubernetes_master:KUBERNETES_MASTER": { + "sonic-kubernetes_master:SERVER": { + "ip": "2001:aa:aa:aa", + "port": "6443", + "disable": "False", + "insecure": "True" + } + } + } + }, + "KUBERNETES_MASTER_INVALID_DNS": { + "sonic-kubernetes_master:sonic-kubernetes_master": { + "sonic-kubernetes_master:KUBERNETES_MASTER": { + "sonic-kubernetes_master:SERVER": { + "ip": "k8s@.apiserver.com", + "port": "6443", + "disable": "False", + "insecure": "True" + } + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-kubernetes_master.yang b/src/sonic-yang-models/yang-models/sonic-kubernetes_master.yang new file mode 100644 index 000000000000..6ac153c606d0 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-kubernetes_master.yang @@ -0,0 +1,62 @@ +module sonic-kubernetes_master { + + yang-version 1.1; + + namespace "http://github.com/Azure/sonic-kubernetes_master"; + prefix kubernetes_master; + + import ietf-inet-types { + prefix inet; + } + + import sonic-types { + prefix stypes; + } + + description "KUBERNETES_MASTER YANG Module for SONiC OS"; + + revision 2022-10-09 { + description "First Revision"; + } + + container sonic-kubernetes_master { + + container KUBERNETES_MASTER { + + description "KUBERNETES_MASTER part of config_db.json"; + + container SERVER { + + leaf ip { + description "Kubernetes api server endpoint(an IP address or a DNS + domain name.)"; + type inet:host; + } + + leaf port { + description "Kubernetes api server port"; + type inet:port-number; + default 6443; + } + + leaf disable { + description "This configuration identicates whether disable kubernetes"; + type stypes:boolean_type; + default "false"; + } + + leaf insecure { + description "This configuration identicates it will download kubernetes + CA by http other than https"; + type stypes:boolean_type; + default "true"; + } + + } + /* end of container SERVER */ + } + /* end of container KUBERNETES_MASTER */ + } + /* end of top level container */ +} +/* end of module sonic-kubernetes_master */