-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 🌈 StatelessCNI: Adding getEndpoint and UpdateEndpoint API to CNS (#2102) * Adding getEndpoint and UpdateEndpoint API to CNS with the respective clients in support of stateless CNI. * Updating the unit tests and address the comments. * Addressing the comments. * Addressing the coments regarding CNS support for Stateless CNI * Adddressing the PR comments * 🌈 feat: adding flags for stateless cni (#2103) feat: stateless cni * 🌈 feat: StatelessCNI: Applying stateless CNI mode changes in network package. (#2197) * Apllying stateless CNI mode in network package. * Addresing the commetns. * feat: create stateless cni binary for swift (#2275) * enabling CNS telemetry * Master rebase changes * CNI Telemetry enabled on CNS * Stateless CNI changes. * making change to CNSendpointStorePath * Updating makefile to avoid creating statless CNI release. --------- Co-authored-by: Vipul Singh <vipul21sept@gmail.com>
- Loading branch information
1 parent
4034aad
commit c4fe3a8
Showing
19 changed files
with
947 additions
and
132 deletions.
There are no files selected for viewing
This file contains 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 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,98 @@ | ||
package network | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"os" | ||
"reflect" | ||
|
||
"github.com/Azure/azure-container-networking/cni" | ||
"github.com/Azure/azure-container-networking/telemetry" | ||
"github.com/containernetworking/cni/pkg/skel" | ||
cniTypes "github.com/containernetworking/cni/pkg/types" | ||
"github.com/pkg/errors" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// send error report to hostnetagent if CNI encounters any error. | ||
func ReportPluginError(reportManager *telemetry.ReportManager, tb *telemetry.TelemetryBuffer, err error) { | ||
logger.Error("Report plugin error") | ||
reflect.ValueOf(reportManager.Report).Elem().FieldByName("ErrorMessage").SetString(err.Error()) | ||
|
||
if err := reportManager.SendReport(tb); err != nil { | ||
logger.Error("SendReport failed", zap.Error(err)) | ||
} | ||
} | ||
|
||
func validateConfig(jsonBytes []byte) error { | ||
var conf struct { | ||
Name string `json:"name"` | ||
} | ||
if err := json.Unmarshal(jsonBytes, &conf); err != nil { | ||
return errors.Wrapf(err, "error reading network config") | ||
} | ||
if conf.Name == "" { | ||
return errors.New("missing network name") | ||
} | ||
return nil | ||
} | ||
|
||
func getCmdArgsFromEnv() (string, *skel.CmdArgs, error) { | ||
logger.Info("Going to read from stdin") | ||
stdinData, err := io.ReadAll(os.Stdin) | ||
if err != nil { | ||
return "", nil, errors.Wrapf(err, "error reading from stdin") | ||
} | ||
|
||
cmdArgs := &skel.CmdArgs{ | ||
ContainerID: os.Getenv("CNI_CONTAINERID"), | ||
Netns: os.Getenv("CNI_NETNS"), | ||
IfName: os.Getenv("CNI_IFNAME"), | ||
Args: os.Getenv("CNI_ARGS"), | ||
Path: os.Getenv("CNI_PATH"), | ||
StdinData: stdinData, | ||
} | ||
|
||
cmd := os.Getenv("CNI_COMMAND") | ||
return cmd, cmdArgs, nil | ||
} | ||
|
||
func HandleIfCniUpdate(update func(*skel.CmdArgs) error) (bool, error) { | ||
isupdate := true | ||
|
||
if os.Getenv("CNI_COMMAND") != cni.CmdUpdate { | ||
return false, nil | ||
} | ||
|
||
logger.Info("CNI UPDATE received") | ||
|
||
_, cmdArgs, err := getCmdArgsFromEnv() | ||
if err != nil { | ||
logger.Error("Received error while retrieving cmds from environment", zap.Error(err)) | ||
return isupdate, err | ||
} | ||
|
||
logger.Info("Retrieved command args for update", zap.Any("args", cmdArgs)) | ||
err = validateConfig(cmdArgs.StdinData) | ||
if err != nil { | ||
logger.Error("Failed to handle CNI UPDATE", zap.Error(err)) | ||
return isupdate, err | ||
} | ||
|
||
err = update(cmdArgs) | ||
if err != nil { | ||
logger.Error("Failed to handle CNI UPDATE", zap.Error(err)) | ||
return isupdate, err | ||
} | ||
|
||
return isupdate, nil | ||
} | ||
|
||
func PrintCNIError(msg string) { | ||
logger.Error(msg) | ||
cniErr := &cniTypes.Error{ | ||
Code: cniTypes.ErrTryAgainLater, | ||
Msg: msg, | ||
} | ||
cniErr.Print() | ||
} |
This file contains 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 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
Oops, something went wrong.