Skip to content

Commit

Permalink
logserver - use deployLogServer function directly instead of CR
Browse files Browse the repository at this point in the history
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
  • Loading branch information
morucci committed Oct 20, 2023
1 parent 91f75f6 commit 7536294
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 62 deletions.
4 changes: 0 additions & 4 deletions controllers/logserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
74 changes: 16 additions & 58 deletions controllers/softwarefactory_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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, &current) {
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(&current)
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(&current)
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 {
Expand Down

0 comments on commit 7536294

Please sign in to comment.