Skip to content

Commit

Permalink
Merge pull request #2182 from jcantrill/log4564
Browse files Browse the repository at this point in the history
LOG-4564: fix nil pointer for CLF without CL
  • Loading branch information
openshift-merge-robot committed Sep 29, 2023
2 parents cb09669 + 2932ad9 commit 09e097d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/k8s/loader/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func FetchClusterLogForwarder(k8sClient client.Client, namespace, name string, i
setMigrationStatusConditions(&forwarder.Status, migrationMessages)

extras[constants.ClusterLoggingAvailable] = (fetchClusterLogging().Name != "")
extras[constants.VectorName] = (fetchClusterLogging().Spec.Collection.Type == logging.LogCollectionTypeVector)
extras[constants.VectorName] = false
if fetchClusterLogging().Spec.Collection != nil {
extras[constants.VectorName] = fetchClusterLogging().Spec.Collection.Type == logging.LogCollectionTypeVector
}
if err, status = clusterlogforwarder.Validate(forwarder, k8sClient, extras); err != nil {
return forwarder, err, status
}
Expand Down
45 changes: 45 additions & 0 deletions internal/k8s/loader/load_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package loader

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/cluster-logging-operator/internal/constants"
"github.com/openshift/cluster-logging-operator/internal/runtime"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

logging "github.com/openshift/cluster-logging-operator/apis/logging/v1"
)

var _ = Describe("#FetchClusterLogForwarder", func() {

var (
clf *logging.ClusterLogForwarder
k8Client client.Client
)

Context("when retrieving a legacy CLF without existing CL", func() {

BeforeEach(func() {
k8Client = fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
clf = runtime.NewClusterLogForwarder(constants.OpenshiftNS, constants.SingletonName)
clf.Spec = logging.ClusterLogForwarderSpec{
Pipelines: []logging.PipelineSpec{
{
Name: "all-logs-to-default",
InputRefs: logging.ReservedInputNames.List(),
OutputRefs: []string{logging.OutputNameDefault},
},
},
}
})

// https://issues.redhat.com/browse/LOG-4564
It("should return with validation errors", func() {
fetchCL := func() logging.ClusterLogging { return logging.ClusterLogging{} }
_, err, _ := FetchClusterLogForwarder(k8Client, clf.Namespace, clf.Name, false, fetchCL)
Expect(err).ToNot(BeNil(), "legacy CLF without CL should fail with validation errors")
})
})
})
13 changes: 13 additions & 0 deletions internal/k8s/loader/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package loader

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestSuite(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "[internal][k8s][loader] Suite")
}

0 comments on commit 09e097d

Please sign in to comment.