From 8ea159ce5dfa1d70e29b49cee07eac6b9dd49732 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 4 Feb 2024 05:39:34 +0100 Subject: [PATCH] confd: add feature flag for containers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not all customers want Container support in their Ínfix builds. This patch adds build-time support for detecting if podman is enabled in the configuration. - Klish container commands have been broken out to their own xml file - infix-interfaces have been given a 'containers' feature - ietf-interfces.c enables 'containers' feature on an #ifdef - infix-container.c is only built if --enable-containers Signed-off-by: Joachim Wiberg --- package/confd/confd.mk | 6 + .../klish-plugin-infix/klish-plugin-infix.mk | 6 + src/confd/configure.ac | 40 ++++ src/confd/src/Makefile.am | 5 +- src/confd/src/ietf-interfaces.c | 4 + .../yang/infix-if-container@2024-01-15.yang | 1 + .../yang/infix-interfaces@2024-01-15.yang | 8 + src/klish-plugin-infix/configure.ac | 10 + src/klish-plugin-infix/xml/Makefile.am | 8 +- src/klish-plugin-infix/xml/containers.xml | 174 ++++++++++++++++++ src/klish-plugin-infix/xml/infix.xml | 162 ---------------- 11 files changed, 259 insertions(+), 165 deletions(-) create mode 100644 src/klish-plugin-infix/xml/containers.xml diff --git a/package/confd/confd.mk b/package/confd/confd.mk index 1fb2abf6..2b20562a 100644 --- a/package/confd/confd.mk +++ b/package/confd/confd.mk @@ -17,6 +17,12 @@ define CONFD_CONF_ENV CFLAGS="$(INFIX_CFLAGS)" endef +ifeq ($(BR2_PACKAGE_PODMAN),y) +CONFD_CONF_OPTS += --enable-containers +else +CONFD_CONF_OPTS += --disable-containers +endif + define CONFD_INSTALL_EXTRA cp $(CONFD_PKGDIR)/confd.conf $(FINIT_D)/available/ ln -sf ../available/confd.conf $(FINIT_D)/enabled/confd.conf diff --git a/package/klish-plugin-infix/klish-plugin-infix.mk b/package/klish-plugin-infix/klish-plugin-infix.mk index d42caabc..2a2d57ca 100644 --- a/package/klish-plugin-infix/klish-plugin-infix.mk +++ b/package/klish-plugin-infix/klish-plugin-infix.mk @@ -17,6 +17,12 @@ define KLISH_PLUGIN_INFIX_CONF_ENV CFLAGS="$(INFIX_CFLAGS)" endef +ifeq ($(BR2_PACKAGE_PODMAN),y) +KLISH_PLUGIN_INFIX_CONF_OPTS += --enable-containers +else +KLISH_PLUGIN_INFIX_CONF_OPTS += --disable-containers +endif + define KLISH_PLUGIN_INFIX_INSTALL_DOC $(INSTALL) -t $(TARGET_DIR)/usr/share/infix/cli -D -m 0644 \ $(wildcard $(BR2_EXTERNAL_INFIX_PATH)/doc/cli/*.md) diff --git a/src/confd/configure.ac b/src/confd/configure.ac index b601f155..6fc59380 100644 --- a/src/confd/configure.ac +++ b/src/confd/configure.ac @@ -21,11 +21,20 @@ AC_CONFIG_LIBOBJ_DIR(lib) AC_REPLACE_FUNCS(vasprintf) AC_REPLACE_FUNCS(asprintf) +# # Check feature flags +# +AC_ARG_ENABLE(containers, + AS_HELP_STRING([--enable-containers], [Enable support for containers]),,[ + enable_containers=no]) + AC_ARG_WITH(login-shell, AS_HELP_STRING([--with-login-shell=shell], [Login shell for new users, default: /bin/false]), [login_shell=$withval], [login_shell=yes]) +AS_IF([test "x$enable_containers" = "xyes"], [ + AC_DEFINE(CONTAINERS, 1, [Built with container support])]) + AS_IF([test "x$with_login_shell" != "xno"], [ AS_IF([test "x$login_shell" = "xyes"], [login_shell=/bin/false]) AC_DEFINE_UNQUOTED(LOGIN_SHELL, "$login_shell", [Default: /bin/false])],[ @@ -41,6 +50,9 @@ PKG_CHECK_MODULES([libite], [libite >= 2.5.0]) PKG_CHECK_MODULES([sysrepo], [sysrepo >= 2.2.36]) PKG_CHECK_MODULES([libsrx], [libsrx >= 1.0.0]) +# Control build with automake flags +AM_CONDITIONAL(CONTAINERS, [test "x$enable_containers" != "xno"]) + # Plugin installation path for sysrepo-plugind PKG_CHECK_VAR([srpdplugindir], [sysrepo], [SRPD_PLUGINS_PATH]) AC_SUBST(srpdplugindir) @@ -72,3 +84,31 @@ SYSCONFDIR=`eval echo $SYSCONFDIR` AC_SUBST(SYSCONFDIR) AC_OUTPUT + +cat <conn, "infix-interfaces", "containers"); +#endif + REGISTER_CHANGE(confd->session, "ietf-interfaces", "/ietf-interfaces:interfaces//.", 0, ifchange, confd, &confd->sub); REGISTER_CHANGE(confd->cand, "ietf-interfaces", "/ietf-interfaces:interfaces//.", diff --git a/src/confd/yang/infix-if-container@2024-01-15.yang b/src/confd/yang/infix-if-container@2024-01-15.yang index 10c7547c..f39d48ec 100644 --- a/src/confd/yang/infix-if-container@2024-01-15.yang +++ b/src/confd/yang/infix-if-container@2024-01-15.yang @@ -49,6 +49,7 @@ submodule infix-if-container { augment "/if:interfaces/if:interface/infix-if:port" { description "Augments the interface model with CNI networks."; + if-feature containers; case container-network { container container-network { diff --git a/src/confd/yang/infix-interfaces@2024-01-15.yang b/src/confd/yang/infix-interfaces@2024-01-15.yang index 5aaf3d44..3b042e3e 100644 --- a/src/confd/yang/infix-interfaces@2024-01-15.yang +++ b/src/confd/yang/infix-interfaces@2024-01-15.yang @@ -46,6 +46,14 @@ module infix-interfaces { reference "internal"; } + /* + * Features + */ + + feature containers { + description "Containers is an optional build-time feature in Infix."; + } + /* * Data Nodes */ diff --git a/src/klish-plugin-infix/configure.ac b/src/klish-plugin-infix/configure.ac index e25df3ba..cb39f115 100644 --- a/src/klish-plugin-infix/configure.ac +++ b/src/klish-plugin-infix/configure.ac @@ -15,6 +15,13 @@ AC_CONFIG_FILES([ AC_PROG_CC AC_PROG_INSTALL +# +# Check feature flags +# +AC_ARG_ENABLE(containers, + AS_HELP_STRING([--enable-containers], [Enable support for containers]),,[ + enable_containers=no]) + # Check for pkg-config first, warn if it's not installed PKG_PROG_PKG_CONFIG @@ -22,6 +29,9 @@ PKG_CHECK_MODULES([sysrepo], [sysrepo >= 2.2.60]) PKG_CHECK_MODULES([libyang], [libyang >= 2.1.80]) AC_CHECK_LIB([klish], [kplugin_new],, AC_MSG_ERROR([Klish not found])) +# Control build with automake flags +AM_CONDITIONAL(CONTAINERS, [test "x$enable_containers" != "xno"]) + test "x$prefix" = xNONE && prefix=$ac_default_prefix test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' diff --git a/src/klish-plugin-infix/xml/Makefile.am b/src/klish-plugin-infix/xml/Makefile.am index 1bd6bfa9..33eab011 100644 --- a/src/klish-plugin-infix/xml/Makefile.am +++ b/src/klish-plugin-infix/xml/Makefile.am @@ -1,2 +1,6 @@ -klishconfdir = $(KLISHCONFDIR) -klishconf_DATA = $(wildcard *.xml) +klishconfdir = $(KLISHCONFDIR) +klishconf_DATA = infix.xml + +if CONTAINERS +klishconf_DATA += containers.xml +endif diff --git a/src/klish-plugin-infix/xml/containers.xml b/src/klish-plugin-infix/xml/containers.xml new file mode 100644 index 00000000..b4f587b0 --- /dev/null +++ b/src/klish-plugin-infix/xml/containers.xml @@ -0,0 +1,174 @@ + + + + + + container list + + + + + + + container -a list + + + + + + + container -a list images + + + + + + + + + + podman system prune + + + + + + + + container shell $KLISH_PARAM_name + + + + + + + + + + + + if [ -z "$KLISH_PARAM_name" ]; then + echo "Missing container name." + else + cmd=${KLISH_PARAM_command:-sh} + container exec $KLISH_PARAM_name $cmd + fi + + + + + + + + + + + + creds=${KLISH_PARAM_creds:+--creds=$KLISH_PARAM_creds} + container pull $creds $KLISH_PARAM_image + + + + + + + container remove $KLISH_PARAM_name + + + + + + + container restart $KLISH_PARAM_name + + + + + + + + + + + + + + + port=${KLISH_PARAM_port:+-p $KLISH_PARAM_port} + container $port run $KLISH_PARAM_image ${KLISH_PARAM_command} + + + + + container -d $port run $KLISH_PARAM_image ${KLISH_PARAM_command} + + + + + + + + + container shell $KLISH_PARAM_name + + + + + + + container start $KLISH_PARAM_name + + + + + + + container stop $KLISH_PARAM_name + + + + + + + container upgrade $KLISH_PARAM_name + + + + + + + container show + + + + container -a show + + + cat /log/container + + + container show images + + + container -a show images + + + + + container stat + + + podman system df -v + + + container show volumes + + + + + + + diff --git a/src/klish-plugin-infix/xml/infix.xml b/src/klish-plugin-infix/xml/infix.xml index 06c047cf..007604bf 100644 --- a/src/klish-plugin-infix/xml/infix.xml +++ b/src/klish-plugin-infix/xml/infix.xml @@ -113,27 +113,6 @@ - - - container list - - - - - - - container -a list - - - - - - - container -a list images - - - - @@ -183,117 +162,6 @@ replace config - - - - podman system prune - - - - - - - - container shell $KLISH_PARAM_name - - - - - - - - - - - - if [ -z "$KLISH_PARAM_name" ]; then - echo "Missing container name." - else - cmd=${KLISH_PARAM_command:-sh} - container exec $KLISH_PARAM_name $cmd - fi - - - - - - - - - - - - creds=${KLISH_PARAM_creds:+--creds=$KLISH_PARAM_creds} - container pull $creds $KLISH_PARAM_image - - - - - - - container remove $KLISH_PARAM_name - - - - - - - container restart $KLISH_PARAM_name - - - - - - - - - - - - - - - port=${KLISH_PARAM_port:+-p $KLISH_PARAM_port} - container $port run $KLISH_PARAM_image ${KLISH_PARAM_command} - - - - - container -d $port run $KLISH_PARAM_image ${KLISH_PARAM_command} - - - - - - - - - container shell $KLISH_PARAM_name - - - - - - - container start $KLISH_PARAM_name - - - - - - - container stop $KLISH_PARAM_name - - - - - - - container upgrade $KLISH_PARAM_name - - - - @@ -373,36 +241,6 @@ - - container show - - - - container -a show - - - cat /log/container - - - container show images - - - container -a show images - - - - - container stat - - - podman system df -v - - - container show volumes - - - - date -R