-
Notifications
You must be signed in to change notification settings - Fork 240
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
feat: Dev stateless cni #2276
Merged
Merged
feat: Dev stateless cni #2276
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
50b1584
feat: 🌈 StatelessCNI: Adding getEndpoint and UpdateEndpoint API to CN…
behzad-mir 6a541da
🌈 feat: adding flags for stateless cni (#2103)
vipul-21 a96397a
🌈 feat: StatelessCNI: Applying stateless CNI mode changes in network …
behzad-mir 5351eac
feat: create stateless cni binary for swift (#2275)
vipul-21 41ff105
enabling CNS telemetry
behzad-mir 7660819
Master rebase changes
behzad-mir 2e5bac4
CNI Telemetry enabled on CNS
behzad-mir 6c15348
Stateless CNI changes.
behzad-mir eefd73a
making change to CNSendpointStorePath
behzad-mir 9344500
Updating makefile to avoid creating statless CNI release.
behzad-mir 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 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.
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.
do we need this check if it doesn't apply to stateless cni?
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.
I added a comment on top of it :
// this condition will not apply to stateless CNI since the network struct will be crated on each call