-
Notifications
You must be signed in to change notification settings - Fork 136
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
Validate resource names for drift remediation flags #117
Validate resource names for drift remediation flags #117
Conversation
6013708
to
ffbf989
Compare
Completes aws-controllers-k8s/runtime#117 This patch adds a tiny modification to the controllers `main.go` that passes the resource names to `ackCfg.Validate` method. Needs a new runtime release. /hold Signed-off-by: Amine Hilaly <hilalyamine@gmail.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.
I'm good with this. In the future, it may be good to adopt an "option strategy" for the Config validation (or initialization). This "option strategy" would allow for introducing changes to the runtime that would not break binary/compile-time compatibility in the code generator (like has happened on the related PR there that introduces the resource manager factories getter).
The "option strategy" would look something like this:
// pkg/config/option.go
type Option struct {
kinds []string
// other fields that can be used in validation/initialization...
}
// WithKinds instructs the configuration to validate against a set of
// supplied resource kinds
func WithKinds(kinds []string) Option {
return Option{kinds: kinds}
}
// mergeOptions merges all Option structs into a single Option
// and sets any defaults to missing values
func mergeOptions(opts []Option) Option {
merged := Option{}
for _, opt := range opts {
if opt.kinds != nil {
merged.kinds = opt.kinds
}
// repeat for each field in Option ...
}
// set any defaults on merged if still nil...
return merged
}
// pkg/config/config.go
...
// Note this could also be a New() function instead of Config.Validate()...
func (cfg *Config) Validate(
opts ...Option,
) error {
merged := mergeOptions(opts)
if merged.kinds != nil {
// Validate the kinds...
}
}
This way as we add additional validations or configuration options, we don't need to change the function signature for Config.Validate()
-- or pkg/config.New()
.
Your code-generator template code would call like so:
if !cfg.Validate(WithKinds(resourceKinds)) {
// blah blah..
}
pkg/config/config.go
Outdated
@@ -32,6 +32,7 @@ import ( | |||
|
|||
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1" | |||
acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" | |||
ackrtutil "github.com/aws-controllers-k8s/runtime/pkg/util" |
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.
you can just name this alias ackutil
since we're already in the runtime package.
I love this idea. Let me implement it in this PR... |
Completes aws-controllers-k8s/runtime#117 This patch adds a tiny modification to the controllers `main.go` that passes the resource names to `ackCfg.Validate` method. Needs a new runtime release. /hold Signed-off-by: Amine Hilaly <hilalyamine@gmail.com>
e7422f5
to
dd79a82
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.
muy bueno, thanks @a-hilaly!
pkg/config/config.go
Outdated
func (cfg *Config) Validate(options ...Option) error { | ||
merged := mergeOptions(options) | ||
if len(merged.kinds) > 0 { |
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 don't really understand the value in the options
struct? I think it's an early optimisation that isn't adding much - especially since we aren't providing defaults.
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.
It's a know paradigm in Go - we could definitely do a follow up to bring default values this way. I agree that it's not bringing that much, but it allows us to add good stuff if needed :)
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.
dd79a82
to
84557c0
Compare
704ec6b
to
d25db5b
Compare
Completes aws-controllers-k8s/runtime#117 This patch adds a tiny modification to the controllers `main.go` that passes the resource names to `ackCfg.Validate` method. Needs a new runtime release. /hold Signed-off-by: Amine Hilaly <hilalyamine@gmail.com>
d25db5b
to
3a3c931
Compare
Completes aws-controllers-k8s/runtime#117 This patch adds a tiny modification to the controllers `main.go` that passes the resource names to `ackCfg.Validate` method. Needs a new runtime release. /hold Signed-off-by: Amine Hilaly <hilalyamine@gmail.com>
As discussed in https://github.com/aws-controllers-k8s/runtime/pull/10t6 this patch brings resource name validation to the arguments passed to `--reconcile-resource-resync-seconds`. It also slightly changes the previously implemented `ParseReconcileResourceResyncSeconds` to avoid uncessary validation ops. Signed-off-by: Amine Hilaly <hilalyamine@gmail.com>
3a3c931
to
0aacc2e
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: A-Hilaly, jaypipes, RedbackThomson The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Completes aws-controllers-k8s/runtime#117 This patch adds a tiny modification to the controllers `main.go` that passes the resource names to `ackCfg.Validate` method. Needs a new runtime release. /hold Signed-off-by: Amine Hilaly <hilalyamine@gmail.com>
Completes aws-controllers-k8s/runtime#117 This patch adds a tiny modification to the controllers `main.go` that passes the resource names to `ackCfg.Validate` method. Needs a new runtime release. /hold Signed-off-by: Amine Hilaly <hilalyamine@gmail.com>
[fixes aws-controllers-k8s/community#1647] Completes aws-controllers-k8s/runtime#117 This patch adds a tiny modification to the controllers `main.go` that passes the resource names to `ackCfg.Validate` method. Needs a new runtime release. /hold Signed-off-by: Amine Hilaly <hilalyamine@gmail.com> By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
[fixes https://github.com/aws-controllers-k8s/community/issues/1647]
As discussed in #106
this patch brings resource name validation to the arguments passed to
--reconcile-resource-resync-seconds
. It also slightly changes thepreviously implemented
ParseReconcileResourceResyncSeconds
to avoiduncessary validation ops.
Signed-off-by: Amine Hilaly hilalyamine@gmail.com
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.