Skip to content

Commit

Permalink
Renaming strings with fmt specifiers to include Fmt, removing module …
Browse files Browse the repository at this point in the history
…name prefix from const names, moving redundant constants to tests/utils.io

Signed-off-by: prnaraya <[email protected]>
  • Loading branch information
prnaraya committed Dec 23, 2021
1 parent bbcc02e commit be32d95
Show file tree
Hide file tree
Showing 40 changed files with 545 additions and 554 deletions.
10 changes: 5 additions & 5 deletions pkg/monitoring/perfscale/vmi-phase-transitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
)

const (
transTimeErr = "Error encountered during vmi transition time histogram calculation: %v"
transTimeFail = "Failed to get a histogram for a vmi lifecycle transition times"
transTimeErrFmt = "Error encountered during vmi transition time histogram calculation: %v"
transTimeFail = "Failed to get a histogram for a vmi lifecycle transition times"
)

func getTransitionTimeSeconds(fromCreation bool, fromDeletion bool, oldVMI *v1.VirtualMachineInstance, newVMI *v1.VirtualMachineInstance) (float64, error) {
Expand Down Expand Up @@ -104,7 +104,7 @@ func updateVMIPhaseTransitionTimeHistogramVec(histogramVec *prometheus.Histogram

diffSeconds, err := getTransitionTimeSeconds(false, false, oldVMI, newVMI)
if err != nil {
log.Log.V(4).Infof(transTimeErr, err)
log.Log.V(4).Infof(transTimeErrFmt, err)
return
}

Expand Down Expand Up @@ -147,7 +147,7 @@ func updateVMIPhaseTransitionTimeFromCreationTimeHistogramVec(histogramVec *prom

diffSeconds, err := getTransitionTimeSeconds(true, false, oldVMI, newVMI)
if err != nil {
log.Log.V(4).Infof(transTimeErr, err)
log.Log.V(4).Infof(transTimeErrFmt, err)
return
}

Expand All @@ -172,7 +172,7 @@ func updateVMIPhaseTransitionTimeFromDeletionTimeHistogramVec(histogramVec *prom

diffSeconds, err := getTransitionTimeSeconds(false, true, oldVMI, newVMI)
if err != nil {
log.Log.V(4).Infof(transTimeErr, err)
log.Log.V(4).Infof(transTimeErrFmt, err)
return
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/network/dhcp/serverv6/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"golang.org/x/net/ipv6"
)

const errFormat = "%s: %v"
const errFmt = "%s: %v"

type FilteredConn struct {
ifIndex int
Expand Down Expand Up @@ -80,19 +80,19 @@ func NewConnection(serverIface *net.Interface) (*FilteredConn, error) {
}
udpConn, err := server6.NewIPv6UDPConn("", addr)
if err != nil {
return nil, fmt.Errorf(errFormat, errorString, err)
return nil, fmt.Errorf(errFmt, errorString, err)
}

packetConn := ipv6.NewPacketConn(udpConn)
if err := packetConn.SetControlMessage(ipv6.FlagInterface, true); err != nil {
return nil, fmt.Errorf(errFormat, errorString, err)
return nil, fmt.Errorf(errFmt, errorString, err)
}

group := net.UDPAddr{
IP: dhcpv6.AllDHCPRelayAgentsAndServers,
Port: dhcpv6.DefaultServerPort}
if err := packetConn.JoinGroup(serverIface, &group); err != nil {
return nil, fmt.Errorf(errFormat, errorString, err)
return nil, fmt.Errorf(errFmt, errorString, err)
}

return &FilteredConn{packetConn: packetConn, ifIndex: serverIface.Index}, nil
Expand Down
10 changes: 5 additions & 5 deletions pkg/network/domainspec/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"kubevirt.io/kubevirt/pkg/virt-launcher/virtwrap/api"
)

const linkIfaceFail = "failed to get a link for interface: %s"
const linkIfaceFailFmt = "failed to get a link for interface: %s"

type LibvirtSpecGenerator interface {
Generate() error
Expand Down Expand Up @@ -102,15 +102,15 @@ func (b *BridgeLibvirtSpecGenerator) Generate() error {
func (b *BridgeLibvirtSpecGenerator) discoverDomainIfaceSpec() (*api.Interface, error) {
podNicLink, err := b.handler.LinkByName(b.podInterfaceName)
if err != nil {
log.Log.Reason(err).Errorf(linkIfaceFail, b.podInterfaceName)
log.Log.Reason(err).Errorf(linkIfaceFailFmt, b.podInterfaceName)
return nil, err
}
_, dummy := podNicLink.(*netlink.Dummy)
if dummy {
newPodNicName := virtnetlink.GenerateNewBridgedVmiInterfaceName(b.podInterfaceName)
podNicLink, err = b.handler.LinkByName(newPodNicName)
if err != nil {
log.Log.Reason(err).Errorf(linkIfaceFail, newPodNicName)
log.Log.Reason(err).Errorf(linkIfaceFailFmt, newPodNicName)
return nil, err
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func (b *MasqueradeLibvirtSpecGenerator) discoverDomainIfaceSpec() (*api.Interfa
var domainIface api.Interface
podNicLink, err := b.handler.LinkByName(b.podInterfaceName)
if err != nil {
log.Log.Reason(err).Errorf(linkIfaceFail, b.podInterfaceName)
log.Log.Reason(err).Errorf(linkIfaceFailFmt, b.podInterfaceName)
return nil, err
}

Expand Down Expand Up @@ -233,7 +233,7 @@ func (b *MacvtapLibvirtSpecGenerator) Generate() error {
func (b *MacvtapLibvirtSpecGenerator) discoverDomainIfaceSpec() (*api.Interface, error) {
podNicLink, err := b.handler.LinkByName(b.podInterfaceName)
if err != nil {
log.Log.Reason(err).Errorf(linkIfaceFail, b.podInterfaceName)
log.Log.Reason(err).Errorf(linkIfaceFailFmt, b.podInterfaceName)
return nil, err
}
mac, err := virtnetlink.RetrieveMacAddressFromVMISpecIface(b.vmiSpecIface)
Expand Down
22 changes: 11 additions & 11 deletions pkg/network/infraconfigurators/masquerade.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
)

const (
ipVerifyFail = "failed to verify whether ipv6 is configured on %s"
toDest = "--to-destination"
src = "--source"
dport = "--dport"
str = "{ %s }"
ipVerifyFailFmt = "failed to verify whether ipv6 is configured on %s"
toDest = "--to-destination"
src = "--source"
dport = "--dport"
strFmt = "{ %s }"
LibvirtDirectMigrationPort = 49152
LibvirtBlockMigrationPort = 49153
)
Expand Down Expand Up @@ -69,7 +69,7 @@ func (b *MasqueradePodNetworkConfigurator) DiscoverPodNetworkInterface(podIfaceN

ipv6Enabled, err := b.handler.IsIpv6Enabled(podIfaceName)
if err != nil {
log.Log.Reason(err).Errorf(ipVerifyFail, podIfaceName)
log.Log.Reason(err).Errorf(ipVerifyFailFmt, podIfaceName)
return err
}
if ipv6Enabled {
Expand Down Expand Up @@ -130,7 +130,7 @@ func (b *MasqueradePodNetworkConfigurator) PreparePodNetworkInterface() error {

ipv6Enabled, err := b.handler.IsIpv6Enabled(b.podNicLink.Attrs().Name)
if err != nil {
log.Log.Reason(err).Errorf(ipVerifyFail, b.podNicLink.Attrs().Name)
log.Log.Reason(err).Errorf(ipVerifyFailFmt, b.podNicLink.Attrs().Name)
return err
}
if ipv6Enabled {
Expand Down Expand Up @@ -178,7 +178,7 @@ func (b *MasqueradePodNetworkConfigurator) createBridge() error {
}
ipv6Enabled, err := b.handler.IsIpv6Enabled(b.podNicLink.Attrs().Name)
if err != nil {
log.Log.Reason(err).Errorf(ipVerifyFail, b.podNicLink.Attrs().Name)
log.Log.Reason(err).Errorf(ipVerifyFailFmt, b.podNicLink.Attrs().Name)
return err
}
if ipv6Enabled {
Expand Down Expand Up @@ -462,7 +462,7 @@ func (b *MasqueradePodNetworkConfigurator) skipForwardingForPortsUsingNftables(p
chainWhereSnatIsPerformed := "KUBEVIRT_POSTINBOUND"
for _, chain := range []string{chainWhereDnatIsPerformed, chainWhereSnatIsPerformed} {
err := b.handler.NftablesAppendRule(proto, "nat", chain,
"tcp", "dport", fmt.Sprintf(str, strings.Join(ports, ", ")),
"tcp", "dport", fmt.Sprintf(strFmt, strings.Join(ports, ", ")),
b.handler.GetNFTIPString(proto), "saddr", getLoopbackAdrress(proto),
"counter", "return")
if err != nil {
Expand Down Expand Up @@ -493,7 +493,7 @@ func (b *MasqueradePodNetworkConfigurator) getSrcAddressesToSnat(proto iptables.
if istio.ProxyInjectionEnabled(b.vmi) && proto == iptables.ProtocolIPv4 {
addresses = append(addresses, istio.GetLoopbackAddress())
}
return fmt.Sprintf(str, strings.Join(addresses, ", "))
return fmt.Sprintf(strFmt, strings.Join(addresses, ", "))
}

func (b *MasqueradePodNetworkConfigurator) getDstAddressesToDnat(proto iptables.Protocol) (string, error) {
Expand All @@ -505,7 +505,7 @@ func (b *MasqueradePodNetworkConfigurator) getDstAddressesToDnat(proto iptables.
}
addresses = append(addresses, ipv4)
}
return fmt.Sprintf(str, strings.Join(addresses, ", ")), nil
return fmt.Sprintf(strFmt, strings.Join(addresses, ", ")), nil
}

func getLoopbackAdrress(proto iptables.Protocol) string {
Expand Down
60 changes: 30 additions & 30 deletions pkg/virt-api/rest/subresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ import (
)

const (
unmarshalRequestErr = "Can not unmarshal Request body to struct, error: %s"
vmNotRunning = "VM is not running"
patchingVM = "Patching VM: %s"
jsonpatchTestErr = "jsonpatch test operation does not apply"
patchingVMStatus = "Patching VM status: %s"
vmiNotRunning = "VMI is not running"
vmiGuestAgentErr = "VMI does not have guest agent connected"
prepConnectionErr = "Cannot prepare connection %s"
getRequestErr = "Cannot GET request %s"
unmarshalRequestErrFmt = "Can not unmarshal Request body to struct, error: %s"
vmNotRunning = "VM is not running"
patchingVMFmt = "Patching VM: %s"
jsonpatchTestErr = "jsonpatch test operation does not apply"
patchingVMStatusFmt = "Patching VM status: %s"
vmiNotRunning = "VMI is not running"
vmiGuestAgentErr = "VMI does not have guest agent connected"
prepConnectionErrFmt = "Cannot prepare connection %s"
getRequestErrFmt = "Cannot GET request %s"
defaultProfilerComponentPort = 8443
)

Expand Down Expand Up @@ -240,7 +240,7 @@ func (app *SubresourceAPIApp) MigrateVMRequestHandler(request *restful.Request,
case io.EOF, nil:
break
default:
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErr, err)), response)
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErrFmt, err)), response)
return
}
}
Expand Down Expand Up @@ -307,7 +307,7 @@ func (app *SubresourceAPIApp) RestartVMRequestHandler(request *restful.Request,
case io.EOF, nil:
break
default:
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErr, err)), response)
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErrFmt, err)), response)
return
}
}
Expand Down Expand Up @@ -355,7 +355,7 @@ func (app *SubresourceAPIApp) RestartVMRequestHandler(request *restful.Request,
return
}

log.Log.Object(vm).V(4).Infof(patchingVM, bodyString)
log.Log.Object(vm).V(4).Infof(patchingVMFmt, bodyString)
err = app.statusUpdater.PatchStatus(vm, types.JSONPatchType, []byte(bodyString), &k8smetav1.PatchOptions{DryRun: bodyStruct.DryRun})
if err != nil {
if strings.Contains(err.Error(), jsonpatchTestErr) {
Expand Down Expand Up @@ -455,7 +455,7 @@ func (app *SubresourceAPIApp) StartVMRequestHandler(request *restful.Request, re
case io.EOF, nil:
break
default:
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErr, err)), response)
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErrFmt, err)), response)
return
}
startPaused = bodyStruct.Paused
Expand Down Expand Up @@ -489,11 +489,11 @@ func (app *SubresourceAPIApp) StartVMRequestHandler(request *restful.Request, re
writeError(errors.NewInternalError(err), response)
return
}
log.Log.Object(vm).V(4).Infof(patchingVMStatus, patchString)
log.Log.Object(vm).V(4).Infof(patchingVMStatusFmt, patchString)
patchErr = app.statusUpdater.PatchStatus(vm, types.JSONPatchType, []byte(patchString), &k8smetav1.PatchOptions{DryRun: bodyStruct.DryRun})
} else {
patchString := getRunningJson(vm, true)
log.Log.Object(vm).V(4).Infof(patchingVM, patchString)
log.Log.Object(vm).V(4).Infof(patchingVMFmt, patchString)
_, patchErr = app.virtCli.VirtualMachine(namespace).Patch(vm.GetName(), types.MergePatchType, []byte(patchString), &k8smetav1.PatchOptions{DryRun: bodyStruct.DryRun})
}

