-
Notifications
You must be signed in to change notification settings - Fork 61
add additional function which creates network policy #498
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
add additional function which creates network policy #498
Conversation
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 am approving it, but please take a look at my comment. It seems strange to log the error but not return a failure in the reconciliation.
_, err = r.kubeClient.NetworkingV1().NetworkPolicies(cluster.Namespace).Apply(ctx, desiredNetworkPolicy(&cluster), metav1.ApplyOptions{FieldManager: controllerName, Force: true}) | ||
if err != nil { | ||
logger.Error(err, "Failed to update NetworkPolicy") | ||
} |
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.
shouldn't the error be returned? I see the same is done for the previous objects (ClusterRoleBindings, ServiceAccounts, etc)
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 reviewing this and maybe the comment got moved around but was this addressed?
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 was planning to open another PR that fixes all the instances of this issue once this is merged
@etirelli: changing LGTM is restricted to collaborators In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: etirelli The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
).WithFrom( | ||
networkingapply.NetworkPolicyPeer().WithPodSelector(metav1apply.LabelSelector(). | ||
WithMatchLabels(map[string]string{"app.kubernetes.io/component": "kuberay-operator"})). | ||
WithNamespaceSelector(metav1apply.LabelSelector().WithMatchLabels(map[string]string{"kubernetes.io/metadata.name": "redhat-ods-applications"})), |
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.
We need to expand the list of namespaces where ODH / RHOAI are known to be deployed, e.g. opendatahub
.
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 possible, the DSCInitialization
resource should be get to read the .spec.applicationsNamespace
field.
4675a36
to
9791604
Compare
networkingapply.NetworkPolicyIngressRule().WithFrom( | ||
networkingapply.NetworkPolicyPeer().WithPodSelector(metav1apply.LabelSelector(). | ||
WithMatchLabels(map[string]string{"app.kubernetes.io/component": "kuberay-operator"})). | ||
WithNamespaceSelector(metav1apply.LabelSelector().WithMatchLabels(map[string]string{"opendatahub.io/generated-namespace": "true"})), |
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 relying on the opendatahub.io/generated-namespace
label is correct. The ingress traffic should be allowed from the ODH / RHOAI application namespace. So it should either be sourced from the DSCInitilization resource, or defaulted to the well-known namespaces.
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.
should we hardcode it opendatahub
for ODH and redhat-ods-applications
for RHOAI to simplify the logic for now?
and think about how to get it from DSCI later?
i mentioned it in another thread, operator does make this namespace configurable, but unlikely in ODH user will change the default value
9791604
to
950d7a6
Compare
950d7a6
to
e2dface
Compare
// - Or fallback to the well-known defaults | ||
var kubeRayNamespaces []string | ||
dsci := &dsciv1.DSCInitialization{} | ||
err := r.Client.Get(ctx, client.ObjectKey{Name: "default-dsci"}, dsci) |
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 you load DSCI without hardcoding name? This will make code more resilient for possible naming changes.
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.
default-dsci is the one created by ODH/RHOAI operator.
99% case i would expect it is using this name, but ofc if user tried to create CR by themselves, that will do.
for the time being, we could hardcode with this name.
a follow up PR can add more logic "check CR, get name, set here"
It would be good to provide a component test coverage, though may be added as separate PR. |
main.go
Outdated
@@ -70,6 +71,8 @@ func init() { | |||
utilruntime.Must(rayv1.AddToScheme(scheme)) | |||
// OpenShift Route | |||
utilruntime.Must(routev1.Install(scheme)) | |||
// ODH | |||
utilruntime.Must(odhv1.AddToScheme(scheme)) |
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.
Got error when testing this code for RHOAI:
2024-04-15T13:11:03+02:00 ERROR Reconciler error {"controller": "codeflare-raycluster-controller", "controllerGroup": "ray.io", "controllerKind": "RayCluster", "RayCluster": {"name":"jobtest","namespace":"ksuta-test"}, "namespace": "ksuta-test", "name": "jobtest", "reconcileID": "3f44de47-9706-40d1-a470-62a4db9869dc", "error": "no kind is registered for the type v1.DSCInitialization in scheme \"pkg/runtime/scheme.go:100\""}
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
/home/ksuta/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:324
Was able to fix it by using scheme from dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
7c6cbc9
to
3086d1a
Compare
3086d1a
to
827545d
Compare
827545d
to
b94c3c4
Compare
0969607
to
fc84c9c
Compare
WithMatchExpressions(metav1apply.LabelSelectorRequirement(). | ||
WithKey(corev1.LabelMetadataName). | ||
WithOperator(metav1.LabelSelectorOpIn). | ||
WithValues("openshift-user-workload-monitoring"))), |
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 that should be openshift-monitoring
instead.
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.
does SRE monitoring need access redhat-ods-applications (your ray controller) ? or this is for UWM?
e1ab362
to
416a9a2
Compare
416a9a2
to
c9d028b
Compare
Signed-off-by: Kevin <[email protected]>
Signed-off-by: Kevin <[email protected]>
Signed-off-by: Kevin <[email protected]>
Signed-off-by: Kevin <[email protected]>
Signed-off-by: Kevin <[email protected]>
Signed-off-by: Kevin <[email protected]>
c9d028b
to
b0c2116
Compare
Signed-off-by: Kevin <[email protected]>
b0c2116
to
53ee2f2
Compare
/lgtm |
Issue link
What changes have been made
Verification steps
Checks