-
Notifications
You must be signed in to change notification settings - Fork 90
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
Targetconfig crd #716
base: main
Are you sure you want to change the base?
Targetconfig crd #716
Conversation
aerosouund
commented
Jan 24, 2025
•
edited
Loading
edited
- Crd definition
- Crd storage
- Informer initialization
- Testing
- Makefile cleanup
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
pkg/config/resolver.go
Outdated
@@ -203,6 +206,27 @@ func (r *Resolver) CustomIDGenerators() map[string]result.IDGenerator { | |||
return generators | |||
} | |||
|
|||
func (r *Resolver) AddTargetConfigEventHandlers() { |
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 should move this into a controller/client struct. The resolver is only to manage dependencies and not this kind of business logic
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 are right, this is me still testing out stuff. The Informer initialization task i have in the description is to mark this exact problem
@@ -40,6 +40,9 @@ func (k *k8sPolicyReportClient) Stop() { | |||
func (k *k8sPolicyReportClient) Sync(stopper chan struct{}) error { | |||
factory := metadatainformer.NewSharedInformerFactory(k.metaClient, 15*time.Minute) | |||
|
|||
// tcInformer := tcinformer.NewSharedInformerFactory(tcv1alpha1.New(&rest.RESTClient{}), time.Second) |
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 assume you wanted to try things out, don't forget to clean everything up again.
pkg/target/collection.go
Outdated
mx *sync.Mutex | ||
clients []Client | ||
targets map[string]*Target | ||
crdTargets map[string]*Target |
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 there a reason to separate crd targets from config targets?
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 wanted to first write out all the flows for storing crd targets separate from the existing config and once everything is figured out merge them. but no, they both can be stored in the same map as i see the map key is just a random uuid
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
the |
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: Ammar Yasser <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
cmd/run.go
Outdated
} else { | ||
k8sConfig, err = rest.InClusterConfig() | ||
} | ||
k8sConfig, err := clientcmd.BuildConfigFromFlags("", "/Users/ammaryasser/Downloads/ips") |
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.
cleanup
// +optional | ||
GCS GCSOptions `json:"gcs,omitempty"` | ||
|
||
TargetType string `json:"targetType,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.
I don't think this is needed, you could make S3 etc. to pointers and check which property is set. You can add a schema validation that only one of this fields can be set and not multiple ones.
pkg/target/factory/factory.go
Outdated
func (f *TargetFactory) CreateSingleClient(tc *v1alpha1.TargetConfig) (*target.Target, error) { | ||
var t *target.Target | ||
switch tc.Spec.TargetType { | ||
case "s3": |
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.
as mentioned I would make S3 etc to pointers and check if they are not nil
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.
Wouldn't this enforce priority on some level ? if the code goes: if s3 isn't nil.. else if slack isn't nil.. etc then for a config that has both (even though this is invalid) it will make it so that s3 takes precedence over whatever. with this field i can treat them all the same and only look at the field set in TargetType
and also it simplifies the validation logic. if a TargetConfig
is of type s3 and the s3 field is nil then its invalid. rather than having "if all the fields are not set then the config is invalid"
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 enforce that only one field is set on the schema, so the API Server will not allow multiple types to be set.
(https://github.com/kyverno/kyverno/blob/main/api/kyverno/v1/common_types.go#L99)
Maybe @JimBugwadia or @eddycharly has an opinion on the TargetType
. I think it should not be more cumbersome if needed. If the user configures the s3
and has to set targetType
might confuse people.
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Pull Request Test Coverage Report for Build 13371519744Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
The TargetConfig "slack-notifier" is invalid:
* spec.slack.certificate: Required value
* spec.slack.channel: Required value
* spec.slack.headers: Required value
* spec.slack.skipTLS: Required value They are optional and should not be required, please check also other targets to ensure that all optional values are correctly configured. |
Slack Notifications for a new resource are published twice |
Following Scenario did not work:
Expected:
TargetConfig: kind: TargetConfig
apiVersion: wgpolicyk8s.io/v1alpha1
metadata:
name: slack-notifier
spec:
targetType: slack
slack:
webhook: https://hooks.slack.com/...
certificate: ""
channel: "kyverno"
headers: {}
skipTLS: false
skipExistingOnStartup: true |
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>
Signed-off-by: aerosouund <[email protected]>