confd: add feature flag for containers

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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-02-25 19:49:27 +01:00
parent 235d3e46e6
commit 8ea159ce5d
11 changed files with 259 additions and 165 deletions
+6
View File
@@ -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
@@ -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)
+40
View File
@@ -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 <<EOF
------------------ Summary ------------------
$PACKAGE_NAME version $PACKAGE_VERSION
Prefix................: $prefix
Exec prefix...........: $eprefix
Sysconfdir............: `eval echo $sysconfdir`
Localstatedir.........: `eval echo $localstatedir`
Default fstab.........: `eval echo $fstab`
System environment....: ${sysconfig_path:-${sysconfig}}
C Compiler............: $CC $CFLAGS $CPPFLAGS $LDFLAGS $LIBS
Linker................: $LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS
Optional features:
Container support ....: $enable_containers
Login shell ..........: $login_shell
------------- Compiler version --------------
$($CC --version || true)
-------------- Linker version ---------------
$($LD --version || true)
---------------------------------------------
Check the above options and compile with:
${MAKE-make}
EOF
+4 -1
View File
@@ -29,13 +29,16 @@ confd_plugin_la_SOURCES = \
ietf-system.c \
ietf-factory-default.c \
ietf-routing.c \
infix-containers.c \
infix-dhcp.c \
infix-services.c \
infix-factory.c \
infix-system-software.c \
ietf-hardware.c
if CONTAINERS
confd_plugin_la_SOURCES += infix-containers.c
endif
rauc_installer_sources = \
rauc-installer.c rauc-installer.h
+4
View File
@@ -1584,6 +1584,10 @@ int ietf_interfaces_init(struct confd *confd)
{
int rc = 0;
#ifdef CONTAINERS
sr_enable_module_feature(confd->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//.",
@@ -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 {
@@ -46,6 +46,14 @@ module infix-interfaces {
reference "internal";
}
/*
* Features
*/
feature containers {
description "Containers is an optional build-time feature in Infix.";
}
/*
* Data Nodes
*/
+10
View File
@@ -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}'
+6 -2
View File
@@ -1,2 +1,6 @@
klishconfdir = $(KLISHCONFDIR)
klishconf_DATA = $(wildcard *.xml)
klishconfdir = $(KLISHCONFDIR)
klishconf_DATA = infix.xml
if CONTAINERS
klishconf_DATA += containers.xml
endif
+174
View File
@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8"?>
<KLISH
xmlns="https://klish.libcode.org/klish3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://src.libcode.org/pkun/klish/src/master/klish.xsd">
<PTYPE name="CONTAINERS">
<COMPL>
<ACTION sym="script">container list</ACTION>
</COMPL>
<ACTION sym="STRING"/>
</PTYPE>
<PTYPE name="CONTAINERSa">
<COMPL>
<ACTION sym="script">container -a list</ACTION>
</COMPL>
<ACTION sym="STRING"/>
</PTYPE>
<PTYPE name="IMAGES">
<COMPL>
<ACTION sym="script">container -a list images</ACTION>
</COMPL>
<ACTION sym="STRING"/>
</PTYPE>
<VIEW name="main">
<COMMAND name="container" help="Manage containers, images, and volumes" mode="switch">
<COMMAND name="cleanup" help="Clean up all unused containers, images and volume data">
<ACTION sym="script" in="tty" out="tty" interrupt="true">
podman system prune
</ACTION>
</COMMAND>
<!-- alias for -container shell' -->
<COMMAND name="connect" help="Start a shell inside a container, if available">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" in="tty" out="tty" interrupt="true">
container shell $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="exec" help="Execute command in a running container, default: sh">
<PARAM name="name" ptype="/CONTAINERS" help="Container name" />
<SWITCH name="optional" min="0">
<COMMAND name="command" help="Command to run">
<PARAM name="command" ptype="/STRING" help="Command to run"/>
</COMMAND>
</SWITCH>
<ACTION sym="script" in="tty" out="tty" interrupt="true">
if [ -z "$KLISH_PARAM_name" ]; then
echo "Missing container name."
else
cmd=${KLISH_PARAM_command:-sh}
container exec $KLISH_PARAM_name $cmd
fi
</ACTION>
</COMMAND>
<COMMAND name="pull" help="Fetch a container image">
<PARAM name="image" ptype="/STRING" help="Image url and tag, e.g. docker://hello-world:latest" />
<SWITCH name="optional" min="0">
<COMMAND name="creds" help="Credentials">
<PARAM name="creds" ptype="/STRING" help="username[:password]"/>
</COMMAND>
</SWITCH>
<ACTION sym="script" in="tty" out="tty" interrupt="true">
creds=${KLISH_PARAM_creds:+--creds=$KLISH_PARAM_creds}
container pull $creds $KLISH_PARAM_image
</ACTION>
</COMMAND>
<COMMAND name="remove" help="Remove a container image from local storage">
<PARAM name="name" ptype="/IMAGES" help="Image name" />
<ACTION sym="script" in="tty" out="tty" interrupt="true">
container remove $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="restart" help="Restart a crashed container">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" out="tty" interrupt="true">
container restart $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="run" help="Interactivly run a container image, with optional command">
<PARAM name="image" ptype="/IMAGES" help="Image name" />
<SWITCH name="optional" min="0">
<COMMAND name="command" help="Command to run">
<PARAM name="command" ptype="/STRING" help="Command to run"/>
</COMMAND>
<COMMAND name="port" help="Port to publish, default all exposed">
<PARAM name="port" ptype="/STRING" help="HOST:CONTAINER[/udp]"/>
</COMMAND>
</SWITCH>
<ACTION sym="script" in="tty" out="tty" interrupt="true">
port=${KLISH_PARAM_port:+-p $KLISH_PARAM_port}
container $port run $KLISH_PARAM_image ${KLISH_PARAM_command}
</ACTION>
<SWITCH name="optional" min="0">
<COMMAND name="detach" help="Run container in background and print container ID">
<ACTION sym="script" out="tty">
container -d $port run $KLISH_PARAM_image ${KLISH_PARAM_command}
</ACTION>
</COMMAND>
</SWITCH>
</COMMAND>
<COMMAND name="shell" help="Start a shell inside a container, if available">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" in="tty" out="tty" interrupt="true">
container shell $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="start" help="Start a container">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" out="tty" interrupt="true">
container start $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="stop" help="Stop a container">
<PARAM name="name" ptype="/CONTAINERS" help="Container name" />
<ACTION sym="script" out="tty" interrupt="true">
container stop $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="upgrade" help="Upgrade image of a container (writable layer is lost!)">
<PARAM name="name" ptype="/CONTAINERS" help="Container name" />
<ACTION sym="script" out="tty" interrupt="true">
container upgrade $KLISH_PARAM_name
</ACTION>
</COMMAND>
</COMMAND>
<COMMAND name="show" help="Show system status and configuration files" mode="switch">
<COMMAND name="container" help="Show container status">
<ACTION sym="script">container show</ACTION>
<SWITCH name="optional" min="0">
<COMMAND name="all" help="Show all containers (default only running)">
<ACTION sym="script">container -a show</ACTION>
</COMMAND>
<COMMAND name="log" help="Show container log (alias for show log container)">
<ACTION sym="script">cat /log/container</ACTION>
</COMMAND>
<COMMAND name="images" help="Show container images">
<ACTION sym="script">container show images</ACTION>
<SWITCH name="optional" min="0">
<COMMAND name="all" help="All images (default hides intermediate imaages)">
<ACTION sym="script">container -a show images</ACTION>
</COMMAND>
</SWITCH>
</COMMAND>
<COMMAND name="stat" help="Show continuous containers stats (Ctrl-C aborts)">
<ACTION sym="script">container stat</ACTION>
</COMMAND>
<COMMAND name="usage" help="Show container resource usage">
<ACTION sym="script">podman system df -v</ACTION>
</COMMAND>
<COMMAND name="volumes" help="Show container volumes">
<ACTION sym="script">container show volumes</ACTION>
</COMMAND>
</SWITCH>
</COMMAND>
</COMMAND>
</VIEW>
</KLISH>
-162
View File
@@ -113,27 +113,6 @@
<ACTION sym="STRING"/>
</PTYPE>
<PTYPE name="CONTAINERS">
<COMPL>
<ACTION sym="script">container list</ACTION>
</COMPL>
<ACTION sym="STRING"/>
</PTYPE>
<PTYPE name="CONTAINERSa">
<COMPL>
<ACTION sym="script">container -a list</ACTION>
</COMPL>
<ACTION sym="STRING"/>
</PTYPE>
<PTYPE name="IMAGES">
<COMPL>
<ACTION sym="script">container -a list images</ACTION>
</COMPL>
<ACTION sym="STRING"/>
</PTYPE>
<VIEW name="main">
<HOTKEY key="^D" cmd="exit"/>
@@ -183,117 +162,6 @@
<ACTION sym="nav">replace config</ACTION>
</COMMAND>
<COMMAND name="container" help="Manage containers, images, and volumes" mode="switch">
<COMMAND name="cleanup" help="Clean up all unused containers, images and volume data">
<ACTION sym="script" in="tty" out="tty" interrupt="true">
podman system prune
</ACTION>
</COMMAND>
<!-- alias for -container shell' -->
<COMMAND name="connect" help="Start a shell inside a container, if available">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" in="tty" out="tty" interrupt="true">
container shell $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="exec" help="Execute command in a running container, default: sh">
<PARAM name="name" ptype="/CONTAINERS" help="Container name" />
<SWITCH name="optional" min="0">
<COMMAND name="command" help="Command to run">
<PARAM name="command" ptype="/STRING" help="Command to run"/>
</COMMAND>
</SWITCH>
<ACTION sym="script" in="tty" out="tty" interrupt="true">
if [ -z "$KLISH_PARAM_name" ]; then
echo "Missing container name."
else
cmd=${KLISH_PARAM_command:-sh}
container exec $KLISH_PARAM_name $cmd
fi
</ACTION>
</COMMAND>
<COMMAND name="pull" help="Fetch a container image">
<PARAM name="image" ptype="/STRING" help="Image url and tag, e.g. docker://hello-world:latest" />
<SWITCH name="optional" min="0">
<COMMAND name="creds" help="Credentials">
<PARAM name="creds" ptype="/STRING" help="username[:password]"/>
</COMMAND>
</SWITCH>
<ACTION sym="script" in="tty" out="tty" interrupt="true">
creds=${KLISH_PARAM_creds:+--creds=$KLISH_PARAM_creds}
container pull $creds $KLISH_PARAM_image
</ACTION>
</COMMAND>
<COMMAND name="remove" help="Remove a container image from local storage">
<PARAM name="name" ptype="/IMAGES" help="Image name" />
<ACTION sym="script" in="tty" out="tty" interrupt="true">
container remove $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="restart" help="Restart a crashed container">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" out="tty" interrupt="true">
container restart $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="run" help="Interactivly run a container image, with optional command">
<PARAM name="image" ptype="/IMAGES" help="Image name" />
<SWITCH name="optional" min="0">
<COMMAND name="command" help="Command to run">
<PARAM name="command" ptype="/STRING" help="Command to run"/>
</COMMAND>
<COMMAND name="port" help="Port to publish, default all exposed">
<PARAM name="port" ptype="/STRING" help="HOST:CONTAINER[/udp]"/>
</COMMAND>
</SWITCH>
<ACTION sym="script" in="tty" out="tty" interrupt="true">
port=${KLISH_PARAM_port:+-p $KLISH_PARAM_port}
container $port run $KLISH_PARAM_image ${KLISH_PARAM_command}
</ACTION>
<SWITCH name="optional" min="0">
<COMMAND name="detach" help="Run container in background and print container ID">
<ACTION sym="script" out="tty">
container -d $port run $KLISH_PARAM_image ${KLISH_PARAM_command}
</ACTION>
</COMMAND>
</SWITCH>
</COMMAND>
<COMMAND name="shell" help="Start a shell inside a container, if available">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" in="tty" out="tty" interrupt="true">
container shell $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="start" help="Start a container">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" out="tty" interrupt="true">
container start $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="stop" help="Stop a container">
<PARAM name="name" ptype="/CONTAINERS" help="Container name" />
<ACTION sym="script" out="tty" interrupt="true">
container stop $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="upgrade" help="Upgrade image of a container (writable layer is lost!)">
<PARAM name="name" ptype="/CONTAINERS" help="Container name" />
<ACTION sym="script" out="tty" interrupt="true">
container upgrade $KLISH_PARAM_name
</ACTION>
</COMMAND>
</COMMAND>
<COMMAND name="copy" help="Copy configuration, e.g., copy running-config startup-config">
<PARAM name="src" ptype="/DATASTORE" help="Source datastore"/>
<PARAM name="dst" ptype="/RW_DATASTORE" help="Destination datastore"/>
@@ -373,36 +241,6 @@
</SWITCH>
</COMMAND>
<COMMAND name="container" help="Show container status">
<ACTION sym="script">container show</ACTION>
<SWITCH name="optional" min="0">
<COMMAND name="all" help="Show all containers (default only running)">
<ACTION sym="script">container -a show</ACTION>
</COMMAND>
<COMMAND name="log" help="Show container log (alias for show log container)">
<ACTION sym="script">cat /log/container</ACTION>
</COMMAND>
<COMMAND name="images" help="Show container images">
<ACTION sym="script">container show images</ACTION>
<SWITCH name="optional" min="0">
<COMMAND name="all" help="All images (default hides intermediate imaages)">
<ACTION sym="script">container -a show images</ACTION>
</COMMAND>
</SWITCH>
</COMMAND>
<COMMAND name="stat" help="Show continuous containers stats (Ctrl-C aborts)">
<ACTION sym="script">container stat</ACTION>
</COMMAND>
<COMMAND name="usage" help="Show container resource usage">
<ACTION sym="script">podman system df -v</ACTION>
</COMMAND>
<COMMAND name="volumes" help="Show container volumes">
<ACTION sym="script">container show volumes</ACTION>
</COMMAND>
</SWITCH>
</COMMAND>
<COMMAND name="datetime" help="Show current date and time, default RFC2822 format">
<ACTION sym="script">date -R</ACTION>
<SWITCH name="optional" min="0">