Skip to content

K8SPG-777 set crVersion #1210

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

Merged
merged 10 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -5237,6 +5237,9 @@ spec:
Version of the operator. Update this to new version after operator
upgrade to apply changes to Kubernetes objects. Default is the latest
version.
enum:
- 2.7.0
pattern: ^$|^\d+\.\d+\.\d+$
type: string
dataSource:
description: Specifies a data source for bootstrapping the PostgreSQL
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/pgv2.percona.com_perconapgclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5644,6 +5644,9 @@ spec:
Version of the operator. Update this to new version after operator
upgrade to apply changes to Kubernetes objects. Default is the latest
version.
enum:
- 2.7.0
pattern: ^$|^\d+\.\d+\.\d+$
type: string
dataSource:
description: Specifies a data source for bootstrapping the PostgreSQL
Expand Down
3 changes: 3 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5941,6 +5941,9 @@ spec:
Version of the operator. Update this to new version after operator
upgrade to apply changes to Kubernetes objects. Default is the latest
version.
enum:
- 2.7.0
pattern: ^$|^\d+\.\d+\.\d+$
type: string
dataSource:
description: Specifies a data source for bootstrapping the PostgreSQL
Expand Down
3 changes: 3 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5941,6 +5941,9 @@ spec:
Version of the operator. Update this to new version after operator
upgrade to apply changes to Kubernetes objects. Default is the latest
version.
enum:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I use 2.6.0 with this CRD?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it was like en example.
how can we make it better?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

- 2.7.0
pattern: ^$|^\d+\.\d+\.\d+$
type: string
dataSource:
description: Specifies a data source for bootstrapping the PostgreSQL
Expand Down
3 changes: 3 additions & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5941,6 +5941,9 @@ spec:
Version of the operator. Update this to new version after operator
upgrade to apply changes to Kubernetes objects. Default is the latest
version.
enum:
- 2.7.0
pattern: ^$|^\d+\.\d+\.\d+$
type: string
dataSource:
description: Specifies a data source for bootstrapping the PostgreSQL
Expand Down
22 changes: 22 additions & 0 deletions percona/controller/pgcluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"reflect"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[goimports-reviser] reported by reviewdog 🐶

Suggested change
logf "sigs.k8s.io/controller-runtime/pkg/log"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the importing order here is wrong as correctly the linter complains. Also the alias for the import is not needed at all. We can drop it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have a look on this: #1210 (comment)

"slices"
"strings"
"time"
Expand Down Expand Up @@ -49,6 +50,7 @@ import (
"github.com/percona/percona-postgresql-operator/percona/pmm"
perconaPG "github.com/percona/percona-postgresql-operator/percona/postgres"
"github.com/percona/percona-postgresql-operator/percona/utils/registry"
"github.com/percona/percona-postgresql-operator/percona/version"
"github.com/percona/percona-postgresql-operator/percona/watcher"
v2 "github.com/percona/percona-postgresql-operator/pkg/apis/pgv2.percona.com/v2"
"github.com/percona/percona-postgresql-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
Expand Down Expand Up @@ -201,6 +203,9 @@ func (r *PGClusterReconciler) Reconcile(ctx context.Context, request reconcile.R
return ctrl.Result{}, errors.Wrap(err, "get PerconaPGCluster")
}

if err := r.setCRVersion(ctx, cr); err != nil {
return reconcile.Result{}, errors.Wrap(err, "set CR version")
}
cr.Default()

if cr.Spec.OpenShift == nil {
Expand Down Expand Up @@ -964,3 +969,20 @@ func (r *PGClusterReconciler) ensureFinalizers(ctx context.Context, cr *v2.Perco

return nil
}

func (r *PGClusterReconciler) setCRVersion(ctx context.Context, cr *v2.PerconaPGCluster) error {
if len(cr.Spec.CRVersion) > 0 {
return nil
}

orig := cr.DeepCopy()
cr.Spec.CRVersion = version.Version()

if err := r.Client.Patch(ctx, cr, client.MergeFrom(orig)); err != nil {
return errors.Wrap(err, "patch CR")
}

logf.FromContext(ctx).Info("Set CR version", "version", cr.Spec.CRVersion)

return nil
}
3 changes: 2 additions & 1 deletion pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v2

import (
"context"

gover "github.com/hashicorp/go-version"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -52,6 +51,8 @@ type PerconaPGClusterSpec struct {
// upgrade to apply changes to Kubernetes objects. Default is the latest
// version.
// +optional
// +kubebuilder:validation:Pattern=`^$|^\d+\.\d+\.\d+$`
// +kubebuilder:validation:Enum="2.7.0"
CRVersion string `json:"crVersion,omitempty"`

InitContainer *crunchyv1beta1.InitContainerSpec `json:"initContainer,omitempty"`
Expand Down
Loading