Skip to content
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

Issue-729 External changes for clusterConfigurations of PostgreSQL CR #730

Merged
merged 1 commit into from
Feb 29, 2024
Merged
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
12 changes: 8 additions & 4 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
{
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
},
{
"path": "detect_secrets.filters.common.is_baseline_file",
"filename": ".secrets.baseline"
},
{
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
"min_level": 2
Expand Down Expand Up @@ -147,7 +151,7 @@
"filename": "apis/clusterresources/v1beta1/structs.go",
"hashed_secret": "e03127a337f643c1c0eb2b0e8683e9140e19120d",
"is_verified": false,
"line_number": 65
"line_number": 57
}
],
"apis/clusterresources/v1beta1/zz_generated.deepcopy.go": [
Expand All @@ -156,7 +160,7 @@
"filename": "apis/clusterresources/v1beta1/zz_generated.deepcopy.go",
"hashed_secret": "44e17306b837162269a410204daaa5ecee4ec22c",
"is_verified": false,
"line_number": 548
"line_number": 547
}
],
"apis/clusters/v1beta1/cadence_types.go": [
Expand Down Expand Up @@ -556,7 +560,7 @@
"filename": "controllers/clusters/postgresql_controller.go",
"hashed_secret": "5ffe533b830f08a0326348a9160afafc8ada44db",
"is_verified": false,
"line_number": 1221
"line_number": 1183
}
],
"controllers/clusters/zookeeper_controller_test.go": [
Expand Down Expand Up @@ -1128,5 +1132,5 @@
}
]
},
"generated_at": "2024-02-28T14:20:52Z"
"generated_at": "2024-02-29T10:48:32Z"
}
8 changes: 0 additions & 8 deletions apis/clusterresources/v1beta1/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package v1beta1

