Skip to content

Commit 7fb08d9

Browse files
authored
Make multitenant configs plumb-able in cni manager (#1301)
1 parent 2157d7a commit 7fb08d9

File tree

5 files changed

+64
-36
lines changed

5 files changed

+64
-36
lines changed

tools/acncli/api/constants.go

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const (
3333
Singletenancy = "singletenancy"
3434
Multitenancy = "multitenancy"
3535

36+
// Multitenant Config flags
37+
FlagCNSUrl = "cnsurl"
38+
FlagEnableExactMatchForPodName = "enableexactmatchforpodname"
39+
3640
// os flags
3741
Linux = "linux"
3842
Windows = "windows"
@@ -66,35 +70,43 @@ const (
6670
Transparent = "transparent"
6771
Bridge = "bridge"
6872
Azure0 = "azure0"
73+
74+
// Multitenancy defaults
75+
DefaultCNSUrl = "http://localhost:10090"
76+
DefaultEnableExactMatchForPodName = "false"
6977
)
7078

7179
var (
7280
// Concatenating flags to the env ensures consistency between flags and env's for viper and cobra
73-
EnvCNIOS = EnvPrefix + "_" + strings.ToUpper(FlagOS)
74-
EnvCNIType = EnvPrefix + "_" + strings.ToUpper(FlagTenancy)
75-
EnvCNISourceDir = EnvPrefix + "_" + "SRC_DIR"
76-
EnvCNIDestinationBinDir = EnvPrefix + "_" + "BIN_DIR"
77-
EnvCNIDestinationConflistDir = EnvPrefix + "_" + "CONFLIST_DIR"
78-
EnvCNIIPAMType = EnvPrefix + "_" + strings.ToUpper(FlagIPAM)
79-
EnvCNIMode = EnvPrefix + "_" + strings.ToUpper(FlagMode)
80-
EnvCNIExemptBins = EnvPrefix + "_" + strings.ToUpper(FlagExempt)
81-
EnvCNILogFile = EnvPrefix + "_" + "LOG_FILE"
81+
EnvCNIOS = EnvPrefix + "_" + strings.ToUpper(FlagOS)
82+
EnvCNIType = EnvPrefix + "_" + strings.ToUpper(FlagTenancy)
83+
EnvCNISourceDir = EnvPrefix + "_" + "SRC_DIR"
84+
EnvCNIDestinationBinDir = EnvPrefix + "_" + "BIN_DIR"
85+
EnvCNIDestinationConflistDir = EnvPrefix + "_" + "CONFLIST_DIR"
86+
EnvCNIIPAMType = EnvPrefix + "_" + strings.ToUpper(FlagIPAM)
87+
EnvCNIMode = EnvPrefix + "_" + strings.ToUpper(FlagMode)
88+
EnvCNIExemptBins = EnvPrefix + "_" + strings.ToUpper(FlagExempt)
89+
EnvCNILogFile = EnvPrefix + "_" + "LOG_FILE"
90+
EnvCNICNSUrl = EnvPrefix + "_" + strings.ToUpper(FlagCNSUrl)
91+
EnvCNIEnableExactMatchForPodName = EnvPrefix + "_" + strings.ToUpper(FlagEnableExactMatchForPodName)
8292

8393
Defaults = map[string]string{
84-
FlagOS: Linux,
85-
FlagTenancy: Singletenancy,
86-
FlagIPAM: AzureVNETIPAM,
87-
FlagExempt: AzureTelemetryBin + "," + AzureTelemetryConfig,
88-
FlagMode: Transparent,
89-
FlagTarget: Local,
90-
FlagBinDirectory: DefaultBinDirLinux,
91-
FlagConflistDirectory: DefaultConflistDirLinux,
92-
FlagVersion: Packaged,
93-
FlagLogFilePath: DefaultLogFile,
94-
EnvCNILogFile: EnvCNILogFile,
95-
EnvCNISourceDir: DefaultSrcDirLinux,
96-
EnvCNIDestinationBinDir: DefaultBinDirLinux,
97-
EnvCNIDestinationConflistDir: DefaultConflistDirLinux,
94+
FlagOS: Linux,
95+
FlagTenancy: Singletenancy,
96+
FlagIPAM: AzureVNETIPAM,
97+
FlagExempt: AzureTelemetryBin + "," + AzureTelemetryConfig,
98+
FlagMode: Transparent,
99+
FlagTarget: Local,
100+
FlagBinDirectory: DefaultBinDirLinux,
101+
FlagConflistDirectory: DefaultConflistDirLinux,
102+
FlagVersion: Packaged,
103+
FlagLogFilePath: DefaultLogFile,
104+
FlagCNSUrl: DefaultCNSUrl,
105+
FlagEnableExactMatchForPodName: DefaultEnableExactMatchForPodName,
106+
EnvCNILogFile: EnvCNILogFile,
107+
EnvCNISourceDir: DefaultSrcDirLinux,
108+
EnvCNIDestinationBinDir: DefaultBinDirLinux,
109+
EnvCNIDestinationConflistDir: DefaultConflistDirLinux,
98110
}
99111

100112
DefaultToggles = map[string]bool{

tools/acncli/cmd/cni/install.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func InstallCNICmd() *cobra.Command {
3737
return err
3838
}
3939

40-
// only allow windows and linux binaries
40+
// only allow singletenancy and multitenancy
4141
if err := envs.SetCNIType(viper.GetString(c.FlagTenancy)); err != nil {
4242
return err
4343
}
4444

45-
// only allow windows and linux binaries
45+
// only allow bridge and transparent modes
4646
if err := envs.SetCNIDatapathMode(viper.GetString(c.FlagMode)); err != nil {
4747
return err
4848
}
@@ -53,6 +53,8 @@ func InstallCNICmd() *cobra.Command {
5353
envs.DstBinDir = viper.GetString(c.FlagBinDirectory)
5454
envs.DstConflistDir = viper.GetString(c.FlagConflistDirectory)
5555
envs.IPAMType = viper.GetString(c.FlagIPAM)
56+
envs.CNSURL = viper.GetString(c.FlagCNSUrl)
57+
envs.EnableExactMatchForPodName = viper.GetBool(c.FlagEnableExactMatchForPodName)
5658

5759
return i.InstallLocal(envs)
5860
},
@@ -66,6 +68,8 @@ func InstallCNICmd() *cobra.Command {
6668
cmd.Flags().String(c.FlagBinDirectory, c.Defaults[c.FlagBinDirectory], "Destination where Azure CNI binaries will be installed")
6769
cmd.Flags().String(c.FlagConflistDirectory, c.Defaults[c.FlagConflistDirectory], "Destination where Azure CNI conflists will be installed")
6870
cmd.Flags().String(c.FlagExempt, c.Defaults[c.FlagExempt], "Exempt files that won't be installed")
71+
cmd.Flags().String(c.FlagCNSUrl, c.Defaults[c.FlagCNSUrl], "CNS URL if multitenancy")
72+
cmd.Flags().String(c.FlagEnableExactMatchForPodName, c.Defaults[c.FlagEnableExactMatchForPodName], "Enable exact match for pod name if multitenancy")
6973

7074
return cmd
7175
}

tools/acncli/cmd/install.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func InstallCNICmd() *cobra.Command {
3737
return err
3838
}
3939

40-
// only allow windows and linux binaries
40+
// only allow singletenancy and multitenancy
4141
if err := envs.SetCNIType(viper.GetString(c.FlagTenancy)); err != nil {
4242
return err
4343
}
4444

45-
// only allow windows and linux binaries
45+
// only allow bridge and transparent modes
4646
if err := envs.SetCNIDatapathMode(viper.GetString(c.FlagMode)); err != nil {
4747
return err
4848
}
@@ -53,6 +53,8 @@ func InstallCNICmd() *cobra.Command {
5353
envs.DstBinDir = viper.GetString(c.FlagBinDirectory)
5454
envs.DstConflistDir = viper.GetString(c.FlagConflistDirectory)
5555
envs.IPAMType = viper.GetString(c.FlagIPAM)
56+
envs.CNSURL = viper.GetString(c.FlagCNSUrl)
57+
envs.EnableExactMatchForPodName = viper.GetBool(c.FlagEnableExactMatchForPodName)
5658

5759
return i.InstallLocal(envs)
5860
},
@@ -66,6 +68,8 @@ func InstallCNICmd() *cobra.Command {
6668
cmd.Flags().String(c.FlagBinDirectory, c.Defaults[c.FlagBinDirectory], "Destination where Azure CNI binaries will be installed")
6769
cmd.Flags().String(c.FlagConflistDirectory, c.Defaults[c.FlagConflistDirectory], "Destination where Azure CNI conflists will be installed")
6870
cmd.Flags().String(c.FlagExempt, c.Defaults[c.FlagExempt], "Exempt files that won't be installed")
71+
cmd.Flags().String(c.FlagCNSUrl, c.Defaults[c.FlagCNSUrl], "CNS URL if multitenancy")
72+
cmd.Flags().String(c.FlagEnableExactMatchForPodName, c.Defaults[c.FlagEnableExactMatchForPodName], "Enable exact match for pod name if multitenancy")
6973

7074
return cmd
7175
}

tools/acncli/installer/conflist.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ func ModifyConflists(conflistpath string, installerConf InstallerConfig, perm os
8888
netconfig.Bridge = c.Azure0
8989
}
9090

91+
// if multitenant, update multitenant configs
92+
if netconfig.MultiTenancy {
93+
netconfig.CNSUrl = installerConf.CNSURL
94+
netconfig.EnableExactMatchForPodName = installerConf.EnableExactMatchForPodName
95+
}
96+
9197
// set conf back in conflist
9298
conflist.Plugins[confindex] = netconfig
9399

tools/acncli/installer/install.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ import (
1212
)
1313

1414
type InstallerConfig struct {
15-
SrcDir string
16-
DstBinDir string
17-
DstConflistDir string
18-
IPAMType string
19-
ExemptBins map[string]bool
20-
OSType string
21-
CNITenancy string
22-
CNIMode string
15+
SrcDir string
16+
DstBinDir string
17+
DstConflistDir string
18+
IPAMType string
19+
ExemptBins map[string]bool
20+
OSType string
21+
CNITenancy string
22+
CNIMode string
23+
CNSURL string
24+
EnableExactMatchForPodName bool
2325
}
2426

2527
func (i *InstallerConfig) SetExempt(exempt []string) {
@@ -53,7 +55,7 @@ func (i *InstallerConfig) SetCNIType(cniType string) error {
5355
}
5456

5557
func (i *InstallerConfig) SetCNIDatapathMode(cniMode string) error {
56-
// get paths for singletenancy and multitenancy
58+
// check transparent or bridge mode only
5759
if cniMode != "" {
5860
if strings.EqualFold(cniMode, c.Transparent) || strings.EqualFold(cniMode, c.Bridge) {
5961
i.CNIMode = cniMode

0 commit comments

Comments
 (0)