From 7536294333f29d8a3750443191130f1993989051 Mon Sep 17 00:00:00 2001 From: Fabien Boucher Date: Fri, 20 Oct 2023 10:33:34 +0000 Subject: [PATCH] logserver - use deployLogServer function directly instead of CR In order to enable the capability to run a SoftwareFactory deployment without the need to install the CRD, we need to relax some constraints. This change changes the SoftwareFactory controller to no rely on the LogServer controller to handle the logserver deployment. Change-Id: I99de3ea7e068b42b39337fa360501002168e9434 --- controllers/logserver_controller.go | 4 -- controllers/softwarefactory_controller.go | 74 +++++------------------ 2 files changed, 16 insertions(+), 62 deletions(-) diff --git a/controllers/logserver_controller.go b/controllers/logserver_controller.go index 48e60e7a..d8985b64 100644 --- a/controllers/logserver_controller.go +++ b/controllers/logserver_controller.go @@ -72,10 +72,6 @@ type LogServerController struct { cr sfv1.LogServer } -func isLogserverReady(logserver sfv1.LogServer) bool { - return logserver.Status.ObservedGeneration == logserver.Generation && logserver.Status.Ready -} - func getLogserverSettingsOrDefault(settings sfv1.LogServerSpecSettings) (int, int) { loopdelay := 3600 if settings.LoopDelay > 0 { diff --git a/controllers/softwarefactory_controller.go b/controllers/softwarefactory_controller.go index e0f53339..37ec7e73 100644 --- a/controllers/softwarefactory_controller.go +++ b/controllers/softwarefactory_controller.go @@ -26,7 +26,6 @@ import ( sfv1 "github.com/softwarefactory-project/sf-operator/api/v1" "github.com/softwarefactory-project/sf-operator/controllers/libs/conds" - "github.com/softwarefactory-project/sf-operator/controllers/libs/utils" ) type SoftwareFactoryReconciler struct { @@ -91,69 +90,28 @@ func isOperatorReady(services map[string]bool) bool { } func (r *SFController) DeployLogserverResource() bool { - - current := sfv1.LogServer{ + pubKey, err := r.getSecretDataFromKey("zuul-ssh-key", "pub") + if err != nil { + return false + } + pubKeyB64 := base64.StdEncoding.EncodeToString(pubKey) + cr := sfv1.LogServer{ ObjectMeta: metav1.ObjectMeta{ - Name: logserverIdent, - Namespace: r.ns, + Name: logserverIdent, }, - } - - loopdelay, retentiondays := getLogserverSettingsOrDefault(r.cr.Spec.Logserver) - storage := r.cr.Spec.Logserver.Storage - if storage.Size.IsZero() { - storage.Size = utils.Qty1Gi() - } - logServerSpecSettings := sfv1.LogServerSpecSettings{ - LoopDelay: loopdelay, - RetentionDays: retentiondays, - Storage: storage, - } - - if r.GetM(logserverIdent, ¤t) { - needUpdate := false - if current.Spec.Settings != logServerSpecSettings { - current.Spec.Settings = logServerSpecSettings - needUpdate = true - } - if r.cr.Spec.LetsEncrypt == nil && current.Spec.LetsEncrypt != nil { - current.Spec.LetsEncrypt = nil - needUpdate = true - } - if r.cr.Spec.LetsEncrypt != nil && current.Spec.LetsEncrypt == nil { - current.Spec.LetsEncrypt = r.cr.Spec.LetsEncrypt - needUpdate = true - } - if r.cr.Spec.LetsEncrypt != nil && current.Spec.LetsEncrypt != nil { - if *r.cr.Spec.LetsEncrypt != *current.Spec.LetsEncrypt { - current.Spec.LetsEncrypt = r.cr.Spec.LetsEncrypt - needUpdate = true - } - } - if needUpdate { - r.log.V(1).Info("Updating the logserver resource", "name", logserverIdent) - r.UpdateR(¤t) - return false - } - } else { - pubKey, err := r.getSecretDataFromKey("zuul-ssh-key", "pub") - if err != nil { - return false - } - pubKeyB64 := base64.StdEncoding.EncodeToString(pubKey) - current.Spec = sfv1.LogServerSpec{ + Spec: sfv1.LogServerSpec{ FQDN: r.cr.Spec.FQDN, - StorageClassName: r.cr.Spec.StorageClassName, LetsEncrypt: r.cr.Spec.LetsEncrypt, + StorageClassName: r.cr.Spec.Logserver.Storage.ClassName, AuthorizedSSHKey: pubKeyB64, - Settings: logServerSpecSettings, - } - r.log.V(1).Info("Creating the logserver resource", "name", logserverIdent) - r.CreateR(¤t) - return false + Settings: r.cr.Spec.Logserver, + }, } - - return isLogserverReady(current) + var logserverController = LogServerController{ + SFUtilContext: r.SFUtilContext, + cr: cr, + } + return logserverController.DeployLogserver().Ready } func (r *SFController) Step() sfv1.SoftwareFactoryStatus {