Skip to content

Commit 71626ae

Browse files
committed
NETOBSERV-2418: new FlowCollectorSlice API
1 parent 587b562 commit 71626ae

32 files changed

+1198
-9
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ endif
279279
doc: crdoc ## Generate markdown documentation
280280
$(CRDOC) --resources config/crd/bases/flows.netobserv.io_flowcollectors.yaml --output docs/FlowCollector.md
281281
$(CRDOC) --resources config/crd/bases/flows.netobserv.io_flowmetrics.yaml --output docs/FlowMetric.md
282+
$(CRDOC) --resources config/crd/bases/flows.netobserv.io_flowcollectorslices.yaml --output docs/FlowCollectorSlice.md
282283

283284
# Hack to reintroduce when the API stored version != latest version; see also envtest.go (CRD path config)
284285
# .PHONY: hack-crd-for-test
@@ -288,6 +289,7 @@ doc: crdoc ## Generate markdown documentation
288289
# '(.spec.versions.[]|select(.name != "v1beta2").storage) = false,(.spec.versions.[]|select(.name == "v1beta2").storage) = true' \
289290
# > ./hack/cloned.flows.netobserv.io_flowcollectors.yaml
290291
# cp ./config/crd/bases/flows.netobserv.io_flowmetrics.yaml ./hack/cloned.flows.netobserv.io_flowmetrics.yaml
292+
# cp ./config/crd/bases/flows.netobserv.io_flowcollectorslices.yaml ./hack/cloned.flows.netobserv.io_flowcollectorslices.yaml
291293

292294
generate: gencode manifests doc ## Run all code/file generators
293295

PROJECT

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ resources:
3838
webhooks:
3939
validation: true
4040
webhookVersion: v1
41+
- api:
42+
crdVersion: v1
43+
namespaced: true
44+
domain: netobserv.io
45+
group: flows
46+
kind: FlowCollectorSlice
47+
path: github.com/netobserv/network-observability-operator/api/flowcollectorslice/v1alpha1
48+
version: v1alpha1
4149
version: "3"

api/flowcollector/v1beta2/flowcollector_types.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,10 @@ type FlowCollectorFLP struct {
697697
// but with a lesser improvement in performance.
698698
Filters []FLPFilterSet `json:"filters"`
699699

700+
// Global configuration managing FlowCollectorSlices custom resources.
701+
//+optional
702+
SlicesConfig *SlicesConfig `json:"slicesConfig,omitempty"`
703+
700704
// `advanced` allows setting some aspects of the internal configuration of the flow processor.
701705
// This section is aimed mostly for debugging and fine-grained performance optimizations,
702706
// such as `GOGC` and `GOMAXPROCS` environment variables. Set these values at your own risk.
@@ -787,6 +791,33 @@ type FlowCollectorHPA struct {
787791
Metrics []ascv2.MetricSpec `json:"metrics"`
788792
}
789793

794+
type SliceCollectionMode string
795+
796+
const (
797+
CollectionAlwaysCollect SliceCollectionMode = "AlwaysCollect"
798+
CollectionAllowList SliceCollectionMode = "AllowList"
799+
)
800+
801+
type SlicesConfig struct {
802+
// `enable` determines if the FlowCollectorSlice feature is enabled. If not, all resources of kind FlowCollectorSlice are simply ignored.
803+
//+kubebuilder:default:=false
804+
//+kubebuilder:validation:Required
805+
Enable bool `json:"enable,omitempty"`
806+
807+
// `collectionMode` determines how the FlowCollectorSlice custom resources impacts the flow collection process:<br>
808+
// - When set to `AlwaysCollect`, all flows are collected regardless of the presence of FlowCollectorSlice.<br>
809+
// - When set to `AllowList`, only the flows related to namespaces where a FlowCollectorSlice resource is present, or configured via the global `namespacesAllowList`, are collected.<br>
810+
//+kubebuilder:validation:Enum=AlwaysCollect;AllowList
811+
//+kubebuilder:default:="AlwaysCollect"
812+
CollectionMode SliceCollectionMode `json:"collectionMode,omitempty"`
813+
814+
// `namespacesAllowList` is a list of namespaces for which flows are always collected, regardless of the presence of FlowCollectorSlice in those namespaces.
815+
// An entry enclosed by slashes, such as `/openshift-.*/`, is matched as a regular expression.
816+
// This setting is ignored if `collectionMode` is different from `AllowList`.
817+
//+kubebuilder:validation:optional
818+
NamespacesAllowList []string `json:"namespacesAllowList,omitempty"`
819+
}
820+
790821
type LokiAuthToken string
791822

792823
const (

api/flowcollector/v1beta2/helper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,7 @@ func (spec *FlowCollectorConsolePlugin) IsUnmanagedConsolePluginReplicas() bool
227227
}
228228
return spec.Autoscaler.IsHPAEnabled()
229229
}
230+
231+
func (spec *FlowCollectorSpec) IsSliceEnabled() bool {
232+
return spec.Processor.SlicesConfig != nil && spec.Processor.SlicesConfig.Enable
233+
}

