Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ ipam-*.xml

controller-gen
build/tools/bin
npm/debugTools/http
npm/debug/http
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ACNCLI_DIR = tools/acncli
TELEMETRY_CONF_DIR = telemetry
CNS_DIR = cns/service
CNMS_DIR = cnms/service
NPM_DIR = npm/plugin
NPM_DIR = npm/cmd
OUTPUT_DIR = output
BUILD_DIR = $(OUTPUT_DIR)/$(GOOS)_$(GOARCH)
IMAGE_DIR = $(OUTPUT_DIR)/images
Expand Down
2 changes: 1 addition & 1 deletion npm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ COPY $NPM_BUILD_DIR/azure-npm /usr/bin
WORKDIR /usr/bin

# Run the npm command by default when the container starts.
ENTRYPOINT ["/usr/bin/azure-npm"]
ENTRYPOINT ["/usr/bin/azure-npm", "start"]
26 changes: 25 additions & 1 deletion npm/azure-npm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ spec:
effect: NoSchedule
- key: CriticalAddonsOnly
operator: Exists

containers:
- name: azure-npm
image: mcr.microsoft.com/containernetworking/azure-npm:v1.4.1
Expand All @@ -95,13 +94,17 @@ spec:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: NPM_CONFIG
value: /etc/azure-npm/azure-npm.json
volumeMounts:
- name: xtables-lock
mountPath: /run/xtables.lock
- name: log
mountPath: /var/log
- name: protocols
mountPath: /etc/protocols
- name: azure-npm-config
mountPath: /etc/azure-npm
hostNetwork: true
volumes:
- name: log
Expand All @@ -116,6 +119,9 @@ spec:
hostPath:
path: /etc/protocols
type: File
- name: azure-npm-config
configMap:
name: azure-npm-config
serviceAccountName: azure-npm
---
apiVersion: v1
Expand All @@ -131,3 +137,21 @@ spec:
ports:
- port: 9000
targetPort: 10091
---
apiVersion: v1
kind: ConfigMap
metadata:
name: azure-npm-config
namespace: kube-system
data:
azure-npm.json: |
{
"ResyncPeriodInMinutes": 15,
"ListeningPort": 10091,
"ListeningAddress": "0.0.0.0",
"Toggles": {
"EnablePrometheusMetrics": true,
"EnablePprof": true,
"EnableHTTPDebugAPI": true
}
}
8 changes: 0 additions & 8 deletions npm/cmd/const.go

This file was deleted.

12 changes: 6 additions & 6 deletions npm/cmd/convertIPtable.go → npm/cmd/convertiptable.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cmd
package main

import (
"fmt"

"github.com/Azure/azure-container-networking/npm/debugTools/dataplane"
dataplane "github.com/Azure/azure-container-networking/npm/pkg/dataplane/debug"
"github.com/spf13/cobra"
)

