Skip to content

Move the operator updates into the regular reconcile loop #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions controllers/postgres_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,8 @@ func (r *PostgresReconciler) deleteUserPasswordsSecret(ctx context.Context, inst
// ensureZalandoDependencies makes sure Zalando resources are installed in the service-cluster.
func (r *PostgresReconciler) ensureZalandoDependencies(log logr.Logger, ctx context.Context, p *pg.Postgres, b *pg.BackupConfig) error {
namespace := p.ToPeripheralResourceNamespace()
isInstalled, err := r.OperatorManager.IsOperatorInstalled(ctx, namespace)
if err != nil {
return fmt.Errorf("error while querying if zalando dependencies are installed: %w", err)
}

if !isInstalled {
if err := r.OperatorManager.InstallOrUpdateOperator(ctx, namespace); err != nil {
return fmt.Errorf("error while installing zalando dependencies: %w", err)
}
if err := r.OperatorManager.InstallOrUpdateOperator(ctx, namespace); err != nil {
return fmt.Errorf("error while installing zalando dependencies: %w", err)
}

if err := r.updatePodEnvironmentConfigMap(log, ctx, p, b); err != nil {
Expand Down
5 changes: 0 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,6 @@ func main() {

ctx := context.Background()

// update all existing operators to the current version
if err := opMgr.UpdateAllManagedOperators(ctx); err != nil {
setupLog.Error(err, "error updating the postgres operators")
}

setupLog.Info("starting service cluster manager", "version", v.V)
go func() {
if err := svcClusterMgr.Start(ctx); err != nil {
Expand Down
50 changes: 0 additions & 50 deletions pkg/operatormanager/operatormanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

pg "github.com/fi-ts/postgreslet/api/v1"
"github.com/go-logr/logr"
zalando "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
Expand All @@ -40,9 +39,6 @@ const (
// PodEnvSecretName Name of the pod environment secret to create and use
PodEnvSecretName string = "postgres-pod-secret" //nolint:gosec

operatorPodLabelName string = "name"
operatorPodLabelValue string = "postgres-operator"

// SidecarsCMFluentBitConfKey Name of the key containing the fluent-bit.conf config file
SidecarsCMFluentBitConfKey string = "fluent-bit.conf"
// SidecarsCMExporterQueriesKey Name of the key containing the queries.yaml config file
Expand All @@ -54,9 +50,6 @@ const (
debugLogLevel int = 1
)

// operatorPodMatchingLabels is for listing operator pods
var operatorPodMatchingLabels = client.MatchingLabels{operatorPodLabelName: operatorPodLabelValue}

// Options
type Options struct {
PspName string
Expand Down Expand Up @@ -188,23 +181,6 @@ func (m *OperatorManager) IsOperatorDeletable(ctx context.Context, namespace str
return true, nil
}

// IsOperatorInstalled returns true when the operator is installed
func (m *OperatorManager) IsOperatorInstalled(ctx context.Context, namespace string) (bool, error) {
pods := &corev1.PodList{}
opts := []client.ListOption{
client.InNamespace(namespace),
operatorPodMatchingLabels,
}
if err := m.client.List(ctx, pods, opts...); err != nil {
return false, client.IgnoreNotFound(err)
}
if len(pods.Items) == 0 {
return false, nil
}
m.log.Info("operator is installed", "ns", namespace)
return true, nil
}

// UninstallOperator uninstalls the operator
func (m *OperatorManager) UninstallOperator(ctx context.Context, namespace string) error {
items := m.list.Items
Expand Down Expand Up @@ -672,29 +648,3 @@ func (m *OperatorManager) toObjectKey(obj runtime.Object, namespace string) (cli
Name: name,
}, nil
}

// UpdateAllManagedOperators Updates the manifests of all postgres operators managed by this postgreslet
func (m *OperatorManager) UpdateAllManagedOperators(ctx context.Context) error {
// fetch postgresql custom resource (running or otherwise)
m.log.Info("Fetching all zalando custom resources managed by this postgreslet")
matchingLabels := client.MatchingLabels{
pg.PartitionIDLabelName: m.options.PartitionID,
}
zList := &zalando.PostgresqlList{}
opts := []client.ListOption{
matchingLabels,
}
if err := m.client.List(ctx, zList, opts...); err != nil {
return client.IgnoreNotFound(err)
}
// update each namespace
for _, z := range zList.Items {
m.log.Info("Updating postgres operator installation", "ns", z.Namespace)
if err := m.InstallOrUpdateOperator(ctx, z.Namespace); err != nil {
return err
}
}

m.log.Info("Done updating postgres operators in managed namespaces")
return nil
}