api/flowcollector/v1beta2/zz_generated.deepcopy.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package v1aplha1 contains the v1alpha1 API implementation.
2+
package v1alpha1
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package v1alpha1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// FlowCollectorSliceSpec defines the desired state of FlowCollectorSlice
8+
type FlowCollectorSliceSpec struct {
9+
// `subnetLabels` allows to customize subnets and IPs labelling, such as to identify cluster-external workloads or web services.
10+
// Beware that the subnet labels configured in FlowCollectorSlice are not limited to the flows of the related namespace: any flow
11+
// in the whole cluster can be labelled using this configuration. However, subnet labels defined in the cluster-scoped FlowCollector take
12+
// precedence in case of conflicting rules.
13+
//+optional
14+
SubnetLabels []SubnetLabel `json:"subnetLabels,omitempty"`
15+
16+
// `sampling` is an optional sampling interval to apply to this slice. For example, a value of `50` means that 1 matching flow in 50 is sampled.
17+
//+kubebuilder:validation:Minimum=0
18+
// +optional
19+
Sampling int32 `json:"sampling,omitempty"`
20+
}
21+
22+
// SubnetLabel allows to label subnets and IPs, such as to identify cluster-external workloads or web services.
23+
type SubnetLabel struct {
24+
// List of CIDRs, such as `["1.2.3.4/32"]`.
25+
//+required
26+
CIDRs []string `json:"cidrs,omitempty"` // Note, starting with k8s 1.31 / ocp 4.16 there's a new way to validate CIDR such as `+kubebuilder:validation:XValidation:rule="isCIDR(self)",message="field should be in CIDR notation format"`. But older versions would reject the CRD so we cannot implement it now to maintain compatibility.
27+
// Label name, used to flag matching flows.
28+
//+required
29+
Name string `json:"name,omitempty"`
30+
}
31+
32+
// FlowCollectorSliceStatus defines the observed state of FlowCollectorSlice
33+
type FlowCollectorSliceStatus struct {
34+
// `conditions` represent the latest available observations of an object's state
35+
Conditions []metav1.Condition `json:"conditions"`
36+
}
37+
38+
// +kubebuilder:object:root=true
39+
// +kubebuilder:subresource:status
40+
// FlowMetric is the API allowing to create custom metrics from the collected flow logs.
41+
type FlowCollectorSlice struct {
42+
metav1.TypeMeta `json:",inline"`
43+
metav1.ObjectMeta `json:"metadata,omitempty"`
44+
45+
Spec FlowCollectorSliceSpec `json:"spec,omitempty"`
46+
Status FlowCollectorSliceStatus `json:"status,omitempty"`
47+
}
48+
49+
// +kubebuilder:object:root=true
50+
// FlowCollectorSliceList contains a list of FlowCollectorSlice
51+
type FlowCollectorSliceList struct {
52+
metav1.TypeMeta `json:",inline"`
53+
metav1.ListMeta `json:"metadata,omitempty"`
54+
Items []FlowCollectorSlice `json:"items"`
55+
}
56+
57+
func init() {
58+
SchemeBuilder.Register(&FlowCollectorSlice{}, &FlowCollectorSliceList{})
59+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2021.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1alpha1 contains API Schema definitions for the flows v1alpha1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=flows.netobserv.io
20+
package v1alpha1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "flows.netobserv.io", Version: "v1alpha1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

api/flowcollectorslice/v1alpha1/zz_generated.deepcopy.go

Lines changed: 149 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)