fix: internal backup server url (#1072)

Make internal backup server accessible in all namespaces mode

Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
pull/1084/head
Mykola Morhun 2021-09-22 13:12:33 +03:00 committed by GitHub
parent 0b63bdc835
commit 08b26bc573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View File

@ -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,

View File

@ -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.