From 219118a513b1a6904debb79a590a535215381f4e Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Tue, 24 Jan 2023 23:26:04 +0000 Subject: [PATCH] Support for specifying the CNI plugin version (#13) Required to build newer versions of Kubernetes whose packages have a dependency on a newer version of the CNI plugins package. --- README.md | 5 +++-- cmd/build.go | 2 ++ cmd/flags.go | 1 + pkg/openstack/config.go | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 53ffba3..3cddec6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Baskio - Build And Scan Kubernetes Images Openstack +# Baskio - Build And Scan Kubernetes Images OpenStack A binary for building and scanning (with [Trivy](https://github.com/aquasecurity/trivy)) a Kubernetes image using the [eschercloud-image-builder](https://github.com/eschercloudai/image-builder) repo. @@ -33,7 +33,7 @@ openstack security group rule create "${OS_SG}" --egress --ethertype IPv4 --prot # Usage Simply run the binary with the following flags (minimum required). See the example below. You will also require a source image to reference for the build to succeed. -You must supply a clouds.yaml file for Openstack connectivity. +You must supply a clouds.yaml file for OpenStack connectivity. ```yaml clouds-file: "~/.config/openstack/clouds.yaml" @@ -49,6 +49,7 @@ build: floating-ip-network-name: "Internet" image-visibility: "private" crictl-version: "1.25.0" + cni-version: "1.1.1" kubernetes-version: "1.25.3" extra-debs: "nfs-common" enable-nvidia-support: false diff --git a/cmd/build.go b/cmd/build.go index afd7924..5c6ae41 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -89,6 +89,7 @@ To use baskio to build an image, an Openstack cluster is required.`, cmd.Flags().BoolVar(&userFloatingIPFlag, "use-floating-ip", true, "Whether to use a floating IP for the instance") cmd.Flags().StringVar(&floatingIPNetworkNameFlag, "floating-ip-network-name", "Internet", "The Name of the network in which to create the floating ip") cmd.Flags().StringVar(&imageVisibilityFlag, "image-visibility", "private", "Change the image visibility in Openstack - you need to ensure the use you're authenticating with has permissions to do so or this will fail") + cmd.Flags().StringVar(&cniVersionFlag, "cni-version", "1.1.1", "The CNI plugins version to include to the built image") cmd.Flags().StringVar(&crictlVersionFlag, "crictl-version", "1.25.0", "The crictl-tools version to add to the built image") cmd.Flags().StringVar(&kubeVersionFlag, "kubernetes-version", "1.25.3", "The Kubernetes version to add to the built image") cmd.Flags().StringVar(&extraDebsFlag, "extra-debs", "", "A space-seperated list of any extra (Debian / Ubuntu) packages that should be installed") @@ -112,6 +113,7 @@ To use baskio to build an image, an Openstack cluster is required.`, bindViper(cmd, "build.use-floating-ip", "use-floating-ip") bindViper(cmd, "build.floating-ip-network-name", "floating-ip-network-name") bindViper(cmd, "build.image-visibility", "image-visibility") + bindViper(cmd, "build.cni-version", "cni-version") bindViper(cmd, "build.crictl-version", "crictl-version") bindViper(cmd, "build.kubernetes-version", "kubernetes-version") bindViper(cmd, "build.extra-debs", "extra-debs") diff --git a/cmd/flags.go b/cmd/flags.go index f5c4a4b..aae0add 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -17,6 +17,7 @@ var ( floatingIPNetworkNameFlag string attachConfigDriveFlag bool imageVisibilityFlag string + cniVersionFlag string crictlVersionFlag string kubeVersionFlag string extraDebsFlag string diff --git a/pkg/openstack/config.go b/pkg/openstack/config.go index e9fe338..4b27f2c 100644 --- a/pkg/openstack/config.go +++ b/pkg/openstack/config.go @@ -66,6 +66,8 @@ type PackerBuildConfig struct { AttachConfigDrive string `json:"attach_config_drive,omitempty"` UseFloatingIp string `json:"use_floating_ip,omitempty"` FloatingIpNetwork string `json:"floating_ip_network,omitempty"` + CniVersion string `json:"kubernetes_cni_semver,omitempty"` + CniDebVersion string `json:"kubernetes_cni_deb_version,omitempty"` CrictlVersion string `json:"crictl_version,omitempty"` ImageVisibility string `json:"image_visibility,omitempty"` KubernetesSemver string `json:"kubernetes_semver,omitempty"` @@ -129,6 +131,8 @@ func buildConfigFromInputs() *PackerBuildConfig { AttachConfigDrive: strconv.FormatBool(viper.GetBool("build.attach-config-drive")), UseFloatingIp: strconv.FormatBool(viper.GetBool("build.use-floating-ip")), FloatingIpNetwork: viper.GetString("build.floating-ip-network-name"), + CniVersion: "v" + viper.GetString("build.cni-version"), + CniDebVersion: viper.GetString("build.cni-version") + "-00", CrictlVersion: viper.GetString("build.crictl-version"), ImageVisibility: viper.GetString("build.image-visibility"), KubernetesSemver: "v" + viper.GetString("build.kubernetes-version"),