Expand All @@ -520,7 +520,7 @@ func (app *SubresourceAPIApp) StartVMRequestHandler(request *restful.Request, re
writeError(errors.NewInternalError(err), response)
return
}
log.Log.Object(vm).V(4).Infof(patchingVMStatus, bodyString)
log.Log.Object(vm).V(4).Infof(patchingVMStatusFmt, bodyString)
patchErr = app.statusUpdater.PatchStatus(vm, types.JSONPatchType, []byte(bodyString), &k8smetav1.PatchOptions{DryRun: bodyStruct.DryRun})
case v1.RunStrategyAlways:
writeError(errors.NewConflict(v1.Resource("virtualmachine"), name, fmt.Errorf("%v does not support manual start requests", v1.RunStrategyAlways)), response)
Expand Down Expand Up @@ -555,7 +555,7 @@ func (app *SubresourceAPIApp) StopVMRequestHandler(request *restful.Request, res
case io.EOF, nil:
break
default:
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErr, err)), response)
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErrFmt, err)), response)
return
}
}
Expand Down Expand Up @@ -615,11 +615,11 @@ func (app *SubresourceAPIApp) StopVMRequestHandler(request *restful.Request, res
writeError(errors.NewInternalError(err), response)
return
}
log.Log.Object(vm).V(4).Infof(patchingVMStatus, bodyString)
log.Log.Object(vm).V(4).Infof(patchingVMStatusFmt, bodyString)
patchErr = app.statusUpdater.PatchStatus(vm, patchType, []byte(bodyString), &k8smetav1.PatchOptions{DryRun: bodyStruct.DryRun})
case v1.RunStrategyRerunOnFailure, v1.RunStrategyAlways:
bodyString := getRunningJson(vm, false)
log.Log.Object(vm).V(4).Infof(patchingVM, bodyString)
log.Log.Object(vm).V(4).Infof(patchingVMFmt, bodyString)
_, patchErr = app.virtCli.VirtualMachine(namespace).Patch(vm.GetName(), patchType, []byte(bodyString), &k8smetav1.PatchOptions{DryRun: bodyStruct.DryRun})
}

