Skip to content

Commit

Permalink
ADD v1beta2 with new Loki integration fields
Browse files Browse the repository at this point in the history
Signed-off-by: acmenezes <[email protected]>
  • Loading branch information
acmenezes committed Jun 19, 2023
1 parent 92e78be commit 6f4c39d
Show file tree
Hide file tree
Showing 49 changed files with 9,722 additions and 492 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ generate-go-conversions: $(CONVERSION_GEN) ## Run all generate-go-conversions
--output-file-base=zz_generated.conversion \
$(CONVERSION_GEN_OUTPUT_BASE) \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt
$(MAKE) clean-generated-conversions SRC_DIRS="./api/v1beta1"
$(CONVERSION_GEN) \
--input-dirs=./api/v1beta1 \
--build-tag=ignore_autogenerated_core \
--output-file-base=zz_generated.conversion \
$(CONVERSION_GEN_OUTPUT_BASE) \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt

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

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
Loki FlowCollectorLoki `json:"loki,omitempty"`

// consolePlugin defines the settings related to the OpenShift Console plugin, when available.
Expand Down
61 changes: 34 additions & 27 deletions api/v1alpha1/flowcollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ 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 {
return err
}
Expand All @@ -62,7 +62,7 @@ func (r *FlowCollector) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Processor.Metrics.DisableAlerts = restored.Spec.Processor.Metrics.DisableAlerts
}

dst.Spec.Loki.StatusTLS = restored.Spec.Loki.StatusTLS
dst.Spec.Loki.Manual = restored.Spec.Loki.Manual

if restored.Spec.Exporters != nil {
for _, restoredExp := range restored.Spec.Exporters {
Expand All @@ -75,7 +75,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 @@ -85,12 +85,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 @@ -103,39 +103,46 @@ 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_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)
}
Loading

0 comments on commit 6f4c39d

Please sign in to comment.