Skip to content

Commit 1d6d641

Browse files
fix: remove the reverse DNS lookup which fails in multiple cases and takes unnecessarily long (#115)
* fix: remove the reverse DNS lookup which fails in multiple cases and takes unnecessarily long Signed-off-by: Harikrishnan Balagopal <[email protected]>
1 parent 05da828 commit 1d6d641

File tree

3 files changed

+12
-55
lines changed

3 files changed

+12
-55
lines changed

cmd/move2kubeapi/move2kubeapi.go

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ For more information, visit https://move2kube.konveyor.io/`,
7575
rootCmd.Flags().String(app+"-server-client-id", app+"-server", "The OAuth 2.0 client id for the server side.")
7676
rootCmd.Flags().String(app+"-server-client-secret", "8a1340ff-de5d-42a0-8b40-b6239c7cfc58", "The OAuth 2.0 client secret for the server side.")
7777
rootCmd.Flags().String("default-resource-id", "b4d9b0fd-ffdb-4533-9536-5c315af07352", "Resource id on the Keycloak server.")
78+
rootCmd.Flags().String("host", "localhost", "The host name of the server.")
7879
// CloudEvents
7980
rootCmd.Flags().Bool("cloud-events-enabled", false, "Enable CloudEvents reporting.")
8081
rootCmd.Flags().String("cloud-events-endpoint", "", "Endpoint where CloudEvents are reported.")

internal/filesystem/filesystem.go

+10-55
Original file line numberDiff line numberDiff line change
@@ -1223,10 +1223,7 @@ func (fs *FileSystem) startPlanning(t *bolt.Tx, workspaceId, projectId string, d
12231223
}
12241224
message := "Project: " + project.Id + ";"
12251225
// This contains the metadata about a run (host and port of the plan progress server, etc.)
1226-
planProgressServerMeta := types.QAServerMetadata{Host: getDNSHostName(), Debug: debugMode}
1227-
if planProgressServerMeta.Host == "" {
1228-
planProgressServerMeta.Host = "localhost"
1229-
}
1226+
planProgressServerMeta := types.QAServerMetadata{Host: common.Config.Host, Debug: debugMode}
12301227
planProgressServerMeta.Port, err = freeport.GetFreePort()
12311228
if err != nil {
12321229
return fmt.Errorf("failed to get a free port. Error: %q", err)
@@ -1554,10 +1551,7 @@ func (fs *FileSystem) resumeTransformation(t *bolt.Tx, workspaceId, projectId, p
15541551
}
15551552
// update state
15561553
// resume the transformation
1557-
qaServerMeta.Host = getDNSHostName()
1558-
if qaServerMeta.Host == "" {
1559-
qaServerMeta.Host = "localhost"
1560-
}
1554+
qaServerMeta.Host = common.Config.Host
15611555
qaServerMeta.Port, err = freeport.GetFreePort()
15621556
if err != nil {
15631557
return fmt.Errorf("failed to get a free port. Error: %q", err)
@@ -1605,7 +1599,8 @@ func (fs *FileSystem) resumeTransformation(t *bolt.Tx, workspaceId, projectId, p
16051599
}
16061600
currentRunConfigPaths = append(commonConfigPaths, currentRunConfigPaths...)
16071601
}
1608-
go fs.runTransform(currentRunDir, currentRunConfigPaths, currentRunSrcDir, currentRunCustDir, currentRunOutDir, message, qaServerMeta.Port, transformCh, workspaceId, projectId, projOutput, debugMode)
1602+
// resume the transformation
1603+
go fs.runTransform(currentRunDir, currentRunConfigPaths, currentRunSrcDir, currentRunCustDir, currentRunOutDir, message, qaServerMeta.Port, transformCh, workspaceId, projectId, projOutput, debugMode, true)
16091604
return nil
16101605
}
16111606

@@ -1686,10 +1681,7 @@ func (fs *FileSystem) startTransformation(t *bolt.Tx, workspaceId, projectId str
16861681
return fmt.Errorf("failed to update the project with id %s . Error: %q", projectId, err)
16871682
}
16881683
// This file contains the metadata about a run (host and port of the QA engine's http server, etc.)
1689-
qaServerMeta := types.QAServerMetadata{Host: getDNSHostName(), Debug: debugMode}
1690-
if qaServerMeta.Host == "" {
1691-
qaServerMeta.Host = "localhost"
1692-
}
1684+
qaServerMeta := types.QAServerMetadata{Host: common.Config.Host, Debug: debugMode}
16931685
qaServerMeta.Port, err = freeport.GetFreePort()
16941686
if err != nil {
16951687
return fmt.Errorf("failed to get a free port. Error: %q", err)
@@ -1797,7 +1789,7 @@ func (fs *FileSystem) startTransformation(t *bolt.Tx, workspaceId, projectId str
17971789
currentRunConfigPaths = append(commonConfigPaths, currentRunConfigPaths...)
17981790
}
17991791
// start the transformation
1800-
go fs.runTransform(currentRunDir, currentRunConfigPaths, currentRunSrcDir, currentRunCustDir, currentRunOutDir, message, qaServerMeta.Port, transformCh, workspaceId, projectId, projOutput, debugMode)
1792+
go fs.runTransform(currentRunDir, currentRunConfigPaths, currentRunSrcDir, currentRunCustDir, currentRunOutDir, message, qaServerMeta.Port, transformCh, workspaceId, projectId, projOutput, debugMode, false)
18011793
logrus.Infof("Waiting for QA engine to start for the output %s of the project %s", projOutput.Id, projectId)
18021794
if err := <-transformCh; err != nil {
18031795
return fmt.Errorf("failed to start the transformation and qa engine. Error: %q", err)
@@ -2338,13 +2330,16 @@ func (fs *FileSystem) runPlan(currentRunDir string, currentRunConfigPaths []stri
23382330
return err
23392331
}
23402332

2341-
func (fs *FileSystem) runTransform(currentRunDir string, currentRunConfigPaths []string, currentRunSrcDir, currentRunCustDir, currentRunOutDir, message string, port int, transformCh chan error, workspaceId, projectId string, projOutput types.ProjectOutput, debugMode bool) error {
2333+
func (fs *FileSystem) runTransform(currentRunDir string, currentRunConfigPaths []string, currentRunSrcDir, currentRunCustDir, currentRunOutDir, message string, port int, transformCh chan error, workspaceId, projectId string, projOutput types.ProjectOutput, debugMode bool, overwriteOutDir bool) error {
23422334
logrus.Infof("Starting transformation in %s with configs from %+v and source from %s , customizations from %s and output to %s", currentRunDir, currentRunConfigPaths, currentRunSrcDir, currentRunCustDir, currentRunOutDir)
23432335
portStr, err := cast.ToStringE(port)
23442336
if err != nil {
23452337
return fmt.Errorf("failed to convert the port '%d' to a string. Error: %q", port, err)
23462338
}
23472339
cmdArgs := []string{"transform", "--qa-disable-cli", "--qa-port", portStr, "--source", currentRunSrcDir, "--output", currentRunOutDir, "--log-file", M2K_CLI_LOG_FILE}
2340+
if overwriteOutDir {
2341+
cmdArgs = append(cmdArgs, "--overwrite")
2342+
}
23482343
verbose := debugMode || isVerbose()
23492344
if verbose {
23502345
cmdArgs = append(cmdArgs, "--log-level", "trace")
@@ -2541,46 +2536,6 @@ func copyOverPlanConfigAndQACache(srcDir, destDir string) error {
25412536
return nil
25422537
}
25432538

2544-
func getDNSHostName() string {
2545-
logrus.Trace("getDNSHostName start")
2546-
dnsHostName := ""
2547-
ifaces, err := net.Interfaces()
2548-
if err != nil {
2549-
logrus.Errorf("failed to get the interfaces. Error: %q", err)
2550-
return ""
2551-
}
2552-
for _, iface := range ifaces {
2553-
addrs, err := iface.Addrs()
2554-
if err != nil {
2555-
logrus.Errorf("failed to get the addresses for the interface %s . Error: %q", iface.Name, err)
2556-
continue
2557-
}
2558-
for _, addr := range addrs {
2559-
var ip net.IP
2560-
switch v := addr.(type) {
2561-
case *net.IPNet:
2562-
ip = v.IP
2563-
case *net.IPAddr:
2564-
ip = v.IP
2565-
}
2566-
ptr, err := net.LookupAddr(ip.String())
2567-
if err != nil {
2568-
logrus.Errorf("failed to do a reverse lookup for the address %s . Error: %q", addr.String(), err)
2569-
continue
2570-
}
2571-
for _, ptrvalue := range ptr {
2572-
logrus.Debugf("host: %s", ptrvalue)
2573-
if len(dnsHostName) <= len(ptrvalue) {
2574-
dnsHostName = ptrvalue
2575-
}
2576-
}
2577-
}
2578-
}
2579-
logrus.Debugf("dnsHostName: '%s'", dnsHostName)
2580-
logrus.Trace("getDNSHostName end")
2581-
return dnsHostName
2582-
}
2583-
25842539
// generateVerboseLogs synchronizes move2kube-api loggging level wrt move2kube logging level
25852540
func generateVerboseLogs(message string) {
25862541
var loggingLevel string

internal/types/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type ConfigT struct {
5656
M2kServerClientId string `mapstructure:"m2k-server-client-id"`
5757
M2kServerClientSecret string `mapstructure:"m2k-server-client-secret"`
5858
DefaultResourceId string `mapstructure:"default-resource-id"`
59+
Host string `mapstructure:"host"`
5960
CloudEventsEndpoint string `mapstructure:"cloud-events-endpoint"`
6061
CloudEventsAccessToken string `mapstructure:"cloud-events-access-token"`
6162
CloudEventsSpecVersion string `mapstructure:"cloud-events-spec-version"`

0 commit comments

Comments
 (0)