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

Adds the configmap for naming the security group #111

Merged
merged 1 commit into from
Feb 21, 2023

Conversation

Nithish555
Copy link
Contributor

The configmap conatins the name prefix for the security group

Signed-off-by: nithishs nithishs@vmware.com

@codecov
Copy link

codecov bot commented Jan 26, 2023

Codecov Report

Merging #111 (22b1c12) into main (7f2e609) will decrease coverage by 0.10%.
The diff coverage is 53.63%.

❗ Current head 22b1c12 differs from pull request most recent head abd6568. Consider uploading reports for the commit abd6568 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
- Coverage   58.20%   58.11%   -0.10%     
==========================================
  Files          50       52       +2     
  Lines        8248     8361     +113     
==========================================
+ Hits         4801     4859      +58     
- Misses       2959     3003      +44     
- Partials      488      499      +11     
Flag Coverage Δ
unit-tests 58.11% <53.63%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/controllers/cloud/networkpolicy_controller.go 51.86% <33.33%> (-0.19%) ⬇️
pkg/apiserver/webhook/configmap_webhook.go 50.72% <50.72%> (ø)
pkg/controllers/cloud/configmap_controller.go 60.52% <60.52%> (ø)
pkg/cloud-provider/cloudapi/aws/aws_ec2.go 63.42% <0.00%> (-0.84%) ⬇️
pkg/controllers/cloud/networkpolicy.go 69.40% <0.00%> (-0.27%) ⬇️
pkg/converter/source/virtualmachine_converter.go 85.38% <0.00%> (-0.23%) ⬇️
pkg/controllers/cloud/virtualmachine_controller.go 50.87% <0.00%> (ø)
pkg/cloud-provider/cloudapi/aws/aws_security.go 50.50% <0.00%> (+0.71%) ⬆️

pkg/cloud-provider/securitygroup/securitygroup.go Outdated Show resolved Hide resolved
pkg/cloud-provider/securitygroup/securitygroup.go Outdated Show resolved Hide resolved
config/nephe.yml Outdated Show resolved Hide resolved
config/nephe.yml Outdated Show resolved Hide resolved
config/nephe.yml Outdated Show resolved Hide resolved
config/nephe.yml Outdated Show resolved Hide resolved
config/nephe.yml Outdated
namespace: nephe-system
data:
nephe-controller.conf: |
ResourcePrefix: anp-
Copy link
Contributor

Choose a reason for hiding this comment

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

By default it should be commented out and default value should be nephe

Suggested change
ResourcePrefix: anp-
#ResourcePrefix: nephe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that the value is not commented out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the nephe is the default value.

Copy link
Contributor

@shenmo3 shenmo3 Jan 31, 2023

Choose a reason for hiding this comment

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

imo we should add the - separator in the AddResourcePrefix func or in options.go setting options, since I don't think we should let user customize separators, or it might cause errors if it's some cloud not allowed character. We can also have a separate const defaultResourceSeparator?
@reachjainrahul @Anandkumar26 Should we have some checks on the prefix validity in the webhook, like no cloud not allowed character, no special character etc.?

config/nephe.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@shenmo3 shenmo3 left a comment

Choose a reason for hiding this comment

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

Minor nits, up to you.

)

