From efc4e2cd0113eb780b98754df4012e4b77e2f89f Mon Sep 17 00:00:00 2001 From: Paul Johnston Date: Wed, 23 Mar 2022 16:30:59 -0700 Subject: [PATCH] Make multitenant configs plumb-able in cni manager --- tools/acncli/api/constants.go | 58 ++++++++++++++++++------------ tools/acncli/cmd/cni/install.go | 8 +++-- tools/acncli/cmd/install.go | 8 +++-- tools/acncli/installer/conflist.go | 6 ++++ tools/acncli/installer/install.go | 20 ++++++----- 5 files changed, 64 insertions(+), 36 deletions(-) diff --git a/tools/acncli/api/constants.go b/tools/acncli/api/constants.go index 731e1f34d9..2ba4aa1140 100644 --- a/tools/acncli/api/constants.go +++ b/tools/acncli/api/constants.go @@ -33,6 +33,10 @@ const ( Singletenancy = "singletenancy" Multitenancy = "multitenancy" + // Multitenant Config flags + FlagCNSUrl = "cnsurl" + FlagEnableExactMatchForPodName = "enableexactmatchforpodname" + // os flags Linux = "linux" Windows = "windows" @@ -66,35 +70,43 @@ const ( Transparent = "transparent" Bridge = "bridge" Azure0 = "azure0" + + // Multitenancy defaults + DefaultCNSUrl = "http://localhost:10090" + DefaultEnableExactMatchForPodName = "false" ) var ( // Concatenating flags to the env ensures consistency between flags and env's for viper and cobra - EnvCNIOS = EnvPrefix + "_" + strings.ToUpper(FlagOS) - EnvCNIType = EnvPrefix + "_" + strings.ToUpper(FlagTenancy) - EnvCNISourceDir = EnvPrefix + "_" + "SRC_DIR" - EnvCNIDestinationBinDir = EnvPrefix + "_" + "BIN_DIR" - EnvCNIDestinationConflistDir = EnvPrefix + "_" + "CONFLIST_DIR" - EnvCNIIPAMType = EnvPrefix + "_" + strings.ToUpper(FlagIPAM) - EnvCNIMode = EnvPrefix + "_" + strings.ToUpper(FlagMode) - EnvCNIExemptBins = EnvPrefix + "_" + strings.ToUpper(FlagExempt) - EnvCNILogFile = EnvPrefix + "_" + "LOG_FILE" + EnvCNIOS = EnvPrefix + "_" + strings.ToUpper(FlagOS) + EnvCNIType = EnvPrefix + "_" + strings.ToUpper(FlagTenancy) + EnvCNISourceDir = EnvPrefix + "_" + "SRC_DIR" + EnvCNIDestinationBinDir = EnvPrefix + "_" + "BIN_DIR" + EnvCNIDestinationConflistDir = EnvPrefix + "_" + "CONFLIST_DIR" + EnvCNIIPAMType = EnvPrefix + "_" + strings.ToUpper(FlagIPAM) + EnvCNIMode = EnvPrefix + "_" + strings.ToUpper(FlagMode) + EnvCNIExemptBins = EnvPrefix + "_" + strings.ToUpper(FlagExempt) + EnvCNILogFile = EnvPrefix + "_" + "LOG_FILE" + EnvCNICNSUrl = EnvPrefix + "_" + strings.ToUpper(FlagCNSUrl) + EnvCNIEnableExactMatchForPodName = EnvPrefix + "_" + strings.ToUpper(FlagEnableExactMatchForPodName) Defaults = map[string]string{ - FlagOS: Linux, - FlagTenancy: Singletenancy, - FlagIPAM: AzureVNETIPAM, - FlagExempt: AzureTelemetryBin + "," + AzureTelemetryConfig, - FlagMode: Transparent, - FlagTarget: Local, - FlagBinDirectory: DefaultBinDirLinux, - FlagConflistDirectory: DefaultConflistDirLinux, - FlagVersion: Packaged, - FlagLogFilePath: DefaultLogFile, - EnvCNILogFile: EnvCNILogFile, - EnvCNISourceDir: DefaultSrcDirLinux, - EnvCNIDestinationBinDir: DefaultBinDirLinux, - EnvCNIDestinationConflistDir: DefaultConflistDirLinux, + FlagOS: Linux, + FlagTenancy: Singletenancy, + FlagIPAM: AzureVNETIPAM, + FlagExempt: AzureTelemetryBin + "," + AzureTelemetryConfig, + FlagMode: Transparent, + FlagTarget: Local, + FlagBinDirectory: DefaultBinDirLinux, + FlagConflistDirectory: DefaultConflistDirLinux, + FlagVersion: Packaged, + FlagLogFilePath: DefaultLogFile, + FlagCNSUrl: DefaultCNSUrl, + FlagEnableExactMatchForPodName: DefaultEnableExactMatchForPodName, + EnvCNILogFile: EnvCNILogFile, + EnvCNISourceDir: DefaultSrcDirLinux, + EnvCNIDestinationBinDir: DefaultBinDirLinux, + EnvCNIDestinationConflistDir: DefaultConflistDirLinux, } DefaultToggles = map[string]bool{ diff --git a/tools/acncli/cmd/cni/install.go b/tools/acncli/cmd/cni/install.go index caa26be718..7a0b667ac4 100644 --- a/tools/acncli/cmd/cni/install.go +++ b/tools/acncli/cmd/cni/install.go @@ -37,12 +37,12 @@ func InstallCNICmd() *cobra.Command { return err } - // only allow windows and linux binaries + // only allow singletenancy and multitenancy if err := envs.SetCNIType(viper.GetString(c.FlagTenancy)); err != nil { return err } - // only allow windows and linux binaries + // only allow bridge and transparent modes if err := envs.SetCNIDatapathMode(viper.GetString(c.FlagMode)); err != nil { return err } @@ -53,6 +53,8 @@ func InstallCNICmd() *cobra.Command { envs.DstBinDir = viper.GetString(c.FlagBinDirectory) envs.DstConflistDir = viper.GetString(c.FlagConflistDirectory) envs.IPAMType = viper.GetString(c.FlagIPAM) + envs.CNSURL = viper.GetString(c.FlagCNSUrl) + envs.EnableExactMatchForPodName = viper.GetBool(c.FlagEnableExactMatchForPodName) return i.InstallLocal(envs) }, @@ -66,6 +68,8 @@ func InstallCNICmd() *cobra.Command { cmd.Flags().String(c.FlagBinDirectory, c.Defaults[c.FlagBinDirectory], "Destination where Azure CNI binaries will be installed") cmd.Flags().String(c.FlagConflistDirectory, c.Defaults[c.FlagConflistDirectory], "Destination where Azure CNI conflists will be installed") cmd.Flags().String(c.FlagExempt, c.Defaults[c.FlagExempt], "Exempt files that won't be installed") + cmd.Flags().String(c.FlagCNSUrl, c.Defaults[c.FlagCNSUrl], "CNS URL if multitenancy") + cmd.Flags().String(c.FlagEnableExactMatchForPodName, c.Defaults[c.FlagEnableExactMatchForPodName], "Enable exact match for pod name if multitenancy") return cmd } diff --git a/tools/acncli/cmd/install.go b/tools/acncli/cmd/install.go index 88c75de92d..fb3fb85a38 100644 --- a/tools/acncli/cmd/install.go +++ b/tools/acncli/cmd/install.go @@ -37,12 +37,12 @@ func InstallCNICmd() *cobra.Command { return err } - // only allow windows and linux binaries + // only allow singletenancy and multitenancy if err := envs.SetCNIType(viper.GetString(c.FlagTenancy)); err != nil { return err } - // only allow windows and linux binaries + // only allow bridge and transparent modes if err := envs.SetCNIDatapathMode(viper.GetString(c.FlagMode)); err != nil { return err } @@ -53,6 +53,8 @@ func InstallCNICmd() *cobra.Command { envs.DstBinDir = viper.GetString(c.FlagBinDirectory) envs.DstConflistDir = viper.GetString(c.FlagConflistDirectory) envs.IPAMType = viper.GetString(c.FlagIPAM) + envs.CNSURL = viper.GetString(c.FlagCNSUrl) + envs.EnableExactMatchForPodName = viper.GetBool(c.FlagEnableExactMatchForPodName) return i.InstallLocal(envs) }, @@ -66,6 +68,8 @@ func InstallCNICmd() *cobra.Command { cmd.Flags().String(c.FlagBinDirectory, c.Defaults[c.FlagBinDirectory], "Destination where Azure CNI binaries will be installed") cmd.Flags().String(c.FlagConflistDirectory, c.Defaults[c.FlagConflistDirectory], "Destination where Azure CNI conflists will be installed") cmd.Flags().String(c.FlagExempt, c.Defaults[c.FlagExempt], "Exempt files that won't be installed") + cmd.Flags().String(c.FlagCNSUrl, c.Defaults[c.FlagCNSUrl], "CNS URL if multitenancy") + cmd.Flags().String(c.FlagEnableExactMatchForPodName, c.Defaults[c.FlagEnableExactMatchForPodName], "Enable exact match for pod name if multitenancy") return cmd } diff --git a/tools/acncli/installer/conflist.go b/tools/acncli/installer/conflist.go index 481ff60e5d..d39ad055a7 100644 --- a/tools/acncli/installer/conflist.go +++ b/tools/acncli/installer/conflist.go @@ -88,6 +88,12 @@ func ModifyConflists(conflistpath string, installerConf InstallerConfig, perm os netconfig.Bridge = c.Azure0 } + // if multitenant, update multitenant configs + if netconfig.MultiTenancy { + netconfig.CNSUrl = installerConf.CNSURL + netconfig.EnableExactMatchForPodName = installerConf.EnableExactMatchForPodName + } + // set conf back in conflist conflist.Plugins[confindex] = netconfig diff --git a/tools/acncli/installer/install.go b/tools/acncli/installer/install.go index c562373461..ac34dc5e13 100644 --- a/tools/acncli/installer/install.go +++ b/tools/acncli/installer/install.go @@ -12,14 +12,16 @@ import ( ) type InstallerConfig struct { - SrcDir string - DstBinDir string - DstConflistDir string - IPAMType string - ExemptBins map[string]bool - OSType string - CNITenancy string - CNIMode string + SrcDir string + DstBinDir string + DstConflistDir string + IPAMType string + ExemptBins map[string]bool + OSType string + CNITenancy string + CNIMode string + CNSURL string + EnableExactMatchForPodName bool } func (i *InstallerConfig) SetExempt(exempt []string) { @@ -53,7 +55,7 @@ func (i *InstallerConfig) SetCNIType(cniType string) error { } func (i *InstallerConfig) SetCNIDatapathMode(cniMode string) error { - // get paths for singletenancy and multitenancy + // check transparent or bridge mode only if cniMode != "" { if strings.EqualFold(cniMode, c.Transparent) || strings.EqualFold(cniMode, c.Bridge) { i.CNIMode = cniMode