From 08b26bc5737217e2d07de04bf20aa6f099f73cfc Mon Sep 17 00:00:00 2001 From: Mykola Morhun Date: Wed, 22 Sep 2021 13:12:33 +0300 Subject: [PATCH] fix: internal backup server url (#1072) Make internal backup server accessible in all namespaces mode Signed-off-by: Mykola Morhun --- .../internal_backup_server.go | 25 +++++++++++++------ pkg/backup_servers/backup_servers.go | 3 ++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/controllers/checlusterbackup/internal_backup_server.go b/controllers/checlusterbackup/internal_backup_server.go index 73cd7f7cc..8bc7a9a0e 100644 --- a/controllers/checlusterbackup/internal_backup_server.go +++ b/controllers/checlusterbackup/internal_backup_server.go @@ -14,10 +14,10 @@ package checlusterbackup import ( "context" "fmt" - "net/http" "strings" chev1 "github.com/eclipse-che/che-operator/api/v1" + "github.com/eclipse-che/che-operator/pkg/backup_servers" "github.com/eclipse-che/che-operator/pkg/deploy" "github.com/eclipse-che/che-operator/pkg/util" "github.com/sirupsen/logrus" @@ -45,10 +45,10 @@ func ConfigureInternalBackupServer(bctx *BackupContext) (bool, error) { taskList := []func(*BackupContext) (bool, error){ ensureInternalBackupServerDeploymentExist, ensureInternalBackupServerServiceExists, - ensureInternalBackupServerPodReady, ensureInternalBackupServerConfigurationExistAndCorrect, ensureInternalBackupServerConfigurationCurrent, ensureInternalBackupServerSecretExists, + ensureInternalBackupServerPodReady, } for _, task := range taskList { @@ -145,8 +145,16 @@ func ensureInternalBackupServerPodReady(bctx *BackupContext) (bool, error) { // It is not possible to implement the check via StartupProbe of the pod, // because the probe requires 2xx status, but a fresh REST server responds with 404 only. - restServerBaseUrl := fmt.Sprintf("http://%s:%d", backupServerServiceName, backupServerPort) - _, err := http.Head(restServerBaseUrl) + backupServer, err := backup_servers.NewBackupServer(bctx.backupServerConfigCR.Spec) + if err != nil { + return true, err + } + _, err = backupServer.PrepareConfiguration(bctx.r.client, bctx.namespace) + if err != nil { + return true, err + } + // Try to reach internal backup server: if it responds, then the server is ready. + _, _, err = backupServer.IsRepositoryExist() if err != nil { if strings.Contains(err.Error(), "connection refused") { // Internal REST server is not ready yet. Reconcile. @@ -223,7 +231,7 @@ func ensureInternalBackupServerConfigurationExistAndCorrect(bctx *BackupContext) err := bctx.r.client.Get(context.TODO(), namespacedName, internalBackupServerConfiguration) if err == nil { // Configuration exist, check if it is correct - expectedInternalRestServerConfig := getExpectedInternalRestServerConfiguration() + expectedInternalRestServerConfig := getExpectedInternalRestServerConfiguration(bctx) if *internalBackupServerConfiguration.Spec.Rest != *expectedInternalRestServerConfig { // Something is wrong in the configuration if err := bctx.r.client.Delete(context.TODO(), internalBackupServerConfiguration); err != nil { @@ -264,15 +272,16 @@ func getInternalBackupServerConfigurationSpec(bctx *BackupContext) *chev1.CheBac Labels: labels, }, Spec: chev1.CheBackupServerConfigurationSpec{ - Rest: getExpectedInternalRestServerConfiguration(), + Rest: getExpectedInternalRestServerConfiguration(bctx), }, } } -func getExpectedInternalRestServerConfiguration() *chev1.RestServerConfig { +func getExpectedInternalRestServerConfiguration(bctx *BackupContext) *chev1.RestServerConfig { + // Use service to communicate with internal backup server return &chev1.RestServerConfig{ Protocol: "http", - Hostname: backupServerServiceName, + Hostname: fmt.Sprintf("%s.%s.svc", backupServerServiceName, bctx.namespace), Port: backupServerPort, RepositoryPath: "che", RepositoryPasswordSecretRef: BackupServerRepoPasswordSecretName, diff --git a/pkg/backup_servers/backup_servers.go b/pkg/backup_servers/backup_servers.go index a5a18b5eb..c7a05dd59 100644 --- a/pkg/backup_servers/backup_servers.go +++ b/pkg/backup_servers/backup_servers.go @@ -29,7 +29,8 @@ type BackupServer interface { // InitRepository creates backup repository on the backup server side. InitRepository() (bool, error) - // IsRepositoryExist check whether the repository alredy innitialized. + // IsRepositoryExist check whether the repository alredy initialized. + // Returns: exists, done, error IsRepositoryExist() (bool, bool, error) // CheckRepository verifies ability to connect to the remote backup server.