Skip to content
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

azure-vnet: Implement GET command #161

Merged
merged 3 commits into from
Jun 2, 2018

Conversation

ashvindeodhar
Copy link
Member

CNI spec has added a new method : GET which allows the runtime / orchestrator to query the current state of the container networking configuration. This change adds the implementation for the GET method in azure-vnet plugin. The supported version changes to 0.4.0 to support GET API.
This PR fixes #148

Copy link
Member

@tamilmani1989 tamilmani1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. A runtime may call GET at any time; but if GET is called for a container before an ADD or after a DEL for that container, the plugin should return error 3 to indicate the container is unknown (see Well-known Error Codes section).

  2. If the previous action for the container was ADD or GET, the runtime must add a prevResult field to the configuration JSON of the plugin (or all plugins in the chain), which must be the Result of that previous ADD or GET action in JSON format

Are we ensuring the above two conditions as per spec -> https://github.com/containernetworking/cni/blob/master/SPEC.md

@@ -144,6 +150,18 @@ func (ep *endpoint) getInfo() *EndpointInfo {
Id: ep.Id,
IPAddresses: ep.IPAddresses,
Data: make(map[string]interface{}),
MacAddress: ep.MacAddress,
SandboxKey: ep.SandboxKey,
IfIndex: 0, // Azure CNI supports only one interface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this value is hardcoded.? Whicn interface it points to?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoded this to 0 with Sushant. Let me touch base with him again if this needs to be a declared const.

@@ -21,6 +21,8 @@ type endpoint struct {
MacAddress net.HardwareAddr
IPAddresses []net.IPNet
Gateways []net.IP
DNS DNSInfo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move Data to last field in structure..also plz group same datatypes together

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

cni/plugin.go Outdated
}

// Acquire store lock.
err = plugin.Store.Lock(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we started following this convention now.. in old code we dint change to this..but in new code we are following this
if err := function(); err != nil {
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

cni/plugin.go Outdated
}

config.Store = plugin.Store
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be a blank line before return

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return err
}
}
plugin.Store = nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}()

err = netPlugin.Plugin.InitializeKeyValueStore(&config)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove blank and you can check for err in same line as i said below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Changed to this stype in other places as well

@@ -177,3 +151,39 @@ func (plugin *Plugin) Error(err error) *cniTypes.Error {
func (plugin *Plugin) Errorf(format string, args ...interface{}) *cniTypes.Error {
return plugin.Error(fmt.Errorf(format, args...))
}

// Initialize key-value store
func (plugin *Plugin) InitializeKeyValueStore(config *common.PluginConfig) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? We are already saving the state of networkManager. What happens if we get a GET call before any ADD happens? Even in this case I don't think we need to initialize json store here, as we can print an empty result.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This initialize is called from the main. We can either check for the operation type in main and then avoid initialization, or we can always initialize and do the operation to keep logic simple. i'm fine with either.

}

// Uninitialize key-value store
func (plugin *Plugin) UninitializeKeyValueStore() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

cni/plugin.go Outdated
log.Printf("[cni] Failed to create store, err:%v.", err)
return err
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close if here?

Version: ipVersion,
Interface: &epInfo.IfIndex,
Address: ipAddresses,
Gateway: epInfo.Gateways[0],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for nil

@@ -177,3 +151,39 @@ func (plugin *Plugin) Error(err error) *cniTypes.Error {
func (plugin *Plugin) Errorf(format string, args ...interface{}) *cniTypes.Error {
return plugin.Error(fmt.Errorf(format, args...))
}

// Initialize key-value store
func (plugin *Plugin) InitializeKeyValueStore(config *common.PluginConfig) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This initialize is called from the main. We can either check for the operation type in main and then avoid initialization, or we can always initialize and do the operation to keep logic simple. i'm fine with either.

@sharmasushant sharmasushant merged commit 54be5fe into Azure:master Jun 2, 2018
@ashvindeodhar ashvindeodhar deleted the b-get-impl branch April 29, 2019 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to build this?
4 participants