-
Notifications
You must be signed in to change notification settings - Fork 260
Add "acn" cli tool to install and manage Azure CNI #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1566194
tail azure-vnet.logs
matmerr 3a943e8
dockerfile update
matmerr 4d14734
installer fixes
matmerr ff549cc
remove external deps
matmerr a574a6b
move to cli design
matmerr 8ede32f
manager cmd
matmerr c0ce71a
update vendor
matmerr 90e0e19
minor fixes
matmerr 9d03b4c
logs
matmerr b91f746
update makefile
matmerr 174d85d
Update manager-master.yaml
matmerr 2a3a44a
Update manager-agent.yaml
matmerr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,7 @@ ipam-*.xml | |
| .vscode/* | ||
|
|
||
| # Coverage | ||
| *.out | ||
| *.out | ||
|
|
||
| # Goland | ||
| .idea/* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| deployment/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| FROM golang as build | ||
| WORKDIR /go/src/github.com/Azure/azure-container-networking/ | ||
| ADD . . | ||
| ARG VERSION | ||
| RUN make all-binaries | ||
| RUN rm -rf ./output/windows* | ||
| RUN rm -rf ./output/linux_amd64/npm/* | ||
| RUN mv ./output /output | ||
| RUN find /output -name "*.zip" -type f -delete | ||
| RUN find /output -name "*.tgz" -type f -delete | ||
|
|
||
| FROM scratch | ||
| COPY --from=build /output/linux_amd64/acncli/ . | ||
| COPY --from=build /output /output | ||
|
|
||
| ENV AZURE_CNI_OS=linux | ||
| ENV AZURE_CNI_TENANCY=singletenancy | ||
| ENV AZURE_CNI_IPAM=azure-cns | ||
| ENV AZURE_CNI_MODE=transparent | ||
|
|
||
| CMD ["./acn", "manager", "-f"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package api | ||
|
|
||
| import "strings" | ||
|
|
||
| const ( | ||
| CNI = "cni" | ||
|
|
||
| EnvPrefix = "AZURE_CNI" | ||
|
|
||
| //CNI Install Flags | ||
| FlagMode = "mode" | ||
| FlagTarget = "target" | ||
| FlagIPAM = "ipam" | ||
| FlagOS = "os" | ||
| FlagTenancy = "tenancy" | ||
| FlagExempt = "exempt" | ||
| FlagBinDirectory = "bin-directory" | ||
| FlagConflistDirectory = "conflist-directory" | ||
| FlagVersion = "version" | ||
|
|
||
| //CNI Log Flags | ||
| FlagFollow = "follow" | ||
| FlagLogFilePath = "log-file" | ||
|
|
||
| // tenancy flags | ||
| Singletenancy = "singletenancy" | ||
| Multitenancy = "multitenancy" | ||
|
|
||
| // os flags | ||
| Linux = "linux" | ||
| Windows = "windows" | ||
|
|
||
| // arch flags | ||
| Amd64 = "amd64" | ||
|
|
||
| // target mode flags | ||
| Local = "local" | ||
| Cluster = "cluster" | ||
|
|
||
| // File permissions | ||
| BinPerm = 755 | ||
| ConflistPerm = 644 | ||
|
|
||
| // CNI versions | ||
| Latest = "latest" | ||
| Packaged = "packaged" | ||
|
|
||
| AzureCNIBin = "azure-vnet" | ||
| AzureTelemetryBin = "azure-vnet-telemetry" | ||
| AzureTelemetryConfig = "azure-vnet-telemetry.config" | ||
| AzureCNSIPAM = "azure-cns" | ||
| AzureVNETIPAM = "azure-vnet-ipam" | ||
| ConflistExtension = ".conflist" | ||
|
|
||
| DefaultSrcDirLinux = "/output/" | ||
| DefaultBinDirLinux = "/opt/cni/bin/" | ||
| DefaultConflistDirLinux = "/etc/cni/net.d/" | ||
| DefaultLogFile = "/var/log/azure-vnet.log" | ||
| Transparent = "transparent" | ||
| Bridge = "bridge" | ||
| Azure0 = "azure0" | ||
| ) | ||
|
|
||
| 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" | ||
|
|
||
| Defaults = map[string]string{ | ||
| FlagOS: Linux, | ||
| FlagTenancy: Singletenancy, | ||
| FlagIPAM: AzureVNETIPAM, | ||
| FlagExempt: AzureTelemetryBin + "," + AzureTelemetryConfig, | ||
| FlagMode: Bridge, | ||
| FlagTarget: Local, | ||
| FlagBinDirectory: DefaultBinDirLinux, | ||
| FlagConflistDirectory: DefaultConflistDirLinux, | ||
| FlagVersion: Packaged, | ||
| FlagLogFilePath: DefaultLogFile, | ||
| EnvCNILogFile: EnvCNILogFile, | ||
| EnvCNISourceDir: DefaultSrcDirLinux, | ||
| EnvCNIDestinationBinDir: DefaultBinDirLinux, | ||
| EnvCNIDestinationConflistDir: DefaultConflistDirLinux, | ||
| } | ||
|
|
||
| DefaultToggles = map[string]bool{ | ||
| FlagFollow: false, | ||
| } | ||
| ) | ||
|
|
||
| func GetDefaults() map[string]string { | ||
| return Defaults | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| c "github.com/Azure/azure-container-networking/acncli/api" | ||
| i "github.com/Azure/azure-container-networking/acncli/installer" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| // install CNI will install CNI to a local machine | ||
| func InstallCmd() *cobra.Command { | ||
| var cmd = &cobra.Command{ | ||
| Use: "install", | ||
| Short: "Installs an ACN component", | ||
| } | ||
| cmd.AddCommand(InstallCNICmd()) | ||
| return cmd | ||
| } | ||
|
|
||
| func InstallCNICmd() *cobra.Command { | ||
| var cmd = &cobra.Command{ | ||
| Use: "cni", | ||
| Short: "Installs CNI and conflist ", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
|
|
||
| envs := i.InstallerConfig{ | ||
| ExemptBins: make(map[string]bool), | ||
| } | ||
|
|
||
| // only allow windows and linux binaries | ||
| if err := envs.SetOSType(viper.GetString(c.FlagOS)); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // only allow windows and linux binaries | ||
| if err := envs.SetCNIType(viper.GetString(c.FlagTenancy)); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // only allow windows and linux binaries | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
| if err := envs.SetCNIDatapathMode(viper.GetString(c.FlagMode)); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| envs.SetExempt(strings.Split(strings.Replace(strings.ToLower(viper.GetString(c.FlagExempt)), " ", "", -1), ",")) | ||
|
|
||
| envs.SrcDir = fmt.Sprintf("%s%s/%s/", c.DefaultSrcDirLinux, envs.OSType, envs.CNITenancy) | ||
| envs.DstBinDir = viper.GetString(c.FlagBinDirectory) | ||
| envs.DstConflistDir = viper.GetString(c.FlagConflistDirectory) | ||
| envs.IPAMType = viper.GetString(c.FlagIPAM) | ||
|
|
||
| return i.InstallLocal(envs) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().String(c.FlagMode, c.Defaults[c.FlagMode], fmt.Sprintf("Datapath mode for Azure CNI, options are %s and %s", c.Transparent, c.Bridge)) | ||
| cmd.Flags().String(c.FlagTarget, c.Defaults[c.FlagTarget], fmt.Sprintf("Location to install Azure CNI, options are %s and %s", c.Local, c.Cluster)) | ||
| cmd.Flags().String(c.FlagIPAM, c.Defaults[c.FlagIPAM], fmt.Sprintf("Specify which IPAM source to use, options are %s and %s", c.AzureVNETIPAM, c.AzureCNSIPAM)) | ||
| cmd.Flags().String(c.FlagOS, c.Defaults[c.FlagOS], fmt.Sprintf("Specify which operating system to install, options are %s and %s", c.Linux, c.Windows)) | ||
| cmd.Flags().String(c.FlagTenancy, c.Defaults[c.FlagTenancy], fmt.Sprintf("Tenancy option for Azure CNI, options are %s and %s", c.Singletenancy, c.Multitenancy)) | ||
| 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") | ||
|
|
||
| return cmd | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| c "github.com/Azure/azure-container-networking/acncli/api" | ||
| "github.com/nxadm/tail" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| // LogsCmd will write the logs of the Azure CNI logs | ||
| func LogsCmd() *cobra.Command { | ||
| var cmd = &cobra.Command{ | ||
| Use: "logs", | ||
| Short: "Fetches the logs of an ACN component", | ||
| Long: "The logs command is used to fetch and/or watch the logs of an ACN component", | ||
| } | ||
| cmd.AddCommand(LogsCNICmd()) | ||
| return cmd | ||
| } | ||
|
|
||
| func LogsCNICmd() *cobra.Command { | ||
| var cmd = &cobra.Command{ | ||
| Use: "cni", | ||
| Short: fmt.Sprintf("Retrieves the logs of %s binary", c.AzureCNIBin), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| fmt.Printf("📃 - started watching %s\n", viper.GetString(c.FlagLogFilePath)) | ||
|
|
||
| // this loop exists for when the logfile gets rotated, and tail loses the original file | ||
| for { | ||
| t, err := tail.TailFile(viper.GetString(c.FlagLogFilePath), tail.Config{Follow: viper.GetBool(c.FlagFollow), ReOpen: true}) | ||
|
|
||
| if err != nil { | ||
| return err | ||
| } | ||
| for line := range t.Lines { | ||
| fmt.Println(line.Text) | ||
| } | ||
| if viper.GetBool(c.FlagFollow) == false { | ||
| return nil | ||
| } | ||
| } | ||
| }} | ||
|
|
||
| cmd.Flags().BoolP(c.FlagFollow, "f", c.DefaultToggles[c.FlagFollow], fmt.Sprintf("Follow the log file, similar to 'tail -f'")) | ||
| cmd.Flags().String(c.FlagLogFilePath, c.Defaults[c.FlagLogFilePath], fmt.Sprintf("Path of the Azure CNI log file")) | ||
|
|
||
| return cmd | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // ManagerCmd starts the manager mode, which installs CNI+Conflists, then watches logs | ||
| func ManagerCmd() *cobra.Command { | ||
| var cmd = &cobra.Command{ | ||
| Use: "manager", | ||
| Short: "Starts the ACN CNI manager, which installs CNI, sets up conflists, then starts watching logs", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| err := InstallCNICmd().RunE(cmd, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| err = LogsCNICmd().RunE(cmd, args) | ||
| return err | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().AddFlagSet(InstallCNICmd().Flags()) | ||
| cmd.Flags().AddFlagSet(LogsCNICmd().Flags()) | ||
|
|
||
| return cmd | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment remove or change to //only allow Single or Multi tenancy