Skip to content

Commit

Permalink
Merge "logserver - use deployLogServer function directly instead of CR"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul CI authored and Gerrit Code Review committed Oct 24, 2023
2 parents 57b55ee + 7536294 commit c5e9a49
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 c5e9a49

Please sign in to comment.