Expand All @@ -16,8 +16,8 @@ var convertIPtableCmd = &cobra.Command{
if iptableName == "" {
iptableName = "filter"
}
npmCacheF, _ := cmd.Flags().GetString("npmF")
iptableSaveF, _ := cmd.Flags().GetString("iptF")
npmCacheF, _ := cmd.Flags().GetString("cache-file")
iptableSaveF, _ := cmd.Flags().GetString("iptables-file")
c := &dataplane.Converter{}
if npmCacheF == "" && iptableSaveF == "" {
ipTableRulesRes, err := c.GetJSONRulesFromIptables(iptableName)
Expand All @@ -38,6 +38,6 @@ var convertIPtableCmd = &cobra.Command{

func init() {
debugCmd.AddCommand(convertIPtableCmd)
convertIPtableCmd.Flags().StringP("iptF", "i", "", "Set the iptable-save file path (optional)")
convertIPtableCmd.Flags().StringP("npmF", "n", "", "Set the NPM cache file path (optional)")
convertIPtableCmd.Flags().StringP("iptables-file", "i", "", "Set the iptable-save file path (optional)")
convertIPtableCmd.Flags().StringP("cache-file", "c", "", "Set the NPM cache file path (optional)")
}
2 changes: 1 addition & 1 deletion npm/cmd/debugCmd.go → npm/cmd/debug.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"github.com/spf13/cobra"
Expand Down
29 changes: 15 additions & 14 deletions npm/cmd/getTuples.go → npm/cmd/gettuples.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
package cmd
package main

import (
"fmt"

"github.com/Azure/azure-container-networking/npm/debugTools/dataplane"
dataplane "github.com/Azure/azure-container-networking/npm/pkg/dataplane/debug"
"github.com/Azure/azure-container-networking/npm/util/errors"
"github.com/spf13/cobra"
)

func init() {
debugCmd.AddCommand(getTuplesCmd)
getTuplesCmd.Flags().StringP("src", "s", "", "set the source")
getTuplesCmd.Flags().StringP("dst", "d", "", "set the destination")
getTuplesCmd.Flags().StringP("iptables-file", "i", "", "Set the iptable-save file path (optional)")
getTuplesCmd.Flags().StringP("cache-file", "c", "", "Set the NPM cache file path (optional)")
}

// getTuplesCmd represents the getTuples command
var getTuplesCmd = &cobra.Command{
Use: "gettuples",
Short: "Get a list of hit rule tuples between specified source and destination",
RunE: func(cmd *cobra.Command, args []string) error {
src, _ := cmd.Flags().GetString("src")
if src == "" {
return fmt.Errorf("%w", errSrcNotSpecified)
return fmt.Errorf("%w", errors.ErrSrcNotSpecified)
}
dst, _ := cmd.Flags().GetString("dst")
if dst == "" {
return fmt.Errorf("%w", errDstNotSpecified)
return fmt.Errorf("%w", errors.ErrDstNotSpecified)
}
npmCacheF, _ := cmd.Flags().GetString("npmF")
iptableSaveF, _ := cmd.Flags().GetString("iptF")
npmCacheF, _ := cmd.Flags().GetString("cache-file")
iptableSaveF, _ := cmd.Flags().GetString("iptables-file")
srcType := dataplane.GetInputType(src)
dstType := dataplane.GetInputType(dst)
srcInput := &dataplane.Input{Content: src, Type: srcType}
Expand All @@ -47,11 +56,3 @@ var getTuplesCmd = &cobra.Command{
return nil
},
}

func init() {
debugCmd.AddCommand(getTuplesCmd)
getTuplesCmd.Flags().StringP("src", "s", "", "set the source")
getTuplesCmd.Flags().StringP("dst", "d", "", "set the destination")
getTuplesCmd.Flags().StringP("iptF", "i", "", "Set the iptable-save file path (optional)")
getTuplesCmd.Flags().StringP("npmF", "n", "", "Set the NPM cache file path (optional)")
}
14 changes: 14 additions & 0 deletions npm/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2018 Microsoft. All rights reserved.
// MIT License
package main

import (
"github.com/spf13/cobra"
)

// Version is populated by make during build.
var version string

func main() {
cobra.CheckErr(rootCmd.Execute())
}
8 changes: 4 additions & 4 deletions npm/cmd/parseIPtable.go → npm/cmd/parseiptable.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cmd
package main

import (
"fmt"

"github.com/Azure/azure-container-networking/npm/debugTools/dataplane/parse"
"github.com/Azure/azure-container-networking/npm/pkg/dataplane/parse"
"github.com/spf13/cobra"
)

Expand All @@ -12,7 +12,7 @@ var parseIPtableCmd = &cobra.Command{
Use: "parseiptable",
Short: "Parse iptable into Go object, dumping it to the console",
RunE: func(cmd *cobra.Command, args []string) error {
iptableSaveF, _ := cmd.Flags().GetString("iptF")
iptableSaveF, _ := cmd.Flags().GetString("iptables-file")
if iptableSaveF == "" {
iptable, err := parse.Iptables("filter")
if err != nil {
Expand All @@ -33,5 +33,5 @@ var parseIPtableCmd = &cobra.Command{

func init() {
debugCmd.AddCommand(parseIPtableCmd)
parseIPtableCmd.Flags().StringP("iptF", "i", "", "Set the iptable-save file path (optional)")
parseIPtableCmd.Flags().StringP("iptables-file", "i", "", "Set the iptable-save file path (optional)")
}
47 changes: 4 additions & 43 deletions npm/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,14 @@
package cmd
package main

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var cfgFile string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "azure-npm",
Short: "Collection of functions related to Azure NPM's debugging tools",
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
cobra.CheckErr(rootCmd.Execute())
}

func init() {
cobra.OnInitialize(initConfig)

rootCmd.Flags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.azure-npm-debug-cli.yaml)")
}

// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := os.UserHomeDir()
cobra.CheckErr(err)

// Search config in home directory with name ".azure-npm-debug-cli" (without extension).
viper.AddConfigPath(home)
viper.SetConfigType("yaml")
viper.SetConfigName(".azure-npm-debug-cli")
}

viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
}
Loading