Skip to content

Commit 8788c6c

Browse files
committed
Move the operator updates into the regular reconcile loop
1 parent 6e5cca4 commit 8788c6c

File tree

3 files changed

+2
-58
lines changed

3 files changed

+2
-58
lines changed

controllers/postgres_controller.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,8 @@ func (r *PostgresReconciler) deleteUserPasswordsSecret(ctx context.Context, inst
485485
// ensureZalandoDependencies makes sure Zalando resources are installed in the service-cluster.
486486
func (r *PostgresReconciler) ensureZalandoDependencies(log logr.Logger, ctx context.Context, p *pg.Postgres, b *pg.BackupConfig) error {
487487
namespace := p.ToPeripheralResourceNamespace()
488-
isInstalled, err := r.OperatorManager.IsOperatorInstalled(ctx, namespace)
489-
if err != nil {
490-
return fmt.Errorf("error while querying if zalando dependencies are installed: %w", err)
491-
}
492-
493-
if !isInstalled {
494-
if err := r.OperatorManager.InstallOrUpdateOperator(ctx, namespace); err != nil {
495-
return fmt.Errorf("error while installing zalando dependencies: %w", err)
496-
}
488+
if err := r.OperatorManager.InstallOrUpdateOperator(ctx, namespace); err != nil {
489+
return fmt.Errorf("error while installing zalando dependencies: %w", err)
497490
}
498491

499492
if err := r.updatePodEnvironmentConfigMap(log, ctx, p, b); err != nil {

main.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,6 @@ func main() {
551551

552552
ctx := context.Background()
553553

554-
// update all existing operators to the current version
555-
if err := opMgr.UpdateAllManagedOperators(ctx); err != nil {
556-
setupLog.Error(err, "error updating the postgres operators")
557-
}
558-
559554
setupLog.Info("starting service cluster manager", "version", v.V)
560555
go func() {
561556
if err := svcClusterMgr.Start(ctx); err != nil {

pkg/operatormanager/operatormanager.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
pg "github.com/fi-ts/postgreslet/api/v1"
1919
"github.com/go-logr/logr"
20-
zalando "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
2120
appsv1 "k8s.io/api/apps/v1"
2221
corev1 "k8s.io/api/core/v1"
2322
rbacv1 "k8s.io/api/rbac/v1"
@@ -188,23 +187,6 @@ func (m *OperatorManager) IsOperatorDeletable(ctx context.Context, namespace str
188187
return true, nil
189188
}
190189

191-
// IsOperatorInstalled returns true when the operator is installed
192-
func (m *OperatorManager) IsOperatorInstalled(ctx context.Context, namespace string) (bool, error) {
193-
pods := &corev1.PodList{}
194-
opts := []client.ListOption{
195-
client.InNamespace(namespace),
196-
operatorPodMatchingLabels,
197-
}
198-
if err := m.client.List(ctx, pods, opts...); err != nil {
199-
return false, client.IgnoreNotFound(err)
200-
}
201-
if len(pods.Items) == 0 {
202-
return false, nil
203-
}
204-
m.log.Info("operator is installed", "ns", namespace)
205-
return true, nil
206-
}
207-
208190
// UninstallOperator uninstalls the operator
209191
func (m *OperatorManager) UninstallOperator(ctx context.Context, namespace string) error {
210192
items := m.list.Items
@@ -672,29 +654,3 @@ func (m *OperatorManager) toObjectKey(obj runtime.Object, namespace string) (cli
672654
Name: name,
673655
}, nil
674656
}
675-
676-
// UpdateAllManagedOperators Updates the manifests of all postgres operators managed by this postgreslet
677-
func (m *OperatorManager) UpdateAllManagedOperators(ctx context.Context) error {
678-
// fetch postgresql custom resource (running or otherwise)
679-
m.log.Info("Fetching all zalando custom resources managed by this postgreslet")
680-
matchingLabels := client.MatchingLabels{
681-
pg.PartitionIDLabelName: m.options.PartitionID,
682-
}
683-
zList := &zalando.PostgresqlList{}
684-
opts := []client.ListOption{
685-
matchingLabels,
686-
}
687-
if err := m.client.List(ctx, zList, opts...); err != nil {
688-
return client.IgnoreNotFound(err)
689-
}
690-
// update each namespace
691-
for _, z := range zList.Items {
692-
m.log.Info("Updating postgres operator installation", "ns", z.Namespace)
693-
if err := m.InstallOrUpdateOperator(ctx, z.Namespace); err != nil {
694-
return err
695-
}
696-
}
697-
698-
m.log.Info("Done updating postgres operators in managed namespaces")
699-
return nil
700-
}

0 commit comments

Comments
 (0)