Skip to content

Commit

Permalink
Fix incorrect use of loggers in forklift-api
Browse files Browse the repository at this point in the history
To prevent 'odd number of arguments passed as key-value pairs for
logging' errors when passing an error, a message, and then odd number of
arguments to the logger.

Signed-off-by: Arik Hadas <ahadas@redhat.com>
  • Loading branch information
ahadas committed Jul 18, 2023
1 parent af91935 commit c53b011
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,36 @@ func (mutator *PlanMutator) setTransferNetworkIfNotSet() (bool, error) {
if mutator.plan.Spec.TransferNetwork == nil {
config, err := rest.InClusterConfig()
if err != nil {
log.Error(err, "Couldn't get the cluster configuration", err.Error())
log.Error(err, "Couldn't get the cluster configuration")
return false, err
}

err = api.SchemeBuilder.AddToScheme(scheme.Scheme)
if err != nil {
log.Error(err, "Couldn't build the scheme", err.Error())
log.Error(err, "Couldn't build the scheme")
return false, err
}
err = apis.AddToScheme(scheme.Scheme)
if err != nil {
log.Error(err, "Couldn't add forklift API to the scheme", err.Error())
log.Error(err, "Couldn't add forklift API to the scheme")
return false, err
}
err = net.AddToScheme(scheme.Scheme)
if err != nil {
log.Error(err, "Couldn't add network-attachment-definition-client to the scheme", err.Error())
log.Error(err, "Couldn't add network-attachment-definition-client to the scheme")
return false, err
}

cl, err := client.New(config, client.Options{Scheme: scheme.Scheme})
if err != nil {
log.Error(err, "Couldn't create a cluster client", err.Error())
log.Error(err, "Couldn't create a cluster client")
return false, err
}

targetProvider := api.Provider{}
err = cl.Get(context.TODO(), client.ObjectKey{Namespace: mutator.plan.Spec.Provider.Destination.Namespace, Name: mutator.plan.Spec.Provider.Destination.Name}, &targetProvider)
if err != nil {
log.Error(err, "Couldn't get the target provider", err.Error())
log.Error(err, "Couldn't get the target provider")
return false, err
}

Expand All @@ -126,13 +126,13 @@ func (mutator *PlanMutator) setTransferNetworkIfNotSet() (bool, error) {
},
secret)
if err != nil {
log.Error(err, "Failed to get secret for target provider", err.Error())
log.Error(err, "Failed to get secret for target provider")
return false, err
}
tcl, err = targetProvider.Client(secret)
}
if err != nil {
log.Error(err, "Failed to initiate client to target cluster", err.Error())
log.Error(err, "Failed to initiate client to target cluster")
return false, err
}

Expand All @@ -145,7 +145,7 @@ func (mutator *PlanMutator) setTransferNetworkIfNotSet() (bool, error) {
}
planChanged = true
} else if !k8serr.IsNotFound(err) { // TODO: else if !NotFound ...
log.Error(err, "Failed to get the network-attachment-definition", err.Error())
log.Error(err, "Failed to get the network-attachment-definition")
return false, err
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,24 @@ func (admitter *SecretAdmitter) buildProviderCollector(providerType *api.Provide
func (admitter *SecretAdmitter) testConnectionToHost(hostName string) (tested bool, err error) {
config, err := rest.InClusterConfig()
if err != nil {
log.Error(err, "Couldn't get the cluster configuration", err.Error())
log.Error(err, "Couldn't get the cluster configuration")
return
}

err = api.SchemeBuilder.AddToScheme(scheme.Scheme)
if err != nil {
log.Error(err, "Couldn't build the scheme", err.Error())
log.Error(err, "Couldn't build the scheme")
return
}
err = apis.AddToScheme(scheme.Scheme)
if err != nil {
log.Error(err, "Couldn't add forklift API to the scheme", err.Error())
log.Error(err, "Couldn't add forklift API to the scheme")
return
}

cl, err := client.New(config, client.Options{Scheme: scheme.Scheme})
if err != nil {
log.Error(err, "Couldn't create a cluster client", err.Error())
log.Error(err, "Couldn't create a cluster client")
return
}

Expand All @@ -183,7 +183,7 @@ func (admitter *SecretAdmitter) testConnectionToHost(hostName string) (tested bo
err = nil
return
} else {
log.Error(err, "Couldn't get the target provider", err.Error())
log.Error(err, "Couldn't get the target provider")
return
}
}
Expand Down

0 comments on commit c53b011

Please sign in to comment.