From 2c56d496f7558520048da68537db2ed225b7f940 Mon Sep 17 00:00:00 2001 From: Brandon Palm Date: Mon, 16 Dec 2024 12:53:13 -0600 Subject: [PATCH] clusterlogging: adjust return consistency --- pkg/clusterlogging/clusterlogforwarder.go | 14 +++++++------- pkg/clusterlogging/clusterlogging.go | 14 +++++++++----- pkg/clusterlogging/elasticsearch.go | 8 ++++++-- pkg/clusterlogging/lokistack.go | 8 ++++++-- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/pkg/clusterlogging/clusterlogforwarder.go b/pkg/clusterlogging/clusterlogforwarder.go index a223759c9..733ae4365 100644 --- a/pkg/clusterlogging/clusterlogforwarder.go +++ b/pkg/clusterlogging/clusterlogforwarder.go @@ -59,12 +59,16 @@ func NewClusterLogForwarderBuilder( glog.V(100).Infof("The name of the clusterlogforwarder is empty") builder.errorMsg = "clusterlogforwarder 'name' cannot be empty" + + return builder } if nsname == "" { glog.V(100).Infof("The namespace of the clusterlogforwarder is empty") builder.errorMsg = "clusterlogforwarder 'nsname' cannot be empty" + + return builder } return builder @@ -83,9 +87,7 @@ func (builder *ClusterLogForwarderBuilder) WithOutput(outputSpec *clov1.OutputSp glog.V(100).Infof("The 'outputSpec' of the deployment is empty") builder.errorMsg = "'outputSpec' parameter is empty" - } - if builder.errorMsg != "" { return builder } @@ -111,9 +113,7 @@ func (builder *ClusterLogForwarderBuilder) WithPipeline(pipelineSpec *clov1.Pipe glog.V(100).Infof("The 'pipelineSpec' of the deployment is empty") builder.errorMsg = "'pipelineSpec' parameter is empty" - } - if builder.errorMsg != "" { return builder } @@ -143,7 +143,7 @@ func PullClusterLogForwarder(apiClient *clients.Settings, name, nsname string) ( return nil, err } - builder := ClusterLogForwarderBuilder{ + builder := &ClusterLogForwarderBuilder{ apiClient: apiClient.Client, Definition: &clov1.ClusterLogForwarder{ ObjectMeta: metav1.ObjectMeta{ @@ -169,7 +169,7 @@ func PullClusterLogForwarder(apiClient *clients.Settings, name, nsname string) ( return nil, fmt.Errorf("clusterlogforwarder object %s does not exist in namespace %s", name, nsname) } - return &builder, nil + return builder, nil } // Get returns clusterlogforwarder object if found. @@ -191,7 +191,7 @@ func (builder *ClusterLogForwarderBuilder) Get() (*clov1.ClusterLogForwarder, er return nil, err } - return clusterLogForwarder, err + return clusterLogForwarder, nil } // Create makes a clusterlogforwarder in the cluster and stores the created object in struct. diff --git a/pkg/clusterlogging/clusterlogging.go b/pkg/clusterlogging/clusterlogging.go index 6a2484214..a0df237d3 100644 --- a/pkg/clusterlogging/clusterlogging.go +++ b/pkg/clusterlogging/clusterlogging.go @@ -62,12 +62,16 @@ func NewBuilder( glog.V(100).Infof("The name of the clusterLogging is empty") builder.errorMsg = "the clusterLogging 'name' cannot be empty" + + return builder } if nsname == "" { glog.V(100).Infof("The namespace of the clusterLogging is empty") builder.errorMsg = "the clusterLogging 'nsname' cannot be empty" + + return builder } return builder @@ -91,7 +95,7 @@ func Pull(apiClient *clients.Settings, name, nsname string) (*Builder, error) { return nil, err } - builder := Builder{ + builder := &Builder{ apiClient: apiClient.Client, Definition: &clov1.ClusterLogging{ ObjectMeta: metav1.ObjectMeta{ @@ -119,7 +123,7 @@ func Pull(apiClient *clients.Settings, name, nsname string) (*Builder, error) { builder.Definition = builder.Object - return &builder, nil + return builder, nil } // Get returns clusterLogging object if found. @@ -141,7 +145,7 @@ func (builder *Builder) Get() (*clov1.ClusterLogging, error) { return nil, err } - return clusterLogging, err + return clusterLogging, nil } // Create makes a clusterLogging in the cluster and stores the created object in struct. @@ -348,13 +352,13 @@ func (builder *Builder) validate() (bool, error) { if builder.Definition == nil { glog.V(100).Infof("The %s is undefined", resourceCRD) - builder.errorMsg = msg.UndefinedCrdObjectErrString(resourceCRD) + return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD)) } if builder.apiClient == nil { glog.V(100).Infof("The %s builder apiclient is nil", resourceCRD) - builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD) + return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD) } if builder.errorMsg != "" { diff --git a/pkg/clusterlogging/elasticsearch.go b/pkg/clusterlogging/elasticsearch.go index 169bcd192..470215a8d 100644 --- a/pkg/clusterlogging/elasticsearch.go +++ b/pkg/clusterlogging/elasticsearch.go @@ -58,12 +58,16 @@ func NewElasticsearchBuilder( glog.V(100).Infof("The name of the elasticsearch is empty") builder.errorMsg = "elasticsearch 'name' cannot be empty" + + return builder } if nsname == "" { glog.V(100).Infof("The nsname of the elasticsearch is empty") builder.errorMsg = "elasticsearch 'nsname' cannot be empty" + + return builder } return builder @@ -87,7 +91,7 @@ func PullElasticsearch(apiClient *clients.Settings, name, nsname string) (*Elast return nil, err } - builder := ElasticsearchBuilder{ + builder := &ElasticsearchBuilder{ apiClient: apiClient.Client, Definition: &eskv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ @@ -115,7 +119,7 @@ func PullElasticsearch(apiClient *clients.Settings, name, nsname string) (*Elast builder.Definition = builder.Object - return &builder, nil + return builder, nil } // Get returns elasticsearch object if found. diff --git a/pkg/clusterlogging/lokistack.go b/pkg/clusterlogging/lokistack.go index 589d8262e..934b8241d 100644 --- a/pkg/clusterlogging/lokistack.go +++ b/pkg/clusterlogging/lokistack.go @@ -62,12 +62,16 @@ func NewLokiStackBuilder( glog.V(100).Infof("The name of the lokiStack is empty") builder.errorMsg = "lokiStack 'name' cannot be empty" + + return builder } if nsname == "" { glog.V(100).Infof("The nsname of the lokiStack is empty") builder.errorMsg = "lokiStack 'nsname' cannot be empty" + + return builder } return builder @@ -91,7 +95,7 @@ func PullLokiStack(apiClient *clients.Settings, name, nsname string) (*LokiStack return nil, err } - builder := LokiStackBuilder{ + builder := &LokiStackBuilder{ apiClient: apiClient.Client, Definition: &lokiv1.LokiStack{ ObjectMeta: metav1.ObjectMeta{ @@ -119,7 +123,7 @@ func PullLokiStack(apiClient *clients.Settings, name, nsname string) (*LokiStack builder.Definition = builder.Object - return &builder, nil + return builder, nil } // Get returns lokiStack object if found.