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

cilium: Make CLI more graceful on environments with IPv6 disabled #16168

Merged
merged 1 commit into from Aug 4, 2021

Conversation

Maddy007-maha
Copy link
Contributor

@Maddy007-maha Maddy007-maha commented May 17, 2021

cilium: Make CLI more graceful on environments with IPv6 disabled

Description:
Issue: Some CLI's are complaining to stderr even on environments with IPV6 disabled
Root cause: As part of CLI implementation, it is always retrieving the GlobalMaps using true flag irrespective of IPV6 is enabled/disabled
Suggested fix: Now, GlobalMaps are based on correct IPV6 status from the cilium-agent else read from the system config (absence of agent)

Affected CLIs:

    $ cilium bpf ct ...
    $ cilium bpf nat ...
    $ cilium bpf recorder ...

Fixes: #13834

Signed-off-by: Mahadev Panchal mahadev.panchal@accuknox.com

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label May 17, 2021
@Maddy007-maha Maddy007-maha changed the title Fix 13834 cli ipv6 cilium: Make CLI more graceful on environments with IPv6 disabled May 17, 2021
@Maddy007-maha Maddy007-maha force-pushed the fix_13834_cli_ipv6 branch 6 times, most recently from 34dd200 to e7bbafb Compare May 19, 2021 15:59
@Maddy007-maha Maddy007-maha marked this pull request as ready for review May 19, 2021 16:05
@Maddy007-maha Maddy007-maha requested a review from a team as a code owner May 19, 2021 16:05
@twpayne twpayne added the release-note/minor This PR changes functionality that users may find relevant to operating Cilium. label May 20, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label May 20, 2021
} else { // else read the EnableIPv6 status from the file-system
agentConfigFile := filepath.Join(defaults.RuntimePath, defaults.StateDir,
"agent-runtime-config.json")
var agentConfig interface{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to use the appropriate concrete type here, rather than an empty interface and lots of unchecked type assertions below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

"agent-runtime-config.json")
var agentConfig interface{}

if _, err := os.Stat(agentConfigFile); !os.IsNotExist(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The call to os.Stat is unnecessary - an error will be returned by ReadFile anyway. Note also that the condition is wrong: any other error than IsNotExist will cause the condition to be true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

var agentConfig interface{}

if _, err := os.Stat(agentConfigFile); !os.IsNotExist(err) {
if byteValue, err := ioutil.ReadFile(agentConfigFile); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

ioutil.ReadFile is deprecated. Please use os.ReadFile instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the update, incorporated your all comments

}
}
// returning the EnableIPv6 default status
return true
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be defaults.EnableIPv6.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


if byteValue, err := os.ReadFile(agentConfigFile); err == nil {
if err = json.Unmarshal(byteValue, &agentConfig); err == nil {
return agentConfig["EnableIPv6"].(bool)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still doing an unchecked type assertion and using a map with string keys where better safety can be used by defining agentConfig to be a github.com/cilium/cilium/pkg/option.DaemonConfig.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

Choose a reason for hiding this comment

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

The change isn't what was requested. The file should be unmarshalled into a DaemonConfig struct, not add a new field to DaemonConfig.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the input, Have incorporated your comment.

Description:
Issue: Some CLI's are complaining to stderr even on environments with IPV6 disabled
Root cause: As part of CLI implemenation, it is always retrieving the GlobalMaps using true flag irrespective of IPV6 is enabled/disabled
Suggested fix: Now, GlobalMaps are based on correct IPV6 status from the cilium-agent else read from the system config (absence of agent)

Affected CLIs:
    $ cilium bpf ct ...
    $ cilium bpf nat ...
    $ cilium bpf recorder ...

Fixes: cilium#13834

Signed-off-by: Mahadev Panchal <mahadev.panchal@accuknox.com>
@twpayne
Copy link
Contributor

twpayne commented Jul 16, 2021

test-me-please

@aanm aanm merged commit 1a950d7 into cilium:master Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/minor This PR changes functionality that users may find relevant to operating Cilium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make CLI more graceful on handling environments with IPv6 disabled
4 participants