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

NETOBSERV-764 - ADD v1beta2 api version with simplified Loki configuration options #329

Merged
merged 17 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .mk/sample.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
deploy-sample-cr:
@echo -e "\n==> Deploy sample CR"
ifeq (main,$(VERSION))
kubectl apply -f ./config/samples/flows_v1beta1_flowcollector.yaml || true
kubectl apply -f ./config/samples/flows_v1beta2_flowcollector.yaml || true
else
kubectl apply -f ./config/samples/flows_v1beta1_flowcollector_versioned.yaml || true
kubectl apply -f ./config/samples/flows_v1beta2_flowcollector_versioned.yaml || true
endif

# Undeploy the sample FlowCollector CR
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,15 @@ doc: crdoc ## Generate markdown documentation
$(CRDOC) --resources config/crd/bases/flows.netobserv.io_flowcollectors.yaml --output docs/FlowCollector.md

generate-go-conversions: $(CONVERSION_GEN) ## Run all generate-go-conversions
$(MAKE) clean-generated-conversions SRC_DIRS="./api/v1alpha1"
$(MAKE) clean-generated-conversions SRC_DIRS="./api/v1alpha1 ./api/v1beta1 ./api/v1beta2"
jpinsonneau marked this conversation as resolved.
Show resolved Hide resolved
$(CONVERSION_GEN) \
--input-dirs=./api/v1alpha1 \
--input-dirs=./api/v1beta1 \
--input-dirs=./api/v1beta2 \
--build-tag=ignore_autogenerated_core \
--output-file-base=zz_generated.conversion \
$(CONVERSION_GEN_OUTPUT_BASE) \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt

generate: gencode manifests doc generate-go-conversions ## Run all code/file generators

