Skip to content

Commit

Permalink
Merge pull request #274 from vshn/fix/scaling_pg_issue
Browse files Browse the repository at this point in the history
Set the correct version for the SGCluster
  • Loading branch information
TheBigLee authored Dec 3, 2024
2 parents 237beb2 + 99ff753 commit 90a90f4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
24 changes: 24 additions & 0 deletions pkg/comp-functions/functions/vshnpostgres/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/vshn/appcat/v4/pkg/comp-functions/runtime"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)
Expand Down Expand Up @@ -129,6 +130,11 @@ func addSchedules(ctx context.Context, comp *vshnv1.VSHNPostgreSQL, svc *runtime
},
}...)

err = setPsqlMinorVersion(svc, cluster)
if err != nil {
return runtime.NewWarningResult(fmt.Errorf("cannot set the minor version for the PostgreSQL instance: %w", err).Error())
}

backups := *cluster.Spec.Configurations.Backups
backups[0].CronSchedule = ptr.To(comp.GetBackupSchedule())
cluster.Spec.Configurations.Backups = &backups
Expand Down Expand Up @@ -178,3 +184,21 @@ func createMaintenanceSecret(instanceNamespace, sgNamespace, resourceName string
},
}
}

func setPsqlMinorVersion(svc *runtime.ServiceRuntime, desiredCluster *stackgresv1.SGCluster) error {
observedCluster := &stackgresv1.SGCluster{}
err := svc.GetObservedKubeObject(observedCluster, "cluster")
if errors.IsNotFound(err) {
// Cluster doesn't exist yet. So let's ignore it here
return nil
}
if err != nil {
return fmt.Errorf("cannot get observed cluster object: %w", err)
}

pgVersion := observedCluster.Spec.Postgres.Version

desiredCluster.Spec.Postgres.Version = pgVersion

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func TestPostgreSqlDeploy(t *testing.T) {
assert.Equal(t, comp.GetName(), cluster.Name)
assert.Equal(t, comp.GetInstanceNamespace(), cluster.Namespace)
assert.Equal(t, comp.Spec.Parameters.Instances, cluster.Spec.Instances)
assert.Equal(t, comp.Spec.Parameters.Service.MajorVersion, cluster.Spec.Postgres.Version)
assert.Nil(t, cluster.Spec.InitialData.Restore)
assert.Equal(t, comp.GetName(), *cluster.Spec.SgInstanceProfile)
assert.Equal(t, comp.GetName(), *cluster.Spec.Configurations.SgPostgresConfig)
Expand Down
2 changes: 1 addition & 1 deletion test/functions/vshn-postgres/deploy/01_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ observed:
privateKeySecretKeySelector:
key: tls.key
name: tls-certificate
version: "15"
version: "15.1"
sgInstanceProfile: psql-gc9x4
managementPolicy: Default
providerConfigRef:
Expand Down

0 comments on commit 90a90f4

Please sign in to comment.