Skip to content

Commit

Permalink
Fix Long Startup Time for Kopia Repository Server (#2048)
Browse files Browse the repository at this point in the history
* Fix Long Startup for Kopia Repository Server

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Change Name of Functions

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Resolving Suggestions

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Reuse Redundant Code

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

---------

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>
Co-authored-by: kale-amruta <41624751+kale-amruta@users.noreply.github.com>
  • Loading branch information
r4rajat and kale-amruta authored May 10, 2023
1 parent 548dbeb commit 9ce4426
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions pkg/controllers/repositoryserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (h *RepoServerHandler) startRepoProxyServer(ctx context.Context) (err error
return errors.Wrap(err, "Failed to start Kopia API server")
}

err = h.checkServerStatus(ctx, repoServerAddress, serverAdminUserName, serverAdminPassword)
err = h.waitForServerReady(ctx, repoServerAddress, serverAdminUserName, serverAdminPassword)
if err != nil {
return errors.Wrap(err, "Failed to check Kopia API server status")
}
Expand All @@ -97,23 +97,21 @@ func (h *RepoServerHandler) getServerDetails(ctx context.Context) (string, strin
}

func (h *RepoServerHandler) checkServerStatus(ctx context.Context, serverAddress, username, password string) error {
fingerprint, err := kopia.ExtractFingerprintFromCertSecret(ctx, h.KubeCli, h.RepositoryServerSecrets.serverTLS.Name, h.RepositoryServer.Namespace)
cmd, err := h.getServerStatusCommand(ctx, serverAddress, username, password)
if err != nil {
return errors.Wrap(err, "Failed to extract fingerprint from Kopia API server certificate secret data")
}
cmd := command.ServerStatus(
command.ServerStatusCommandArgs{
CommandArgs: &command.CommandArgs{
RepoPassword: "",
ConfigFilePath: command.DefaultConfigFilePath,
LogDirectory: command.DefaultLogDirectory,
},
ServerAddress: serverAddress,
ServerUsername: username,
ServerPassword: password,
Fingerprint: fingerprint,
})
stdout, stderr, exErr := kube.Exec(h.KubeCli, h.RepositoryServer.Namespace, h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, cmd, nil)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout)
format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stderr)
return exErr
}

func (h *RepoServerHandler) waitForServerReady(ctx context.Context, serverAddress, username, password string) error {
cmd, err := h.getServerStatusCommand(ctx, serverAddress, username, password)
if err != nil {
return errors.Wrap(err, "Failed to extract fingerprint from Kopia API server certificate secret data")
}
serverStartTimeOut := h.getRepositoryServerStartTimeout()
ctx, cancel := context.WithTimeout(ctx, serverStartTimeOut)
defer cancel()
Expand Down Expand Up @@ -245,3 +243,23 @@ func (h *RepoServerHandler) getRepositoryServerStartTimeout() time.Duration {
}
return DefaultServerStartTimeout
}

func (h *RepoServerHandler) getServerStatusCommand(ctx context.Context, serverAddress, username, password string) ([]string, error) {
fingerprint, err := kopia.ExtractFingerprintFromCertSecret(ctx, h.KubeCli, h.RepositoryServerSecrets.serverTLS.Name, h.RepositoryServer.Namespace)
if err != nil {
return nil, errors.Wrap(err, "Failed to extract fingerprint from Kopia API server certificate secret data")
}
cmd := command.ServerStatus(
command.ServerStatusCommandArgs{
CommandArgs: &command.CommandArgs{
RepoPassword: "",
ConfigFilePath: command.DefaultConfigFilePath,
LogDirectory: command.DefaultLogDirectory,
},
ServerAddress: serverAddress,
ServerUsername: username,
ServerPassword: password,
Fingerprint: fingerprint,
})
return cmd, nil
}

0 comments on commit 9ce4426

Please sign in to comment.