const (
namePrefix = "nephe-"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: defaultResourcePrefix?

Try to be consistent on this option var name across all files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved


func newOptions() *Options {
return &Options{
config: &ControllerConfig{},
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can set the default values here then return. This saves checks for setting default later in complete() and imo its more readable.

@@ -14,6 +14,10 @@

package main

type ControllerConfig struct {
ResourcePrefix string `yaml:"ResourcePrefix,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

CloudResourcePrefix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved


flag.StringVar(&opts.configFile, "config", opts.configFile, "The path to the configuration file")
Copy link
Contributor

Choose a reason for hiding this comment

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

end with .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

@@ -68,6 +71,8 @@ func main() {
logging.SetDebugLog(enableDebugLog)
ctrl.SetLogger(logging.GetLogger("setup"))

opts.complete()
Copy link
Contributor

Choose a reason for hiding this comment

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

if you fail to parse config, you should consider failing pod status to notReady

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

@@ -86,6 +91,9 @@ func main() {
// Initialize Account poller map.
poller := controllers.InitPollers()

// Add the name prefix
securitygroup.AddResourcePrefix(opts.config.ResourcePrefix)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be set after you parse config.. Dont delay

namespace: system
data:
nephe-controller.conf: |
ResourcePrefix: nephe-
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 be in under '#' and add a comment description indicating what this field does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

NepheControllerAddressGroupPrefix = NepheControllerPrefix + "ag-"
NepheControllerAppliedToPrefix = NepheControllerPrefix + "at-"
var (
NepheControllerPrefix string
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Drop Nephe.. Just use ControllerPrefix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

@@ -141,6 +141,12 @@ type CloudResourceID struct {
Vpc string
}

func AddResourcePrefix(name string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: SetCloudResourcePrefixes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

flag.StringVar(&opts.configFile, "config", opts.configFile, "The path to the configuration file.")
err := opts.complete()
if err != nil {
setupLog.Error(err, "Invalid controller config map data")
Copy link
Contributor

Choose a reason for hiding this comment

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

All error message should start with smallcase.

Suggested change
setupLog.Error(err, "Invalid controller config map data")
setupLog.Error(err, "invalid config map data")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

@@ -86,6 +96,9 @@ func main() {
// Initialize Account poller map.
poller := controllers.InitPollers()

// Add the CloudResourcePrefix
Copy link
Contributor

Choose a reason for hiding this comment

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

Set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

package main

import (
"antrea.io/nephe/pkg/controllers/config"
Copy link
Contributor

Choose a reason for hiding this comment

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

Sort imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

return err
}
}
o.Log.V(1).Info("CloudResourcePrefix")
Copy link
Contributor

Choose a reason for hiding this comment

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

2 logging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

namespace: system
data:
nephe-controller.conf: |
CloudResourcePrefix: anp
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 be commented and a description on variable is required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

package webhook

import (
controllers "antrea.io/nephe/pkg/controllers/cloud"
Copy link
Contributor

Choose a reason for hiding this comment

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

Sort imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

DefaultCloudResourcePrefix = "nephe"
)

type ControllerConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is the struct here..? Its mostly for const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because controller config might contains more properties. This is how they followed in antrea controller.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can have config.go and move ControllerConfig struct and ConfigMapName/Namespace constants there.

v.Log.V(1).Info("new", "CloudResourcePrefix", newConfigMap.Data["CloudResourcePrefix"])
if req.OldObject.Raw != nil {
if err := json.Unmarshal(req.OldObject.Raw, &oldConfigMap); err != nil {
v.Log.Error(err, "Failed to decode old configMap", "ConfigMapValidator", req.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

all error message should begin with lower case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

if len(newCloudResourcePrefix) > 0 {
if !config.ValidateName(newCloudResourcePrefix) {
return admission.Denied(fmt.Sprintf("invalid CloudResourcePrefix %s only "+
"alphanumeric and '-' characters are allowed.", newCloudResourcePrefix))
Copy link
Contributor

Choose a reason for hiding this comment

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

invalid CloudResourcePrefix xyz, only.. Basically , is required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is suggested by anand. @Anandkumar26 Please comment about this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just add a comma after invalid CloudResourcePrefix %s,

Suggested change
"alphanumeric and '-' characters are allowed.", newCloudResourcePrefix))
"invalid CloudResourcePrefix %s only, "+
"alphanumeric and '-' characters are allowed."))

CloudResourcePrefix string `yaml:"CloudResourcePrefix,omitempty"`
}

func SetConfigFile(name string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why no move ConfigFile inside ControllerConfig struct?? avoid using global variables..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because controller config is specifically for nephe-controller.conf. The config file contains more than one controller conf that's why we used this approach.

@@ -15,6 +15,8 @@
package main

import (
"antrea.io/nephe/pkg/cloud-provider/securitygroup"
Copy link
Contributor

Choose a reason for hiding this comment

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

Sort imports

os.Exit(1)
}

securitygroup.SetCloudResourcePrefix(&configMapController.ControllerConfig.CloudResourcePrefix)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to set Prefix here?? Consider avoiding it

}

if newCloudResourcePrefix == oldCloudResourcePrefix {
v.Log.V(1).Info("CloudResourcePrefix are same", "newCloudResourcePrefix",
Copy link
Contributor

Choose a reason for hiding this comment

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

this log is not required

Context("Running Webhook tests for ConfigMap", func() {
var (
testNamespacedName1 = types.NamespacedName{Namespace: "nephe-system", Name: "nephe-config"}
// testNamespacedName2 = types.NamespacedName{Namespace: "nephe-system", Name: "config"}
Copy link
Contributor

Choose a reason for hiding this comment

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

remove comment

decoder, err = admission.NewDecoder(newScheme)
Expect(err).Should(BeNil())
fakeClient = fake.NewClientBuilder().WithScheme(newScheme).Build()
npController = &controllers.NetworkPolicyReconciler{
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed?

err = ConfigMapValidatorTest.InjectDecoder(decoder)
Expect(err).Should(BeNil())
})
AfterEach(func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

check if you even need to declare it

controllerConfig: conf,
},
}
if !errors.IsNotFound(retError) {
Copy link
Contributor

Choose a reason for hiding this comment

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

re-org the code

The configmap conatins the name prefix for the security group

Signed-off-by: nithishs <nithishs@vmware.com>
Copy link
Contributor

@reachjainrahul reachjainrahul left a comment

Choose a reason for hiding this comment

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

/LGTM

@reachjainrahul
Copy link
Contributor

/nephe-test-e2e-kind

@reachjainrahul reachjainrahul merged commit f507f02 into antrea-io:main Feb 21, 2023
Copy link

@krishnamiriyala krishnamiriyala left a comment

Choose a reason for hiding this comment

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

Can nephe-controller.conf move from /tmp to /etc/nephe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants