-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
config/nephe.yml
Outdated
namespace: nephe-system | ||
data: | ||
nephe-controller.conf: | | ||
ResourcePrefix: anp- |
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.
By default it should be commented out and default value should be nephe
ResourcePrefix: anp- | |
#ResourcePrefix: nephe |
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.
Solved
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 see that the value is not commented out.
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.
Because the nephe is the default value.
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.
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.?
84954e9
to
49f8164
Compare
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.
Minor nits, up to you.
cmd/nephe-controller/options.go
Outdated
) | ||
|
||
const ( | ||
namePrefix = "nephe-" |
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.
nit: defaultResourcePrefix?
Try to be consistent on this option var name across all files.
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.
Solved
cmd/nephe-controller/options.go
Outdated
|
||
func newOptions() *Options { | ||
return &Options{ | ||
config: &ControllerConfig{}, |
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.
Maybe we can set the default values here then return. This saves checks for setting default later in complete()
and imo its more readable.
cmd/nephe-controller/config.go
Outdated
@@ -14,6 +14,10 @@ | |||
|
|||
package main | |||
|
|||
type ControllerConfig struct { | |||
ResourcePrefix string `yaml:"ResourcePrefix,omitempty"` |
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.
CloudResourcePrefix
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.
Solved
cmd/nephe-controller/main.go
Outdated
|
||
flag.StringVar(&opts.configFile, "config", opts.configFile, "The path to the configuration file") |
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.
end with .
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.
Solved
cmd/nephe-controller/main.go
Outdated
@@ -68,6 +71,8 @@ func main() { | |||
logging.SetDebugLog(enableDebugLog) | |||
ctrl.SetLogger(logging.GetLogger("setup")) | |||
|
|||
opts.complete() |
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.
if you fail to parse config, you should consider failing pod status to notReady
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.
Solved
cmd/nephe-controller/main.go
Outdated
@@ -86,6 +91,9 @@ func main() { | |||
// Initialize Account poller map. | |||
poller := controllers.InitPollers() | |||
|
|||
// Add the name prefix | |||
securitygroup.AddResourcePrefix(opts.config.ResourcePrefix) |
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.
This can be set after you parse config.. Dont delay
config/manager/nephe-controller.yaml
Outdated
namespace: system | ||
data: | ||
nephe-controller.conf: | | ||
ResourcePrefix: nephe- |
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.
This should be in under '#' and add a comment description indicating what this field does
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.
Solved
NepheControllerAddressGroupPrefix = NepheControllerPrefix + "ag-" | ||
NepheControllerAppliedToPrefix = NepheControllerPrefix + "at-" | ||
var ( | ||
NepheControllerPrefix string |
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.
nit: Drop Nephe.. Just use ControllerPrefix
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.
Solved
@@ -141,6 +141,12 @@ type CloudResourceID struct { | |||
Vpc string | |||
} | |||
|
|||
func AddResourcePrefix(name string) { |
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.
nit: SetCloudResourcePrefixes?
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.
Solved
3d31d32
to
b4c2f55
Compare
cmd/nephe-controller/main.go
Outdated
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") |
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.
All error message should start with smallcase.
setupLog.Error(err, "Invalid controller config map data") | |
setupLog.Error(err, "invalid config map data") |
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.
Solved
cmd/nephe-controller/main.go
Outdated
@@ -86,6 +96,9 @@ func main() { | |||
// Initialize Account poller map. | |||
poller := controllers.InitPollers() | |||
|
|||
// Add the CloudResourcePrefix |
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.
Set
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.
Solved
cmd/nephe-controller/options.go
Outdated
package main | ||
|
||
import ( | ||
"antrea.io/nephe/pkg/controllers/config" |
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.
Sort imports
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.
Solved
cmd/nephe-controller/options.go
Outdated
return err | ||
} | ||
} | ||
o.Log.V(1).Info("CloudResourcePrefix") |
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.
2 logging
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.
Solved
config/manager/nephe-controller.yaml
Outdated
namespace: system | ||
data: | ||
nephe-controller.conf: | | ||
CloudResourcePrefix: anp |
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.
This should be commented and a description on variable is required
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.
Solved
package webhook | ||
|
||
import ( | ||
controllers "antrea.io/nephe/pkg/controllers/cloud" |
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.
Sort imports
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.
Solved
pkg/controllers/config/labels.go
Outdated
DefaultCloudResourcePrefix = "nephe" | ||
) | ||
|
||
type ControllerConfig struct { |
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.
why is the struct here..? Its mostly for const
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.
Because controller config might contains more properties. This is how they followed in antrea controller.
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 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) |
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.
all error message should begin with lower case
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.
Solved
if len(newCloudResourcePrefix) > 0 { | ||
if !config.ValidateName(newCloudResourcePrefix) { | ||
return admission.Denied(fmt.Sprintf("invalid CloudResourcePrefix %s only "+ | ||
"alphanumeric and '-' characters are allowed.", newCloudResourcePrefix)) |
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.
invalid CloudResourcePrefix xyz, only.. Basically , is required
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.
This is suggested by anand. @Anandkumar26 Please comment about this.
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.
Just add a comma after invalid CloudResourcePrefix %s,
"alphanumeric and '-' characters are allowed.", newCloudResourcePrefix)) | |
"invalid CloudResourcePrefix %s only, "+ | |
"alphanumeric and '-' characters are allowed.")) |
pkg/controllers/config/config.go
Outdated
CloudResourcePrefix string `yaml:"CloudResourcePrefix,omitempty"` | ||
} | ||
|
||
func SetConfigFile(name string) { |
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.
why no move ConfigFile inside ControllerConfig struct?? avoid using global variables..
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.
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.
fa73161
to
8d91e8c
Compare
cmd/nephe-controller/main.go
Outdated
@@ -15,6 +15,8 @@ | |||
package main | |||
|
|||
import ( | |||
"antrea.io/nephe/pkg/cloud-provider/securitygroup" |
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.
Sort imports
cmd/nephe-controller/main.go
Outdated
os.Exit(1) | ||
} | ||
|
||
securitygroup.SetCloudResourcePrefix(&configMapController.ControllerConfig.CloudResourcePrefix) |
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 really need to set Prefix here?? Consider avoiding it
} | ||
|
||
if newCloudResourcePrefix == oldCloudResourcePrefix { | ||
v.Log.V(1).Info("CloudResourcePrefix are same", "newCloudResourcePrefix", |
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.
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"} |
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.
remove comment
decoder, err = admission.NewDecoder(newScheme) | ||
Expect(err).Should(BeNil()) | ||
fakeClient = fake.NewClientBuilder().WithScheme(newScheme).Build() | ||
npController = &controllers.NetworkPolicyReconciler{ |
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.
is this needed?
err = ConfigMapValidatorTest.InjectDecoder(decoder) | ||
Expect(err).Should(BeNil()) | ||
}) | ||
AfterEach(func() { |
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.
check if you even need to declare it
controllerConfig: conf, | ||
}, | ||
} | ||
if !errors.IsNotFound(retError) { |
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.
re-org the code
ef065af
to
18fcd4f
Compare
The configmap conatins the name prefix for the security group Signed-off-by: nithishs <nithishs@vmware.com>
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.
/LGTM
/nephe-test-e2e-kind |
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.
Can nephe-controller.conf move from /tmp to /etc/nephe?
The configmap conatins the name prefix for the security group
Signed-off-by: nithishs nithishs@vmware.com