From 788501e8066894685f93ea470164f46037c1cbb2 Mon Sep 17 00:00:00 2001 From: Phil Sphicas Date: Sat, 4 Jan 2020 23:05:49 -0800 Subject: [PATCH] apt: chart update: allow conf.apt.packages as map This change allows conf.apt.packages to be defined as a map of lists, allowing for logical grouping and easier substitution when values.yaml is being assembled from multiple sources. The existing format (conf.apt.packages as a list) is still supported. Change-Id: I4d4c09723b2e9ac1f0ecf847e786d991cc6e669a --- divingbell/templates/bin/_apt.sh.tpl | 16 ++++++++++-- doc/source/index.rst | 31 +++++++++++++++++++++++ tools/gate/scripts/020-test-divingbell.sh | 23 ++++++++++++++--- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/divingbell/templates/bin/_apt.sh.tpl b/divingbell/templates/bin/_apt.sh.tpl index e9b69e9..f4bb273 100644 --- a/divingbell/templates/bin/_apt.sh.tpl +++ b/divingbell/templates/bin/_apt.sh.tpl @@ -90,8 +90,20 @@ apt-get update {{- if hasKey .Values.conf.apt "packages" }} apt-get update +{{/* Build a unified list of packages */}} +{{- $all_apt_packages := list }} +{{- if kindIs "map" .Values.conf.apt.packages }} +{{- range $k, $v := .Values.conf.apt.packages }} +{{- range $v }} +{{- $all_apt_packages = . | append $all_apt_packages }} +{{- end }} +{{- end }} +{{- else }} +{{- $all_apt_packages = .Values.conf.apt.packages }} +{{- end -}} + # Set all debconf selections up front -{{- range .Values.conf.apt.packages }} +{{- range $all_apt_packages }} {{- $pkg_name := .name }} {{- range .debconf }} debconf-set-selections <<< "{{ $pkg_name }} {{ .question }} {{ .question_type }} {{ .answer }}" @@ -102,7 +114,7 @@ apt-get update dpkg --configure -a # Perform package installs -{{- range .Values.conf.apt.packages }} +{{- range $all_apt_packages }} {{- $pkg_name := .name }} if [[ "${CURRENT_PACKAGES[{{ .name | squote }}]+isset}" != "isset"{{- if .version }} || "${CURRENT_PACKAGES[{{ .name | squote }}]}" != {{ .version }}{{- end }} ]]; then # Run this in case some package installation was interrupted diff --git a/doc/source/index.rst b/doc/source/index.rst index cec486e..db2f200 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -124,6 +124,37 @@ Here is an example configuration for it:: allow_downgrade: true - name: +It is also permissible to use ``conf.apt.packages`` as a map, in which case all +the packages from the different groups will be installed. This is primary useful +for logical organization. The keys of the map are ignored, and the values are a +list of the same format as the packages list above. No deduplication or other +processing is performed, just a simple concatenation (without any ordering +guarantees). For example:: + + conf: + apt: + packages: + group1: + - name: + version: + allow_downgrade: true + - name: + group2: + - name: + - name: + +Is equivalent to:: + + conf: + apt: + packages: + - name: + version: + allow_downgrade: true + - name: + - name: + - name: + There is a possibility to blacklist packages, e.g. ``telnetd`` and ``nis``:: conf: diff --git a/tools/gate/scripts/020-test-divingbell.sh b/tools/gate/scripts/020-test-divingbell.sh index b07c400..58506a8 100755 --- a/tools/gate/scripts/020-test-divingbell.sh +++ b/tools/gate/scripts/020-test-divingbell.sh @@ -79,6 +79,8 @@ APT_VERSION3="$(apt-cache show $APT_PACKAGE3 | grep Version: | tail -1 | awk '{p APT_PACKAGE4=less APT_PACKAGE5=python-setuptools APT_PACKAGE6=telnetd +APT_PACKAGE7=sudoku +APT_PACKAGE8=ninvaders APT_REPOSITORY1="http://us.archive.ubuntu.com/ubuntu/" APT_DISTRIBUTIONS1="[ xenial ]" APT_COMPONENTS1="[ main, universe, restricted, multiverse ]" @@ -1281,7 +1283,7 @@ test_apt(){ echo '[SUCCESS] apt test5 passed successfully' >> "${TEST_RESULTS}" # Test blacklistpkgs - local overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set1.yaml + local overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set5.yaml echo "conf: apt: packages: @@ -1294,7 +1296,7 @@ test_apt(){ echo '[SUCCESS] apt test6 passed successfully' >> "${TEST_RESULTS}" # Test add several repositories with gpg keys - local overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set5.yaml + local overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set6.yaml echo "conf: apt: repositories: @@ -1326,7 +1328,7 @@ $(printf '%s' "$APT_GPGKEY3" | awk '{printf " %s\n", $0}')" > "${overri echo '[SUCCESS] apt test7 passed successfully' >> "${TEST_RESULTS}" # Test add same gpg key two times - local overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set6.yaml + local overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set7.yaml echo "conf: apt: repositories: @@ -1349,6 +1351,21 @@ $(printf '%s' "$APT_GPGKEY1" | awk '{printf " %s\n", $0}')" > "${overri _test_apt_repositories "$APT_REPOSITORY1 $APT_REPOSITORY2" _test_apt_keys "$APT_GPGKEYID1" echo '[SUCCESS] apt test8 passed successfully' >> "${TEST_RESULTS}" + + # Test groups of packages using a map + local overrides_yaml=${LOGS_SUBDIR}/${FUNCNAME}-set8.yaml + echo "conf: + apt: + packages: + fun: + - name: $APT_PACKAGE7 + funner: + - name: $APT_PACKAGE8" > "${overrides_yaml}" + install_base "--values=${overrides_yaml}" + get_container_status apt + _test_apt_package_version $APT_PACKAGE7 any + _test_apt_package_version $APT_PACKAGE8 any + echo '[SUCCESS] apt test9 passed successfully' >> "${TEST_RESULTS}" } # test exec module