-
Notifications
You must be signed in to change notification settings - Fork 252
NETOBSERV-2486: Add Network Observability Operator support #8729
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
Open
jpinsonneau
wants to merge
7
commits into
openshift:master
Choose a base branch
from
jpinsonneau:netobserv
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75323b3
Add Network Observability Operator support
jpinsonneau a6ab28c
fix namespace template
jpinsonneau 63e2e3c
addressing nitpicking feedback
jpinsonneau 852cb94
clarify comment
jpinsonneau 0dca9a9
fixed unsafe type and YAML parsing assertions
jpinsonneau ed87330
addressing nitpicking feedback
jpinsonneau a0bda85
lint
jpinsonneau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
internal/operators/networkobservability/networkobservability_config.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package networkobservability | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| ) | ||
|
|
||
| const ( | ||
| Name = "network-observability" | ||
| FullName = "Network Observability Operator" | ||
| Namespace = "openshift-netobserv-operator" | ||
| SubscriptionName = "network-observability-operator" | ||
| Source = "redhat-operators" | ||
| SourceName = "netobserv-operator" | ||
| GroupName = "netobserv-operatorgroup" | ||
| ) | ||
|
|
||
| // Config holds the configuration for Network Observability Operator | ||
| type Config struct { | ||
| // CreateFlowCollector indicates whether to create a FlowCollector resource | ||
| CreateFlowCollector bool `json:"createFlowCollector,omitempty"` | ||
| // Sampling rate for eBPF agent (default: 50) | ||
| Sampling int `json:"sampling,omitempty"` | ||
| } | ||
|
|
||
| // ParseProperties parses the properties JSON string into a Config struct | ||
| func ParseProperties(properties string) (*Config, error) { | ||
| config := &Config{ | ||
| CreateFlowCollector: false, // Default: don't create FlowCollector | ||
| Sampling: 50, // Default sampling rate | ||
| } | ||
|
|
||
| if properties == "" { | ||
| return config, nil | ||
| } | ||
|
|
||
| if err := json.Unmarshal([]byte(properties), config); err != nil { | ||
| return nil, fmt.Errorf("failed to parse network-observability properties: %w", err) | ||
| } | ||
|
|
||
| // Validate sampling rate | ||
| if config.Sampling <= 0 { | ||
| config.Sampling = 50 | ||
| } | ||
|
|
||
| return config, nil | ||
| } |
199 changes: 199 additions & 0 deletions
199
internal/operators/networkobservability/networkobservability_manifests_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| package networkobservability | ||
|
|
||
| import ( | ||
| . "github.com/onsi/ginkgo" | ||
| . "github.com/onsi/gomega" | ||
| "github.com/openshift/assisted-service/internal/common" | ||
| "github.com/openshift/assisted-service/models" | ||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| var _ = Describe("Network Observability manifest generation", func() { | ||
| var ( | ||
| cluster *common.Cluster | ||
| operator *operator | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| cluster = &common.Cluster{ | ||
| Cluster: models.Cluster{ | ||
| OpenshiftVersion: "4.12.0", | ||
| }, | ||
| } | ||
| operator = NewNetworkObservabilityOperator(common.GetTestLog()) | ||
| }) | ||
|
|
||
| It("Generates the required manifests", func() { | ||
| manifests, customManifest, err := operator.GenerateManifests(cluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| Expect(manifests).To(HaveLen(3)) | ||
| Expect(manifests).To(HaveKey("50_openshift-network-observability_ns.yaml")) | ||
| Expect(manifests).To(HaveKey("50_openshift-network-observability_subscription.yaml")) | ||
| Expect(manifests).To(HaveKey("50_openshift-network-observability_operator_group.yaml")) | ||
| // When FlowCollector is not created, customManifest may contain only YAML separators | ||
| Expect(string(customManifest)).To(Or(BeEmpty(), MatchRegexp(`^---\s*$`))) | ||
| }) | ||
|
|
||
| It("Generates valid YAML for OpenShift manifests", func() { | ||
| openShiftManifests, _, err := operator.GenerateManifests(cluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| for _, openShiftManifest := range openShiftManifests { | ||
| var object interface{} | ||
| err = yaml.Unmarshal(openShiftManifest, &object) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| } | ||
| }) | ||
|
|
||
| It("Namespace manifest has correct content", func() { | ||
| manifests, _, err := operator.GenerateManifests(cluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| nsManifest := manifests["50_openshift-network-observability_ns.yaml"] | ||
| var nsData map[string]interface{} | ||
| err = yaml.Unmarshal(nsManifest, &nsData) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| metadata := nsData["metadata"].(map[string]interface{}) | ||
| Expect(metadata["name"]).To(Equal(Namespace)) | ||
| }) | ||
|
|
||
| It("Subscription manifest has correct content", func() { | ||
| manifests, _, err := operator.GenerateManifests(cluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| subManifest := manifests["50_openshift-network-observability_subscription.yaml"] | ||
| var subData map[string]interface{} | ||
| err = yaml.Unmarshal(subManifest, &subData) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| metadata := subData["metadata"].(map[string]interface{}) | ||
| Expect(metadata["name"]).To(Equal(SubscriptionName)) | ||
| Expect(metadata["namespace"]).To(Equal(Namespace)) | ||
|
|
||
| spec := subData["spec"].(map[string]interface{}) | ||
| Expect(spec["channel"]).To(Equal("stable")) | ||
| Expect(spec["name"]).To(Equal(SourceName)) | ||
| Expect(spec["source"]).To(Equal(Source)) | ||
| Expect(spec["sourceNamespace"]).To(Equal("openshift-marketplace")) | ||
| }) | ||
|
|
||
| It("OperatorGroup manifest has correct content", func() { | ||
| manifests, _, err := operator.GenerateManifests(cluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| ogManifest := manifests["50_openshift-network-observability_operator_group.yaml"] | ||
| var ogData map[string]interface{} | ||
| err = yaml.Unmarshal(ogManifest, &ogData) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| metadata := ogData["metadata"].(map[string]interface{}) | ||
| Expect(metadata["name"]).To(Equal(GroupName)) | ||
| Expect(metadata["namespace"]).To(Equal(Namespace)) | ||
| }) | ||
|
|
||
| Context("FlowCollector generation", func() { | ||
| It("Does not generate FlowCollector when createFlowCollector is false", func() { | ||
| cluster.MonitoredOperators = []*models.MonitoredOperator{ | ||
| { | ||
| Name: Name, | ||
| Properties: `{"createFlowCollector": false}`, | ||
| }, | ||
| } | ||
|
|
||
| manifests, customManifest, err := operator.GenerateManifests(cluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| Expect(manifests).To(HaveLen(3)) | ||
| // When FlowCollector is not created, customManifest may contain only YAML separators | ||
| Expect(string(customManifest)).To(Or(BeEmpty(), MatchRegexp(`^---\s*$`))) | ||
| }) | ||
|
|
||
| It("Generates FlowCollector when createFlowCollector is true", func() { | ||
| cluster.MonitoredOperators = []*models.MonitoredOperator{ | ||
| { | ||
| Name: Name, | ||
| Properties: `{"createFlowCollector": true, "sampling": 100}`, | ||
| }, | ||
| } | ||
|
|
||
| manifests, customManifest, err := operator.GenerateManifests(cluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| Expect(manifests).To(HaveLen(3)) | ||
| Expect(customManifest).ToNot(BeEmpty()) | ||
|
|
||
| // Parse the custom manifest (it's a multi-document YAML) | ||
| var flowCollectorData map[string]interface{} | ||
| err = yaml.Unmarshal(customManifest, &flowCollectorData) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| Expect(flowCollectorData["kind"]).To(Equal("FlowCollector")) | ||
| metadata := flowCollectorData["metadata"].(map[string]interface{}) | ||
| Expect(metadata["name"]).To(Equal("cluster")) | ||
| Expect(metadata["namespace"]).To(Equal("netobserv")) | ||
|
|
||
| spec := flowCollectorData["spec"].(map[string]interface{}) | ||
| agent := spec["agent"].(map[string]interface{}) | ||
| ebpf := agent["ebpf"].(map[string]interface{}) | ||
| Expect(ebpf["sampling"]).To(Equal(100)) | ||
|
|
||
| loki := spec["loki"].(map[string]interface{}) | ||
| Expect(loki["enabled"]).To(Equal(false)) | ||
| }) | ||
|
|
||
| It("Uses default values when properties are not provided", func() { | ||
| cluster.MonitoredOperators = []*models.MonitoredOperator{ | ||
| { | ||
| Name: Name, | ||
| Properties: `{"createFlowCollector": true}`, | ||
| }, | ||
| } | ||
|
|
||
| _, customManifest, err := operator.GenerateManifests(cluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| Expect(customManifest).ToNot(BeEmpty()) | ||
|
|
||
| var flowCollectorData map[string]interface{} | ||
| err = yaml.Unmarshal(customManifest, &flowCollectorData) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| spec := flowCollectorData["spec"].(map[string]interface{}) | ||
| agent := spec["agent"].(map[string]interface{}) | ||
| ebpf := agent["ebpf"].(map[string]interface{}) | ||
| Expect(ebpf["sampling"]).To(Equal(50)) // Default value | ||
|
|
||
| loki := spec["loki"].(map[string]interface{}) | ||
| Expect(loki["enabled"]).To(Equal(false)) // Always false | ||
| }) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
|
|
||
| Context("Config parsing", func() { | ||
| It("Handles invalid JSON properties gracefully", func() { | ||
| cluster.MonitoredOperators = []*models.MonitoredOperator{ | ||
| { | ||
| Name: Name, | ||
| Properties: `{"invalid": json}`, | ||
| }, | ||
| } | ||
|
|
||
| manifests, customManifest, err := operator.GenerateManifests(cluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| Expect(manifests).To(HaveLen(3)) | ||
| // When FlowCollector is not created, customManifest may contain only YAML separators | ||
| Expect(string(customManifest)).To(Or(BeEmpty(), MatchRegexp(`^---\s*$`))) | ||
| }) | ||
|
|
||
| It("Handles empty properties", func() { | ||
| cluster.MonitoredOperators = []*models.MonitoredOperator{ | ||
| { | ||
| Name: Name, | ||
| Properties: "", | ||
| }, | ||
| } | ||
|
|
||
| manifests, customManifest, err := operator.GenerateManifests(cluster) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| Expect(manifests).To(HaveLen(3)) | ||
| // When FlowCollector is not created, customManifest may contain only YAML separators | ||
| Expect(string(customManifest)).To(Or(BeEmpty(), MatchRegexp(`^---\s*$`))) | ||
| }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.