Skip to content

Commit

Permalink
Use pointer package
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak committed Apr 4, 2023
1 parent f97260f commit 6992083
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 33 deletions.
12 changes: 4 additions & 8 deletions controllers/flowcollector_controller_console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import (
// For simplicity, we'll use a different namespace
const cpNamespace = "namespace-console-specs"

var tRue = true
var fAlse = false

// nolint:cyclop
func flowCollectorConsolePluginSpecs() {
cpKey := types.NamespacedName{
Expand Down Expand Up @@ -80,7 +77,7 @@ func flowCollectorConsolePluginSpecs() {
ConsolePlugin: flowslatest.FlowCollectorConsolePlugin{
Port: 9001,
ImagePullPolicy: "Never",
Register: &tRue,
Register: pointer.Bool(true),
Autoscaler: flowslatest.FlowCollectorHPA{
Status: flowslatest.HPAStatusEnabled,
MinReplicas: pointer.Int32(1),
Expand All @@ -97,7 +94,7 @@ func flowCollectorConsolePluginSpecs() {
}},
},
PortNaming: flowslatest.ConsolePluginPortConfig{
Enable: &tRue,
Enable: pointer.Bool(true),
PortNames: map[string]string{
"3100": "loki",
},
Expand Down Expand Up @@ -153,9 +150,8 @@ func flowCollectorConsolePluginSpecs() {
if err := k8sClient.Get(ctx, crKey, &fc); err != nil {
return err
}
two := int32(2)
fc.Spec.ConsolePlugin.Port = 9099
fc.Spec.ConsolePlugin.Replicas = &two
fc.Spec.ConsolePlugin.Replicas = pointer.Int32(2)
fc.Spec.ConsolePlugin.Autoscaler.Status = flowslatest.HPAStatusDisabled
return k8sClient.Update(ctx, &fc)
}).Should(Succeed())
Expand Down Expand Up @@ -245,7 +241,7 @@ func flowCollectorConsolePluginSpecs() {
It("Should be unregistered", func() {
By("Update CR to unregister")
UpdateCR(crKey, func(fc *flowslatest.FlowCollector) {
fc.Spec.ConsolePlugin.Register = &fAlse
fc.Spec.ConsolePlugin.Register = pointer.Bool(false)
})

By("Expecting the Console CR to not have plugin registered")
Expand Down
21 changes: 11 additions & 10 deletions controllers/flowcollector_controller_iso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"

flowslatest "github.com/netobserv/network-observability-operator/api/v1beta1"
"github.com/netobserv/network-observability-operator/controllers/constants"
Expand Down Expand Up @@ -76,8 +77,8 @@ func flowCollectorIsoSpecs() {
IgnoreTags: []string{},
DisableAlerts: []flowslatest.FLPAlert{},
},
EnableKubeProbes: &fAlse,
DropUnusedFields: &fAlse,
EnableKubeProbes: pointer.Bool(false),
DropUnusedFields: pointer.Bool(false),
},
Agent: flowslatest.FlowCollectorAgent{
Type: "EBPF",
Expand Down Expand Up @@ -110,15 +111,15 @@ func flowCollectorIsoSpecs() {
},
},
ConsolePlugin: flowslatest.FlowCollectorConsolePlugin{
Register: &fAlse,
Register: pointer.Bool(false),
Replicas: &zero,
Port: 12345,
ImagePullPolicy: "Always",
Resources: v1.ResourceRequirements{Limits: nil, Requests: nil},
LogLevel: "trace",
Autoscaler: flowslatest.FlowCollectorHPA{Status: "DISABLED", MinReplicas: &zero, MaxReplicas: zero, Metrics: []ascv2.MetricSpec{}},
PortNaming: flowslatest.ConsolePluginPortConfig{
Enable: &fAlse,
Enable: pointer.Bool(false),
PortNames: map[string]string{},
},
QuickFilters: []flowslatest.QuickFilter{},
Expand All @@ -137,8 +138,8 @@ func flowCollectorIsoSpecs() {
MaxRetries: &zero,
StaticLabels: map[string]string{},
TLS: flowslatest.ClientTLS{
Enable: fAlse,
InsecureSkipVerify: fAlse,
Enable: false,
InsecureSkipVerify: false,
CACert: flowslatest.CertificateReference{
Type: "configmap",
Name: "",
Expand All @@ -153,8 +154,8 @@ func flowCollectorIsoSpecs() {
},
},
StatusTLS: flowslatest.ClientTLS{
Enable: fAlse,
InsecureSkipVerify: fAlse,
Enable: false,
InsecureSkipVerify: false,
CACert: flowslatest.CertificateReference{
Type: "configmap",
Name: "",
Expand All @@ -173,8 +174,8 @@ func flowCollectorIsoSpecs() {
Address: "http://kafka",
Topic: "topic",
TLS: flowslatest.ClientTLS{
Enable: fAlse,
InsecureSkipVerify: fAlse,
Enable: false,
InsecureSkipVerify: false,
CACert: flowslatest.CertificateReference{
Type: "configmap",
Name: "",
Expand Down
5 changes: 2 additions & 3 deletions controllers/flowcollector_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func flowCollectorControllerSpecs() {
Port: 9001,
ImagePullPolicy: "Never",
PortNaming: flowslatest.ConsolePluginPortConfig{
Enable: &tRue,
Enable: pointer.Bool(true),
PortNames: map[string]string{
"3100": "loki",
},
Expand Down Expand Up @@ -333,8 +333,7 @@ func flowCollectorControllerSpecs() {

It("Should redeploy if the spec doesn't change but the external flowlogs-pipeline-config does", func() {
UpdateCR(crKey, func(fc *flowslatest.FlowCollector) {
val := int32(7)
fc.Spec.Loki.MaxRetries = &val
fc.Spec.Loki.MaxRetries = pointer.Int32(7)
})

By("Expecting that the flowlogsPipeline.PodConfigurationDigest attribute has changed")
Expand Down
20 changes: 8 additions & 12 deletions controllers/flowlogspipeline/flp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"

flowslatest "github.com/netobserv/network-observability-operator/api/v1beta1"
"github.com/netobserv/network-observability-operator/controllers/constants"
Expand All @@ -48,13 +49,10 @@ var minReplicas = int32(1)
var maxReplicas = int32(5)
var targetCPU = int32(75)
var outputRecordTypes = flowslatest.LogTypeAll
var tRue = true

const testNamespace = "flp"

func getConfig() flowslatest.FlowCollectorSpec {
one := int32(1)
ten := int32(10)
return flowslatest.FlowCollectorSpec{
DeploymentModel: flowslatest.DeploymentModelDirect,
Agent: flowslatest.FlowCollectorAgent{Type: flowslatest.AgentIPFIX},
Expand All @@ -72,7 +70,7 @@ func getConfig() flowslatest.FlowCollectorSpec {
},
},
},
KafkaConsumerReplicas: &one,
KafkaConsumerReplicas: pointer.Int32(1),
KafkaConsumerAutoscaler: flowslatest.FlowCollectorHPA{
Status: flowslatest.HPAStatusEnabled,
MinReplicas: &minReplicas,
Expand Down Expand Up @@ -108,7 +106,7 @@ func getConfig() flowslatest.FlowCollectorSpec {
MaxBackoff: metav1.Duration{
Duration: 300,
},
MaxRetries: &ten,
MaxRetries: pointer.Int32(10),
StaticLabels: map[string]string{"app": "netobserv-flowcollector"},
},
Kafka: flowslatest.FlowCollectorKafka{
Expand Down Expand Up @@ -187,7 +185,7 @@ func TestDaemonSetChanged(t *testing.T) {
first := b.daemonSet(digest)

// Check probes enabled change
cfg.Processor.EnableKubeProbes = &tRue
cfg.Processor.EnableKubeProbes = pointer.Bool(true)
b = newMonolithBuilder(ns, image, &cfg, true)
_, digest, _, err = b.configMap()
assert.NoError(err)
Expand Down Expand Up @@ -331,7 +329,7 @@ func TestDeploymentChanged(t *testing.T) {
first := b.deployment(digest)

// Check probes enabled change
cfg.Processor.EnableKubeProbes = &tRue
cfg.Processor.EnableKubeProbes = pointer.Bool(true)
b = newTransfoBuilder(ns, image, &cfg, true)
_, digest, _, err = b.configMap()
assert.NoError(err)
Expand Down Expand Up @@ -389,8 +387,7 @@ func TestDeploymentChanged(t *testing.T) {

// Check replicas didn't change because HPA is used
cfg2 := cfg
five := int32(5)
cfg2.Processor.KafkaConsumerReplicas = &five
cfg2.Processor.KafkaConsumerReplicas = pointer.Int32(5)
b = newTransfoBuilder(ns, image, &cfg2, true)
_, digest, _, err = b.configMap()
assert.NoError(err)
Expand All @@ -414,8 +411,7 @@ func TestDeploymentChangedReplicasNoHPA(t *testing.T) {

// Check replicas changed (need to copy flp, as Spec.Replicas stores a pointer)
cfg2 := cfg
five := int32(5)
cfg2.Processor.KafkaConsumerReplicas = &five
cfg2.Processor.KafkaConsumerReplicas = pointer.Int32(5)
b = newTransfoBuilder(ns, image, &cfg2, true)
_, digest, _, err = b.configMap()
assert.NoError(err)
Expand Down Expand Up @@ -734,7 +730,7 @@ func TestPipelineConfigDropUnused(t *testing.T) {
ns := "namespace"
cfg := getConfig()
cfg.Processor.LogLevel = "info"
cfg.Processor.DropUnusedFields = &tRue
cfg.Processor.DropUnusedFields = pointer.Bool(true)
b := newMonolithBuilder(ns, image, &cfg, true)
stages, parameters, _, err := b.buildPipelineConfig()
assert.NoError(err)
Expand Down

0 comments on commit 6992083

Please sign in to comment.