Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove the reverse DNS lookup which fails in multiple cases and takes unnecessarily long #115

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/move2kubeapi/move2kubeapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ For more information, visit https://move2kube.konveyor.io/`,
rootCmd.Flags().String(app+"-server-client-id", app+"-server", "The OAuth 2.0 client id for the server side.")
rootCmd.Flags().String(app+"-server-client-secret", "8a1340ff-de5d-42a0-8b40-b6239c7cfc58", "The OAuth 2.0 client secret for the server side.")
rootCmd.Flags().String("default-resource-id", "b4d9b0fd-ffdb-4533-9536-5c315af07352", "Resource id on the Keycloak server.")
rootCmd.Flags().String("host", "localhost", "The host name of the server.")
// CloudEvents
rootCmd.Flags().Bool("cloud-events-enabled", false, "Enable CloudEvents reporting.")
rootCmd.Flags().String("cloud-events-endpoint", "", "Endpoint where CloudEvents are reported.")
Expand Down
65 changes: 10 additions & 55 deletions internal/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,10 +1223,7 @@ func (fs *FileSystem) startPlanning(t *bolt.Tx, workspaceId, projectId string, d
}
message := "Project: " + project.Id + ";"
// This contains the metadata about a run (host and port of the plan progress server, etc.)
planProgressServerMeta := types.QAServerMetadata{Host: getDNSHostName(), Debug: debugMode}
if planProgressServerMeta.Host == "" {
planProgressServerMeta.Host = "localhost"
}
planProgressServerMeta := types.QAServerMetadata{Host: common.Config.Host, Debug: debugMode}
planProgressServerMeta.Port, err = freeport.GetFreePort()
if err != nil {
return fmt.Errorf("failed to get a free port. Error: %q", err)
Expand Down Expand Up @@ -1554,10 +1551,7 @@ func (fs *FileSystem) resumeTransformation(t *bolt.Tx, workspaceId, projectId, p
}
// update state
// resume the transformation
qaServerMeta.Host = getDNSHostName()
if qaServerMeta.Host == "" {
qaServerMeta.Host = "localhost"
}
qaServerMeta.Host = common.Config.Host
qaServerMeta.Port, err = freeport.GetFreePort()
if err != nil {
return fmt.Errorf("failed to get a free port. Error: %q", err)
Expand Down Expand Up @@ -1605,7 +1599,8 @@ func (fs *FileSystem) resumeTransformation(t *bolt.Tx, workspaceId, projectId, p
}
currentRunConfigPaths = append(commonConfigPaths, currentRunConfigPaths...)
}
go fs.runTransform(currentRunDir, currentRunConfigPaths, currentRunSrcDir, currentRunCustDir, currentRunOutDir, message, qaServerMeta.Port, transformCh, workspaceId, projectId, projOutput, debugMode)
// resume the transformation
go fs.runTransform(currentRunDir, currentRunConfigPaths, currentRunSrcDir, currentRunCustDir, currentRunOutDir, message, qaServerMeta.Port, transformCh, workspaceId, projectId, projOutput, debugMode, true)
return nil
}

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

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 {
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 {
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)
portStr, err := cast.ToStringE(port)
if err != nil {
return fmt.Errorf("failed to convert the port '%d' to a string. Error: %q", port, err)
}
cmdArgs := []string{"transform", "--qa-disable-cli", "--qa-port", portStr, "--source", currentRunSrcDir, "--output", currentRunOutDir, "--log-file", M2K_CLI_LOG_FILE}
if overwriteOutDir {
cmdArgs = append(cmdArgs, "--overwrite")
}
verbose := debugMode || isVerbose()
if verbose {
cmdArgs = append(cmdArgs, "--log-level", "trace")
Expand Down Expand Up @@ -2541,46 +2536,6 @@ func copyOverPlanConfigAndQACache(srcDir, destDir string) error {
return nil
}

func getDNSHostName() string {
logrus.Trace("getDNSHostName start")
dnsHostName := ""
ifaces, err := net.Interfaces()
if err != nil {
logrus.Errorf("failed to get the interfaces. Error: %q", err)
return ""
}
for _, iface := range ifaces {
addrs, err := iface.Addrs()
if err != nil {
logrus.Errorf("failed to get the addresses for the interface %s . Error: %q", iface.Name, err)
continue
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
}
ptr, err := net.LookupAddr(ip.String())
if err != nil {
logrus.Errorf("failed to do a reverse lookup for the address %s . Error: %q", addr.String(), err)
continue
}
for _, ptrvalue := range ptr {
logrus.Debugf("host: %s", ptrvalue)
if len(dnsHostName) <= len(ptrvalue) {
dnsHostName = ptrvalue
}
}
}
}
logrus.Debugf("dnsHostName: '%s'", dnsHostName)
logrus.Trace("getDNSHostName end")
return dnsHostName
}

// generateVerboseLogs synchronizes move2kube-api loggging level wrt move2kube logging level
func generateVerboseLogs(message string) {
var loggingLevel string
Expand Down
1 change: 1 addition & 0 deletions internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type ConfigT struct {
M2kServerClientId string `mapstructure:"m2k-server-client-id"`
M2kServerClientSecret string `mapstructure:"m2k-server-client-secret"`
DefaultResourceId string `mapstructure:"default-resource-id"`
Host string `mapstructure:"host"`
CloudEventsEndpoint string `mapstructure:"cloud-events-endpoint"`
CloudEventsAccessToken string `mapstructure:"cloud-events-access-token"`
CloudEventsSpecVersion string `mapstructure:"cloud-events-spec-version"`
Expand Down