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

add additional function which creates network policy #498

Merged
merged 8 commits into from Apr 19, 2024

Conversation

KPostOffice
Copy link
Collaborator

Issue link

What changes have been made

Verification steps

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • Testing is not required for this change

Copy link

@etirelli etirelli left a 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")
}
Copy link

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)

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?

Copy link
Collaborator Author

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

Copy link

openshift-ci bot commented Apr 3, 2024

@etirelli: changing LGTM is restricted to collaborators

In response to this:

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.

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.

Copy link

openshift-ci bot commented Apr 3, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: etirelli
Once this PR has been reviewed and has the lgtm label, please ask for approval from kpostoffice. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

).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"})),
Copy link
Contributor

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.

Copy link
Contributor

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.

pkg/controllers/raycluster_controller.go Show resolved Hide resolved
pkg/controllers/raycluster_controller.go Show resolved Hide resolved
@KPostOffice KPostOffice force-pushed the rhaoieng-5089 branch 2 times, most recently from 4675a36 to 9791604 Compare April 4, 2024 16:14
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"})),
Copy link
Contributor

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.

Copy link
Contributor

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

// - Or fallback to the well-known defaults
var kubeRayNamespaces []string
dsci := &dsciv1.DSCInitialization{}
err := r.Client.Get(ctx, client.ObjectKey{Name: "default-dsci"}, dsci)
Copy link
Contributor

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.

Copy link
Contributor

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"

@sutaakar
Copy link
Contributor

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))
Copy link
Contributor

@sutaakar sutaakar Apr 15, 2024

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/controller-runtime@v0.15.3/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"

WithMatchExpressions(metav1apply.LabelSelectorRequirement().
WithKey(corev1.LabelMetadataName).
WithOperator(metav1.LabelSelectorOpIn).
WithValues("openshift-user-workload-monitoring"))),
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 that should be openshift-monitoring instead.

Copy link
Contributor

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?

KPostOffice and others added 7 commits April 19, 2024 09:29
Signed-off-by: Kevin <kpostlet@redhat.com>
Signed-off-by: Kevin <kpostlet@redhat.com>
Signed-off-by: Kevin <kpostlet@redhat.com>
Signed-off-by: Kevin <kpostlet@redhat.com>
Signed-off-by: Kevin <kpostlet@redhat.com>
Signed-off-by: Kevin <kpostlet@redhat.com>
Signed-off-by: Kevin <kpostlet@redhat.com>
@astefanutti
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Apr 19, 2024
@astefanutti astefanutti merged commit 07098c0 into project-codeflare:main Apr 19, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants