Skip to content

NETOBSERV-1377: Add controller to deploy netobserv network policy #690

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

Merged
merged 4 commits into from
Aug 1, 2024

Conversation

OlivierCazade
Copy link
Contributor

Description

Add controller to deploy netobserv network policy

Dependencies

n/a

Checklist

If you are not familiar with our processes or don't know what to answer in the list below, let us know in a comment: the maintainers will take care of that.

  • Is this PR backed with a JIRA ticket? If so, make sure it is written as a title prefix (in general, PRs affecting the NetObserv/Network Observability product should be backed with a JIRA ticket - especially if they bring user facing changes).
  • Does this PR require product documentation?
    • If so, make sure the JIRA epic is labelled with "documentation" and provides a description relevant for doc writers, such as use cases or scenarios. Any required step to activate or configure the feature should be documented there, such as new CRD knobs.
  • Does this PR require a product release notes entry?
    • If so, fill in "Release Note Text" in the JIRA.
  • Is there anything else the QE team should know before testing? E.g: configuration changes, environment setup, etc.
    • If so, make sure it is described in the JIRA ticket.
  • QE requirements (check 1 from the list):
    • Standard QE validation, with pre-merge tests unless stated otherwise.
    • Regression tests only (e.g. refactoring with no user-facing change).
    • No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).

@OlivierCazade OlivierCazade force-pushed the network-policy branch 2 times, most recently from bbc161d to ea0cfec Compare June 25, 2024 15:16
Copy link

codecov bot commented Jun 25, 2024

Codecov Report

Attention: Patch coverage is 62.42038% with 59 lines in your changes missing coverage. Please review.

Project coverage is 65.98%. Comparing base (bc0bcef) to head (5a3c92b).
Report is 31 commits behind head on main.

Files Patch % Lines
controllers/networkpolicy/np_objects.go 58.88% 35 Missing and 2 partials ⚠️
...pis/flowcollector/v1beta2/zz_generated.deepcopy.go 43.75% 9 Missing ⚠️
controllers/reconcilers/reconcilers.go 46.66% 8 Missing ⚠️
controllers/networkpolicy/np_controller.go 86.11% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #690      +/-   ##
==========================================
- Coverage   66.60%   65.98%   -0.62%     
==========================================
  Files          70       74       +4     
  Lines        8115     8541     +426     
==========================================
+ Hits         5405     5636     +231     
- Misses       2315     2503     +188     
- Partials      395      402       +7     
Flag Coverage Δ
unittests 65.98% <62.42%> (-0.62%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...s/flowcollector/v1beta1/zz_generated.conversion.go 39.27% <ø> (ø)
apis/flowcollector/v1beta2/flowcollector_types.go 100.00% <ø> (ø)
pkg/manager/manager.go 66.66% <ø> (ø)
pkg/manager/status/status_manager.go 89.47% <ø> (+1.75%) ⬆️
controllers/networkpolicy/np_controller.go 86.11% <86.11%> (ø)
controllers/reconcilers/reconcilers.go 59.39% <46.66%> (-1.62%) ⬇️
...pis/flowcollector/v1beta2/zz_generated.deepcopy.go 42.72% <43.75%> (-1.05%) ⬇️
controllers/networkpolicy/np_objects.go 58.88% <58.88%> (ø)

... and 17 files with indirect coverage changes

NetworkPolicy NetworkPolycy `json:"networkPolicy,omitempty"`
}

type NetworkPolycy struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo :-)

}