Expand Down Expand Up @@ -662,7 +662,7 @@ func (app *SubresourceAPIApp) PauseVMIRequestHandler(request *restful.Request, r
case io.EOF, nil:
break
default:
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErr, err)), response)
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErrFmt, err)), response)
return
}
}
Expand Down Expand Up @@ -697,7 +697,7 @@ func (app *SubresourceAPIApp) UnpauseVMIRequestHandler(request *restful.Request,
case io.EOF, nil:
break
default:
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErr, err)), response)
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErrFmt, err)), response)
return
}
}
Expand Down Expand Up @@ -849,14 +849,14 @@ func (app *SubresourceAPIApp) GuestOSInfo(request *restful.Request, response *re

_, url, conn, err := app.prepareConnection(request, validate, getURL)
if err != nil {
log.Log.Errorf(prepConnectionErr, err.Error())
log.Log.Errorf(prepConnectionErrFmt, err.Error())
response.WriteError(http.StatusInternalServerError, err)
return
}

resp, conErr := conn.Get(url, app.handlerTLSConfiguration)
if conErr != nil {
log.Log.Errorf(getRequestErr, conErr.Error())
log.Log.Errorf(getRequestErrFmt, conErr.Error())
response.WriteError(http.StatusInternalServerError, conErr)
return
}
Expand Down Expand Up @@ -889,14 +889,14 @@ func (app *SubresourceAPIApp) UserList(request *restful.Request, response *restf

_, url, conn, err := app.prepareConnection(request, validate, getURL)
if err != nil {
log.Log.Errorf(prepConnectionErr, err.Error())
log.Log.Errorf(prepConnectionErrFmt, err.Error())
response.WriteError(http.StatusInternalServerError, err)
return
}

resp, conErr := conn.Get(url, app.handlerTLSConfiguration)
if conErr != nil {
log.Log.Errorf(getRequestErr, conErr.Error())
log.Log.Errorf(getRequestErrFmt, conErr.Error())
response.WriteError(http.StatusInternalServerError, conErr)
return
}
Expand Down Expand Up @@ -929,14 +929,14 @@ func (app *SubresourceAPIApp) FilesystemList(request *restful.Request, response

_, url, conn, err := app.prepareConnection(request, validate, getURL)
if err != nil {
log.Log.Errorf(prepConnectionErr, err.Error())
log.Log.Errorf(prepConnectionErrFmt, err.Error())
response.WriteError(http.StatusInternalServerError, err)
return
}

resp, conErr := conn.Get(url, app.handlerTLSConfiguration)
if conErr != nil {
log.Log.Errorf(getRequestErr, conErr.Error())
log.Log.Errorf(getRequestErrFmt, conErr.Error())
response.WriteError(http.StatusInternalServerError, conErr)
return
}
Expand Down Expand Up @@ -1116,7 +1116,7 @@ func (app *SubresourceAPIApp) addVolumeRequestHandler(request *restful.Request,
case io.EOF, nil:
break
default:
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErr, err)), response)
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErrFmt, err)), response)
return
}
} else {
Expand Down Expand Up @@ -1178,7 +1178,7 @@ func (app *SubresourceAPIApp) removeVolumeRequestHandler(request *restful.Reques
case io.EOF, nil:
break
default:
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErr,
writeError(errors.NewBadRequest(fmt.Sprintf(unmarshalRequestErrFmt,
err)), response)
return
}
Expand Down Expand Up @@ -1253,7 +1253,7 @@ func (app *SubresourceAPIApp) vmVolumePatchStatus(name, namespace string, volume
}

dryRunOption := app.getDryRunOption(volumeRequest)
log.Log.Object(vm).V(4).Infof(patchingVM, patch)
log.Log.Object(vm).V(4).Infof(patchingVMFmt, patch)
if err := app.statusUpdater.PatchStatus(vm, types.JSONPatchType, []byte(patch), &k8smetav1.PatchOptions{DryRun: dryRunOption}); err != nil {
log.Log.Object(vm).V(1).Errorf("unable to patch vm status: %v", err)
if errors.IsInvalid(err) {
Expand Down
Loading

0 comments on commit be32d95

Please sign in to comment.