import (
"encoding/json"

"github.com/instaclustr/operator/pkg/apiextensions"

"k8s.io/apimachinery/pkg/types"
Expand All @@ -38,12 +36,6 @@ type PeeringStatus struct {
CDCID string `json:"cdcId,omitempty"`
}

type PatchRequest struct {
Operation string `json:"op"`
Path string `json:"path"`
Value json.RawMessage `json:"value"`
}

type FirewallRuleSpec struct {
ClusterID string `json:"clusterId,omitempty"`
Type string `json:"type"`
Expand Down
21 changes: 0 additions & 21 deletions apis/clusterresources/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions apis/clusters/v1beta1/postgresql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ type PgSpec struct {
//+kubebuilder:Validation:MinItems:=1
//+kubebuilder:Validation:MaxItems=2
DataCentres []*PgDataCentre `json:"dataCentres,omitempty"`
UserRefs []*Reference `json:"userRefs,omitempty" dcomparisonSkip:"true"`
//+kubebuilder:validate:MaxItems:=1
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty" dcomparisonSkip:"true"`
Extensions PgExtensions `json:"extensions,omitempty"`
Expand Down Expand Up @@ -285,7 +284,8 @@ func (pgs *PgSpec) IsEqual(iPG PgSpec) bool {
return pgs.GenericClusterSpec.Equals(&iPG.GenericClusterSpec) &&
pgs.SynchronousModeStrict == iPG.SynchronousModeStrict &&
pgs.DCsEqual(iPG.DataCentres) &&
slices.EqualsUnordered(pgs.Extensions, iPG.Extensions)
slices.EqualsUnordered(pgs.Extensions, iPG.Extensions) &&
pgs.ClusterConfigurationsEqual(iPG.ClusterConfigurations)
}

func (pgs *PgSpec) DCsEqual(instaModels []*PgDataCentre) bool {
Expand Down Expand Up @@ -550,10 +550,10 @@ func (pdc *PgDataCentre) PGBouncerFromInstAPI(instaModels []*models.PGBouncer) {
}
}

func (pgs *PgSpec) ClusterConfigurationsFromInstAPI(instaModels []*models.ClusterConfigurations) {
func (pgs *PgSpec) ClusterConfigurationsFromInstAPI(instaModels []*models.ConfigurationProperties) {
pgs.ClusterConfigurations = make(map[string]string, len(instaModels))
for _, instaModel := range instaModels {
pgs.ClusterConfigurations[instaModel.ParameterName] = instaModel.ParameterValue
pgs.ClusterConfigurations[instaModel.Name] = instaModel.Value
}
}

Expand Down Expand Up @@ -595,3 +595,18 @@ func (pgs *PgStatus) DCsEqual(o []*PgDataCentreStatus) bool {

return true
}

func (pgs *PgSpec) ClusterConfigurationsEqual(configs map[string]string) bool {
if len(pgs.ClusterConfigurations) != len(configs) {
return false
}

for k, v := range pgs.ClusterConfigurations {
param, ok := configs[k]
if !ok || v != param {
return false
}
}

return true
}
45 changes: 4 additions & 41 deletions apis/clusters/v1beta1/postgresql_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"unicode"

k8sCore "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -99,13 +98,6 @@ func (pgv *pgValidator) ValidateCreate(ctx context.Context, obj runtime.Object)
return err
}

if pg.Spec.UserRefs != nil {
err = pgv.validatePostgreSQLUsers(ctx, pg)
if err != nil {
return err
}
}

appVersions, err := pgv.API.ListAppVersions(models.PgAppKind)
if err != nil {
return fmt.Errorf("cannot list versions for kind: %v, err: %w",
Expand Down Expand Up @@ -159,6 +151,10 @@ func (pgv *pgValidator) ValidateCreate(ctx context.Context, obj runtime.Object)
}
}

if pg.Spec.ClusterConfigurations != nil {
return models.ErrPGClusterConfigurationsOnCreationNotAvailable
}

return nil
}

Expand Down Expand Up @@ -193,13 +189,6 @@ func (pgv *pgValidator) ValidateUpdate(ctx context.Context, old runtime.Object,
return pgv.ValidateCreate(ctx, pg)
}

if pg.Spec.UserRefs != nil {
err := pgv.validatePostgreSQLUsers(ctx, pg)
if err != nil {
return err
}
}

err := pg.Spec.ValidateImmutableFieldsUpdate(oldCluster.Spec)
if err != nil {
return fmt.Errorf("immutable fields validation error: %v", err)
Expand All @@ -220,32 +209,6 @@ func (pgv *pgValidator) ValidateUpdate(ctx context.Context, old runtime.Object,
return nil
}

func (pgv *pgValidator) validatePostgreSQLUsers(ctx context.Context, pg *PostgreSQL) error {
nodeList := &k8sCore.NodeList{}

err := pgv.K8sClient.List(ctx, nodeList, &client.ListOptions{})
if err != nil {
return fmt.Errorf("cannot list node list, error: %v", err)
}

var externalIPExists bool
for _, node := range nodeList.Items {
for _, nodeAddress := range node.Status.Addresses {
if nodeAddress.Type == k8sCore.NodeExternalIP {
externalIPExists = true
break
}
}
}

if !externalIPExists || pg.Spec.PrivateNetwork {
return fmt.Errorf("cannot create PostgreSQL user, if your cluster is private or has no external ips " +
"you need to configure peering and remove user references from cluster specification")
}

return nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (pgv *pgValidator) ValidateDelete(ctx context.Context, obj runtime.Object) error {
pg, ok := obj.(*PostgreSQL)
Expand Down
11 changes: 0 additions & 11 deletions apis/clusters/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions config/crd/bases/clusters.instaclustr.com_postgresqls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,6 @@ spec:
- email
type: object
type: array
userRefs:
items:
description: ObjectReference is namespaced reference to an object
properties:
name:
type: string
namespace:
type: string
required:
- name
- namespace
type: object
type: array
version:
type: string
type: object
Expand Down
9 changes: 3 additions & 6 deletions config/samples/clusters_v1beta1_postgresql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ spec:
# - replicationMode: "ASYNCHRONOUS"
# interDataCentreReplication:
# - isPrimaryDataCentre: false
# clusterConfigurations:
# idle_in_transaction_session_timeout: "2"
# statement_timeout: "1"
# clusterConfigurations:
# idle_in_transaction_session_timeout: "2"
# statement_timeout: "1"
# twoFactorDelete:
# - email: "rostyslp@netapp.com"
# description: "test 222"
slaTier: "NON_PRODUCTION"
# userRefs:
# - namespace: default
# name: postgresqluser-sample
privateNetwork: false
synchronousModeStrict: false
# extensions:
Expand Down
Loading
Loading