type NetworkPolycy struct {
// Set `deploy` to `false` to disable network policy deployment. It is enabled by default.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add more information about what this policy does, such as:

This network policy better isolates the NetObserv components to prevent undesired connections to them. It is recommended to install it.

(or something in that vein)

Also, shouldn't we name that Enable, like we do generally for anything that can be turned on/off ?

// +optional
Deploy *bool `json:"deploy,omitempty"`

// `additionalNamespaces` contains the interface names from where flows are collected. If empty, the agent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I guess it's not the good text here :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention here in particular what users need to care about:

  • If they use Kafka and installed it in a separate namespace, they must add it here
  • Same for any exporter

We can expect users misconfigurations here... Probably something that we'll have to worry about in docs & troubleshooting

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted as something to add to docs :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in @Amoghrd's testing having Loki and Kafka in separate NS didn't turn out to be a problem since this was an Ingress policy and only affecting inbound connections.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks Mehul!

return ctrl.NewControllerManagedBy(mgr).
For(&flowslatest.FlowCollector{}, reconcilers.IgnoreStatusChange).
Named("networkPolicy").
Owns(&corev1.Namespace{}).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Namespace is required here?

client.Client
mgr *manager.Manager
status status.Instance
currentNamespace string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the code it doesn't seem that currentNamespace is useful here

Comment on lines 73 to 86
Advanced: &flowslatest.AdvancedProcessorConfig{
Env: map[string]string{
"GOGC": "200",
},
ConversationHeartbeatInterval: &metav1.Duration{
Duration: conntrackHeartbeatInterval,
},
ConversationEndTimeout: &metav1.Duration{
Duration: conntrackEndTimeout,
},
ConversationTerminatingTimeout: &metav1.Duration{
Duration: conntrackTerminatingTimeout,
},
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think conn-track settings has any use here, right? I guess you can remove them

Copy link
Contributor

@jpinsonneau jpinsonneau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good ! Thanks @OlivierCazade

@Amoghrd
Copy link
Contributor

Amoghrd commented Jul 24, 2024

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Jul 24, 2024
Copy link

New images:

  • quay.io/netobserv/network-observability-operator:8afb9c0
  • quay.io/netobserv/network-observability-operator-bundle:v0.0.0-8afb9c0
  • quay.io/netobserv/network-observability-operator-catalog:v0.0.0-8afb9c0

They will expire after two weeks.

To deploy this build:

# Direct deployment, from operator repo
IMAGE=quay.io/netobserv/network-observability-operator:8afb9c0 make deploy

# Or using operator-sdk
operator-sdk run bundle quay.io/netobserv/network-observability-operator-bundle:v0.0.0-8afb9c0

Or as a Catalog Source:

apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
  name: netobserv-dev
  namespace: openshift-marketplace
spec:
  sourceType: grpc
  image: quay.io/netobserv/network-observability-operator-catalog:v0.0.0-8afb9c0
  displayName: NetObserv development catalog
  publisher: Me
  updateStrategy:
    registryPoll:
      interval: 1m

@Amoghrd
Copy link
Contributor

Amoghrd commented Jul 24, 2024

@OlivierCazade networkPolicy seems to be disabled by default
Screenshot 2024-07-24 at 3 21 41 PM

@@ -30,6 +30,7 @@ import (
//+kubebuilder:rbac:groups=monitoring.coreos.com,resources=servicemonitors;prometheusrules,verbs=get;create;delete;update;patch;list;watch
//+kubebuilder:rbac:groups=config.openshift.io,resources=clusterversions;networks,verbs=get;list;watch
//+kubebuilder:rbac:groups=loki.grafana.com,resources=network,resourceNames=logs,verbs=get;create
//+kubebuilder:rbac:groups=networking.k8s.io,resources=networkpolicies,verbs=get;list;watch;create;update
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete is missing here; and I'd also add patch, just in case (we never know exactly what the controller-runtime client does under the cover)

Suggested change
//+kubebuilder:rbac:groups=networking.k8s.io,resources=networkpolicies,verbs=get;list;watch;create;update
//+kubebuilder:rbac:groups=networking.k8s.io,resources=networkpolicies,verbs=get;list;watch;create;update;patch;delete

- Add DELETE and PATCH roles to operator
- Make additionalNamespaces only affect the main namespace
- Add allowed namespaces based on context knowledge (is openshift? is
  console enabled? etc.)
- Add port restriction for console access
@openshift-ci openshift-ci bot removed the lgtm label Jul 25, 2024
@github-actions github-actions bot removed the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Jul 25, 2024
@jotak
Copy link
Member

jotak commented Jul 26, 2024

hey @Amoghrd I think this is ok to test
/lgtm

@openshift-ci openshift-ci bot added the lgtm label Jul 26, 2024
@jotak jotak changed the title NETOBSERV-1377 Add controller to deploy netobserv network policy NETOBSERV-1377: Add controller to deploy netobserv network policy Jul 26, 2024
@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented Jul 26, 2024

@OlivierCazade: This pull request references NETOBSERV-1377 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.17.0" version, but no target version was set.

In response to this:

Description

Add controller to deploy netobserv network policy

Dependencies

n/a

Checklist

If you are not familiar with our processes or don't know what to answer in the list below, let us know in a comment: the maintainers will take care of that.

  • Is this PR backed with a JIRA ticket? If so, make sure it is written as a title prefix (in general, PRs affecting the NetObserv/Network Observability product should be backed with a JIRA ticket - especially if they bring user facing changes).
  • Does this PR require product documentation?
  • If so, make sure the JIRA epic is labelled with "documentation" and provides a description relevant for doc writers, such as use cases or scenarios. Any required step to activate or configure the feature should be documented there, such as new CRD knobs.
  • Does this PR require a product release notes entry?
  • If so, fill in "Release Note Text" in the JIRA.
  • Is there anything else the QE team should know before testing? E.g: configuration changes, environment setup, etc.
  • If so, make sure it is described in the JIRA ticket.
  • QE requirements (check 1 from the list):
  • Standard QE validation, with pre-merge tests unless stated otherwise.
  • Regression tests only (e.g. refactoring with no user-facing change).
  • No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).

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 openshift-eng/jira-lifecycle-plugin repository.

@Amoghrd
Copy link
Contributor

Amoghrd commented Jul 26, 2024

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Jul 26, 2024
Copy link

New images:

  • quay.io/netobserv/network-observability-operator:e618cc3
  • quay.io/netobserv/network-observability-operator-bundle:v0.0.0-e618cc3
  • quay.io/netobserv/network-observability-operator-catalog:v0.0.0-e618cc3

They will expire after two weeks.

To deploy this build:

# Direct deployment, from operator repo
IMAGE=quay.io/netobserv/network-observability-operator:e618cc3 make deploy

# Or using operator-sdk
operator-sdk run bundle quay.io/netobserv/network-observability-operator-bundle:v0.0.0-e618cc3

Or as a Catalog Source:

apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
  name: netobserv-dev
  namespace: openshift-marketplace
spec:
  sourceType: grpc
  image: quay.io/netobserv/network-observability-operator-catalog:v0.0.0-e618cc3
  displayName: NetObserv development catalog
  publisher: Me
  updateStrategy:
    registryPoll:
      interval: 1m

@Amoghrd
Copy link
Contributor

Amoghrd commented Jul 31, 2024

/label qe-approved

@openshift-ci openshift-ci bot added the qe-approved QE has approved this pull request label Jul 31, 2024
@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented Jul 31, 2024

@OlivierCazade: This pull request references NETOBSERV-1377 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.17.0" version, but no target version was set.

In response to this:

Description

Add controller to deploy netobserv network policy

Dependencies

n/a

Checklist

If you are not familiar with our processes or don't know what to answer in the list below, let us know in a comment: the maintainers will take care of that.

  • Is this PR backed with a JIRA ticket? If so, make sure it is written as a title prefix (in general, PRs affecting the NetObserv/Network Observability product should be backed with a JIRA ticket - especially if they bring user facing changes).
  • Does this PR require product documentation?
  • If so, make sure the JIRA epic is labelled with "documentation" and provides a description relevant for doc writers, such as use cases or scenarios. Any required step to activate or configure the feature should be documented there, such as new CRD knobs.
  • Does this PR require a product release notes entry?
  • If so, fill in "Release Note Text" in the JIRA.
  • Is there anything else the QE team should know before testing? E.g: configuration changes, environment setup, etc.
  • If so, make sure it is described in the JIRA ticket.
  • QE requirements (check 1 from the list):
  • Standard QE validation, with pre-merge tests unless stated otherwise.
  • Regression tests only (e.g. refactoring with no user-facing change).
  • No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).

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 openshift-eng/jira-lifecycle-plugin repository.

Copy link
Member

@memodi memodi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we clarify its the Ingress policy that it deploys?

@openshift-ci openshift-ci bot removed the lgtm label Aug 1, 2024
@github-actions github-actions bot removed the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Aug 1, 2024
@jotak
Copy link
Member

jotak commented Aug 1, 2024

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm label Aug 1, 2024
Copy link

openshift-ci bot commented Aug 1, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jotak

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

@openshift-ci openshift-ci bot added the approved label Aug 1, 2024
Copy link

openshift-ci bot commented Aug 1, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jotak

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

@openshift-merge-bot openshift-merge-bot bot merged commit d14d142 into netobserv:main Aug 1, 2024
8 of 9 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.

7 participants