Expand Down
4 changes: 2 additions & 2 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ resources:
domain: netobserv.io
group: flows
kind: FlowCollector
path: github.com/netobserv/network-observability-operator/api/v1beta1
version: v1beta1
path: github.com/netobserv/network-observability-operator/api/v1beta2
version: v1beta2
webhooks:
conversion: true
webhookVersion: v1
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ To deploy the monitoring pipeline, this `make` target installs a `FlowCollector`
make deploy-sample-cr
```

Alternatively, you can [grab and edit](./config/samples/flows_v1beta1_flowcollector.yaml) this config before installing it.
Alternatively, you can [grab and edit](./config/samples/flows_v1beta2_flowcollector.yaml) this config before installing it.

You can still edit the `FlowCollector` after it's installed: the operator will take care about reconciling everything with the updated configuration:

Expand All @@ -61,7 +61,7 @@ To deploy a specific version of the operator, you need to switch to the related
```bash
git checkout 0.1.2
VERSION=0.1.2 make deploy deploy-loki deploy-grafana
kubectl apply -f ./config/samples/flows_v1beta1_flowcollector_versioned.yaml
kubectl apply -f ./config/samples/flows_v1beta2_flowcollector_versioned.yaml
```

Beware that the version of the underlying components, such as flowlogs-pipeline, may be tied to the version of the operator (this is why we recommend switching the git branch). Breaking this correlation may result in crashes. The versions of the underlying components are defined in the `FlowCollector` resource as image tags.
Expand Down Expand Up @@ -110,7 +110,7 @@ To get dashboards, import [this file](./config/samples/dashboards/Network%20Obse

## Configuration

The `FlowCollector` resource is used to configure the operator and its managed components. A comprehensive documentation is [available here](./docs/FlowCollector.md), and a full sample file [there](./config/samples/flows_v1beta1_flowcollector.yaml).
The `FlowCollector` resource is used to configure the operator and its managed components. A comprehensive documentation is [available here](./docs/FlowCollector.md), and a full sample file [there](./config/samples/flows_v1beta2_flowcollector.yaml).

To edit configuration in cluster, run:

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ limitations under the License.
*/

// Package v1aplha1 contains the v1alpha1 API implementation.
// +k8s:conversion-gen=github.com/netobserv/network-observability-operator/api/v1beta1
// +k8s:conversion-gen=github.com/netobserv/network-observability-operator/api/v1beta2
package v1alpha1
1 change: 1 addition & 0 deletions api/v1alpha1/flowcollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type FlowCollectorSpec struct {
Processor FlowCollectorFLP `json:"processor,omitempty"`

// loki, the flow store, client settings.
// +k8s:conversion-gen=false
jpinsonneau marked this conversation as resolved.
Show resolved Hide resolved
Loki FlowCollectorLoki `json:"loki,omitempty"`

// consolePlugin defines the settings related to the OpenShift Console plugin, when available.
Expand Down
117 changes: 68 additions & 49 deletions api/v1alpha1/flowcollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,63 +20,75 @@ import (
"fmt"
"reflect"

"github.com/netobserv/network-observability-operator/api/v1beta1"
"github.com/netobserv/network-observability-operator/api/v1beta2"
utilconversion "github.com/netobserv/network-observability-operator/pkg/conversion"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apiconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

// ConvertTo converts this v1alpha1 FlowCollector to its v1beta1 equivalent (the conversion Hub)
// ConvertTo converts this v1alpha1 FlowCollector to its v1beta2 equivalent (the conversion Hub)
// https://book.kubebuilder.io/multiversion-tutorial/conversion.html
func (r *FlowCollector) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta1.FlowCollector)
dst := dstRaw.(*v1beta2.FlowCollector)

if err := Convert_v1alpha1_FlowCollector_To_v1beta1_FlowCollector(r, dst, nil); err != nil {
return fmt.Errorf("copying v1alpha1.FlowCollector into v1beta1.FlowCollector: %w", err)
if err := Convert_v1alpha1_FlowCollector_To_v1beta2_FlowCollector(r, dst, nil); err != nil {
return fmt.Errorf("copying v1alpha1.FlowCollector into v1beta2.FlowCollector: %w", err)
}
dst.Status.Conditions = make([]v1.Condition, len(r.Status.Conditions))
copy(dst.Status.Conditions, r.Status.Conditions)

// Manually restore data.
restored := &v1beta1.FlowCollector{}
restored := &v1beta2.FlowCollector{}
if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
// fallback on current loki config as Manual mode if metadata are not available
dst.Spec.Loki.Mode = v1beta2.LokiModeManual
dst.Spec.Loki.Manual.IngesterURL = r.Spec.Loki.URL
dst.Spec.Loki.Manual.QuerierURL = r.Spec.Loki.QuerierURL
dst.Spec.Loki.Manual.StatusURL = r.Spec.Loki.StatusURL
dst.Spec.Loki.Manual.TenantID = r.Spec.Loki.TenantID
dst.Spec.Loki.Manual.AuthToken = r.Spec.Loki.AuthToken
if err := Convert_v1alpha1_ClientTLS_To_v1beta2_ClientTLS(&r.Spec.Loki.TLS, &dst.Spec.Loki.Manual.TLS, nil); err != nil {
return fmt.Errorf("copying v1alplha1.Loki.TLS into v1beta2.Loki.Manual.TLS: %w", err)
}
Copy link
Contributor

@msherif1234 msherif1234 Oct 2, 2023

Choose a reason for hiding this comment

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

why would the metadata not been added to the annotation in reality this shouldn't happen do u saw issues ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I had issues when the storage was on v1beta2 🤔
Let's see if I can remove these now that the storage is on v1beta1

Copy link
Contributor

Choose a reason for hiding this comment

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

I confirm we still need these pieces for the first deployment.
You can reproduce by deploying the operator and applying flows_v1alpha1_flowcollector.yaml with a custom loki url from scratch (no existing CR instance).

Without this part of code we lost the custom url and it fallback to its default since the field was moved from spec.loki.url to spec.loki.manual.url.

return err
}

dst.Spec.Processor.LogTypes = restored.Spec.Processor.LogTypes
// Agent
if restored.Spec.Agent.EBPF.Features != nil {
dst.Spec.Agent.EBPF.Features = make([]v1beta2.AgentFeature, len(restored.Spec.Agent.EBPF.Features))
copy(dst.Spec.Agent.EBPF.Features, restored.Spec.Agent.EBPF.Features)
}

// Processor
dst.Spec.Processor.LogTypes = restored.Spec.Processor.LogTypes
if restored.Spec.Processor.ConversationHeartbeatInterval != nil {
dst.Spec.Processor.ConversationHeartbeatInterval = restored.Spec.Processor.ConversationHeartbeatInterval
}

if restored.Spec.Processor.ConversationEndTimeout != nil {
dst.Spec.Processor.ConversationEndTimeout = restored.Spec.Processor.ConversationEndTimeout
}

if restored.Spec.Processor.ConversationTerminatingTimeout != nil {
dst.Spec.Processor.ConversationTerminatingTimeout = restored.Spec.Processor.ConversationTerminatingTimeout
}

if restored.Spec.Processor.Metrics.DisableAlerts != nil {
dst.Spec.Processor.Metrics.DisableAlerts = restored.Spec.Processor.Metrics.DisableAlerts
}
dst.Spec.Processor.Metrics.Server.TLS.InsecureSkipVerify = restored.Spec.Processor.Metrics.Server.TLS.InsecureSkipVerify
dst.Spec.Processor.Metrics.Server.TLS.ProvidedCaFile = restored.Spec.Processor.Metrics.Server.TLS.ProvidedCaFile

dst.Spec.Loki.Enable = restored.Spec.Loki.Enable

if restored.Spec.Agent.EBPF.Features != nil {
dst.Spec.Agent.EBPF.Features = make([]v1beta1.AgentFeature, len(restored.Spec.Agent.EBPF.Features))
copy(dst.Spec.Agent.EBPF.Features, restored.Spec.Agent.EBPF.Features)
}

dst.Spec.Loki.StatusTLS = restored.Spec.Loki.StatusTLS
// Kafka
dst.Spec.Kafka.SASL = restored.Spec.Kafka.SASL

dst.Spec.ConsolePlugin.Enable = restored.Spec.ConsolePlugin.Enable

dst.Spec.Processor.Metrics.Server.TLS.InsecureSkipVerify = restored.Spec.Processor.Metrics.Server.TLS.InsecureSkipVerify
dst.Spec.Processor.Metrics.Server.TLS.ProvidedCaFile = restored.Spec.Processor.Metrics.Server.TLS.ProvidedCaFile
// Loki
dst.Spec.Loki.Enable = restored.Spec.Loki.Enable
dst.Spec.Loki.Mode = restored.Spec.Loki.Mode
dst.Spec.Loki.Manual = restored.Spec.Loki.Manual
if restored.Spec.Loki.LokiStack != nil {
dst.Spec.Loki.LokiStack = restored.Spec.Loki.LokiStack
}

// Exporters
if restored.Spec.Exporters != nil {
for _, restoredExp := range restored.Spec.Exporters {
if !isExporterIn(restoredExp, dst.Spec.Exporters) {
Expand All @@ -88,7 +100,7 @@ func (r *FlowCollector) ConvertTo(dstRaw conversion.Hub) error {
return nil
}

func isExporterIn(restoredExporter *v1beta1.FlowCollectorExporter, dstExporters []*v1beta1.FlowCollectorExporter) bool {
func isExporterIn(restoredExporter *v1beta2.FlowCollectorExporter, dstExporters []*v1beta2.FlowCollectorExporter) bool {

for _, dstExp := range dstExporters {
if reflect.DeepEqual(restoredExporter, dstExp) {
Expand All @@ -98,12 +110,12 @@ func isExporterIn(restoredExporter *v1beta1.FlowCollectorExporter, dstExporters
return false
}

// ConvertFrom converts the hub version v1beta1 FlowCollector object to v1alpha1
// ConvertFrom converts the hub version v1beta2 FlowCollector object to v1alpha1
func (r *FlowCollector) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta1.FlowCollector)
src := srcRaw.(*v1beta2.FlowCollector)

if err := Convert_v1beta1_FlowCollector_To_v1alpha1_FlowCollector(src, r, nil); err != nil {
return fmt.Errorf("copying v1beta1.FlowCollector into v1alpha1.FlowCollector: %w", err)
if err := Convert_v1beta2_FlowCollector_To_v1alpha1_FlowCollector(src, r, nil); err != nil {
return fmt.Errorf("copying v1beta2.FlowCollector into v1alpha1.FlowCollector: %w", err)
}
r.Status.Conditions = make([]v1.Condition, len(src.Status.Conditions))
copy(r.Status.Conditions, src.Status.Conditions)
Expand All @@ -113,60 +125,67 @@ func (r *FlowCollector) ConvertFrom(srcRaw conversion.Hub) error {
}

func (r *FlowCollectorList) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta1.FlowCollectorList)
return Convert_v1alpha1_FlowCollectorList_To_v1beta1_FlowCollectorList(r, dst, nil)
dst := dstRaw.(*v1beta2.FlowCollectorList)
return Convert_v1alpha1_FlowCollectorList_To_v1beta2_FlowCollectorList(r, dst, nil)
}

func (r *FlowCollectorList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta1.FlowCollectorList)
return Convert_v1beta1_FlowCollectorList_To_v1alpha1_FlowCollectorList(src, r, nil)
src := srcRaw.(*v1beta2.FlowCollectorList)
return Convert_v1beta2_FlowCollectorList_To_v1alpha1_FlowCollectorList(src, r, nil)
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta1 not in v1alpha1
// we have new defined fields in v1beta2 not in v1alpha1
// nolint:golint,stylecheck,revive
func Convert_v1beta1_FlowCollectorFLP_To_v1alpha1_FlowCollectorFLP(in *v1beta1.FlowCollectorFLP, out *FlowCollectorFLP, s apiconversion.Scope) error {
return autoConvert_v1beta1_FlowCollectorFLP_To_v1alpha1_FlowCollectorFLP(in, out, s)
func Convert_v1beta2_FlowCollectorFLP_To_v1alpha1_FlowCollectorFLP(in *v1beta2.FlowCollectorFLP, out *FlowCollectorFLP, s apiconversion.Scope) error {
return autoConvert_v1beta2_FlowCollectorFLP_To_v1alpha1_FlowCollectorFLP(in, out, s)
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta1 not in v1alpha1
// we have new defined fields in v1beta2 not in v1alpha1
// nolint:golint,stylecheck,revive
func Convert_v1beta1_FLPMetrics_To_v1alpha1_FLPMetrics(in *v1beta1.FLPMetrics, out *FLPMetrics, s apiconversion.Scope) error {
return autoConvert_v1beta1_FLPMetrics_To_v1alpha1_FLPMetrics(in, out, s)
func Convert_v1beta2_FLPMetrics_To_v1alpha1_FLPMetrics(in *v1beta2.FLPMetrics, out *FLPMetrics, s apiconversion.Scope) error {
return autoConvert_v1beta2_FLPMetrics_To_v1alpha1_FLPMetrics(in, out, s)
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta1 not in v1alpha1
// we have new defined fields in v1beta2 not in v1alpha1
// nolint:golint,stylecheck,revive
func Convert_v1beta2_FlowCollectorLoki_To_v1alpha1_FlowCollectorLoki(in *v1beta2.FlowCollectorLoki, out *FlowCollectorLoki, s apiconversion.Scope) error {
return autoConvert_v1beta2_FlowCollectorLoki_To_v1alpha1_FlowCollectorLoki(in, out, s)
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta2 not in v1alpha1
// nolint:golint,stylecheck,revive
func Convert_v1beta1_FlowCollectorLoki_To_v1alpha1_FlowCollectorLoki(in *v1beta1.FlowCollectorLoki, out *FlowCollectorLoki, s apiconversion.Scope) error {
return autoConvert_v1beta1_FlowCollectorLoki_To_v1alpha1_FlowCollectorLoki(in, out, s)
func Convert_v1alpha1_FlowCollectorLoki_To_v1beta2_FlowCollectorLoki(in *FlowCollectorLoki, out *v1beta2.FlowCollectorLoki, s apiconversion.Scope) error {
return autoConvert_v1alpha1_FlowCollectorLoki_To_v1beta2_FlowCollectorLoki(in, out, s)
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta1 not in v1alpha1
// nolint:golint,stylecheck,revive
func Convert_v1beta1_FlowCollectorConsolePlugin_To_v1alpha1_FlowCollectorConsolePlugin(in *v1beta1.FlowCollectorConsolePlugin, out *FlowCollectorConsolePlugin, s apiconversion.Scope) error {
return autoConvert_v1beta1_FlowCollectorConsolePlugin_To_v1alpha1_FlowCollectorConsolePlugin(in, out, s)
func Convert_v1beta2_FlowCollectorConsolePlugin_To_v1alpha1_FlowCollectorConsolePlugin(in *v1beta2.FlowCollectorConsolePlugin, out *FlowCollectorConsolePlugin, s apiconversion.Scope) error {
return autoConvert_v1beta2_FlowCollectorConsolePlugin_To_v1alpha1_FlowCollectorConsolePlugin(in, out, s)
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta1 not in v1alpha1
// nolint:golint,stylecheck,revive
func Convert_v1beta1_FlowCollectorExporter_To_v1alpha1_FlowCollectorExporter(in *v1beta1.FlowCollectorExporter, out *FlowCollectorExporter, s apiconversion.Scope) error {
return autoConvert_v1beta1_FlowCollectorExporter_To_v1alpha1_FlowCollectorExporter(in, out, s)
func Convert_v1beta2_FlowCollectorExporter_To_v1alpha1_FlowCollectorExporter(in *v1beta2.FlowCollectorExporter, out *FlowCollectorExporter, s apiconversion.Scope) error {
return autoConvert_v1beta2_FlowCollectorExporter_To_v1alpha1_FlowCollectorExporter(in, out, s)
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta1 not in v1alpha1
// nolint:golint,stylecheck,revive
func Convert_v1beta1_FlowCollectorEBPF_To_v1alpha1_FlowCollectorEBPF(in *v1beta1.FlowCollectorEBPF, out *FlowCollectorEBPF, s apiconversion.Scope) error {
return autoConvert_v1beta1_FlowCollectorEBPF_To_v1alpha1_FlowCollectorEBPF(in, out, s)
func Convert_v1beta2_FlowCollectorEBPF_To_v1alpha1_FlowCollectorEBPF(in *v1beta2.FlowCollectorEBPF, out *FlowCollectorEBPF, s apiconversion.Scope) error {
return autoConvert_v1beta2_FlowCollectorEBPF_To_v1alpha1_FlowCollectorEBPF(in, out, s)
}

// // This function need to be manually created because conversion-gen not able to create it intentionally because
// // we have new defined fields in v1beta1 not in v1alpha1
// // we have new defined fields in v1beta2 not in v1alpha1
// // nolint:golint,stylecheck,revive
func Convert_v1beta1_ServerTLS_To_v1alpha1_ServerTLS(in *v1beta1.ServerTLS, out *ServerTLS, s apiconversion.Scope) error {
return autoConvert_v1beta1_ServerTLS_To_v1alpha1_ServerTLS(in, out, s)
func Convert_v1beta2_ServerTLS_To_v1alpha1_ServerTLS(in *v1beta2.ServerTLS, out *ServerTLS, s apiconversion.Scope) error {
return autoConvert_v1beta2_ServerTLS_To_v1alpha1_ServerTLS(in, out, s)
}
Loading
Loading