Skip to content

Commit

Permalink
clusterresources for postgres were migrated to reference pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
tengu-alt committed Oct 18, 2023
1 parent 4d5d744 commit 8d6411a
Show file tree
Hide file tree
Showing 43 changed files with 828 additions and 134 deletions.
9 changes: 1 addition & 8 deletions apis/clusterresources/v1beta1/awsvpcpeering_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ func (aws *AWSVPCPeeringSpec) newImmutableFields() *immutableAWSVPCPeeringFields
peerAWSAccountID: aws.PeerAWSAccountID,
peerRegion: aws.PeerRegion,
},
immutablePeeringFields{
DataCentreID: aws.DataCentreID,
},
immutablePeeringFields{},
}
}

Expand Down Expand Up @@ -125,11 +123,6 @@ func (aws *AWSVPCPeeringSpec) Validate(availableRegions []string) error {
return fmt.Errorf("VPC ID must begin with 'vpc-' and fit pattern: %s. %v", models.PeerVPCIDRegExp, err)
}

dataCentreIDMatched, err := regexp.Match(models.UUIDStringRegExp, []byte(aws.DataCentreID))
if !dataCentreIDMatched || err != nil {
return fmt.Errorf("data centre ID is a UUID formated string. It must fit the pattern: %s. %v", models.UUIDStringRegExp, err)
}

if !validation.Contains(aws.PeerRegion, availableRegions) {
return fmt.Errorf("AWS Region to peer: %s is unavailable, available regions: %v",
aws.PeerRegion, availableRegions)
Expand Down
4 changes: 0 additions & 4 deletions apis/clusterresources/v1beta1/awsvpcpeering_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ func (r *AWSVPCPeering) ValidateCreate() error {
return fmt.Errorf("peer AWS Account Region is empty")
}

if r.Spec.DataCentreID == "" {
return fmt.Errorf("dataCentre ID is empty")
}

if r.Spec.PeerSubnets == nil {
return fmt.Errorf("peer Subnets list is empty")
}
Expand Down
8 changes: 0 additions & 8 deletions apis/clusterresources/v1beta1/azurevnetpeering_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,6 @@ func init() {
}

func (azure *AzureVNetPeeringSpec) Validate() error {
dataCentreIDMatched, err := regexp.Match(models.UUIDStringRegExp, []byte(azure.DataCentreID))
if err != nil {
return err
}
if !dataCentreIDMatched {
return fmt.Errorf("data centre ID is a UUID formated string. It must fit the pattern: %s", models.UUIDStringRegExp)
}

for _, subnet := range azure.PeerSubnets {
peerSubnetMatched, err := regexp.Match(models.PeerSubnetsRegExp, []byte(subnet))
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions apis/clusterresources/v1beta1/azurevnetpeering_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ func (r *AzureVNetPeering) ValidateCreate() error {
return fmt.Errorf("peer Subscription ID is empty")
}

if r.Spec.DataCentreID == "" {
return fmt.Errorf("dataCentre ID is empty")
}

if r.Spec.PeerSubnets == nil {
return fmt.Errorf("peer Subnets list is empty")
}
Expand Down
2 changes: 1 addition & 1 deletion apis/clusterresources/v1beta1/clusterbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

// ClusterBackupSpec defines the desired state of ClusterBackup
type ClusterBackupSpec struct {
ClusterID string `json:"clusterId"`
ClusterID string `json:"clusterId,omitempty"`
ClusterKind string `json:"clusterKind"`
}

Expand Down
2 changes: 1 addition & 1 deletion apis/clusterresources/v1beta1/clusterbackup_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"

"github.com/instaclustr/operator/pkg/models"
)

Expand Down
2 changes: 1 addition & 1 deletion apis/clusterresources/v1beta1/exclusionwindow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

// ExclusionWindowSpec defines the desired state of ExclusionWindow
type ExclusionWindowSpec struct {
ClusterID string `json:"clusterId"`
ClusterID string `json:"clusterId,omitempty"`
DayOfWeek string `json:"dayOfWeek"`
//+kubebuilder:validation:Minimum:=0
//+kubebuilder:validation:Maximum:=23
Expand Down
1 change: 0 additions & 1 deletion apis/clusterresources/v1beta1/maintenanceevents_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

// MaintenanceEventsSpec defines the desired state of MaintenanceEvents
type MaintenanceEventsSpec struct {
ClusterID string `json:"clusterId"`
MaintenanceEventsReschedules []*MaintenanceEventReschedule `json:"maintenanceEventsReschedule"`
}

Expand Down
4 changes: 2 additions & 2 deletions apis/clusterresources/v1beta1/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

type VPCPeeringSpec struct {
DataCentreID string `json:"cdcId"`
DataCentreID string `json:"cdcId,omitempty"`
PeerSubnets []string `json:"peerSubnets"`
}

Expand All @@ -39,7 +39,7 @@ type PatchRequest struct {
}

type FirewallRuleSpec struct {
ClusterID string `json:"clusterId"`
ClusterID string `json:"clusterId,omitempty"`
Type string `json:"type"`
}

Expand Down
16 changes: 12 additions & 4 deletions apis/clusters/v1beta1/postgresql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,21 @@ type PgSpec struct {
ClusterConfigurations map[string]string `json:"clusterConfigurations,omitempty"`
SynchronousModeStrict bool `json:"synchronousModeStrict,omitempty"`
UserRefs []*UserReference `json:"userRefs,omitempty"`
ClusterResourceRefs *ClusterResourceRefs `json:"clusterResourceRefs,omitempty"`
//+kubebuilder:validate:MaxItems:=1
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
}

type ClusterResourceRefs struct {
ClusterBackups []*UserReference `json:"clusterBackups,omitempty"`
ClusterNetworkFirewallRules []*UserReference `json:"clusterNetworkFirewallRules,omitempty"`
AWSVPCPeerings []*UserReference `json:"awsVPCPeerings,omitempty"`
AWSSecurityGroupFirewallRules []*UserReference `json:"awsSecurityGroupFirewallRules,omitempty"`
ExclusionWindows []*UserReference `json:"exclusionWindows,omitempty"`
GCPVPCPeerings []*UserReference `json:"gcpVPCPeerings,omitempty"`
AzureVNetPeerings []*UserReference `json:"azureVNetPeerings,omitempty"`
}

// PgStatus defines the observed state of PostgreSQL
type PgStatus struct {
ClusterStatus `json:",inline"`
Expand Down Expand Up @@ -154,12 +165,11 @@ func (pg *PostgreSQL) NewBackupSpec(startTimestamp int) *clusterresourcesv1beta1
ObjectMeta: ctrl.ObjectMeta{
Name: models.PgBackupPrefix + pg.Status.ID + "-" + strconv.Itoa(startTimestamp),
Namespace: pg.Namespace,
Annotations: map[string]string{models.StartTimestampAnnotation: strconv.Itoa(startTimestamp)},
Annotations: map[string]string{models.StartTimestampAnnotation: strconv.Itoa(startTimestamp), models.ClusterIDAnnotation: pg.Status.ID},
Labels: map[string]string{models.ClusterIDLabel: pg.Status.ID},
Finalizers: []string{models.DeletionFinalizer},
},
Spec: clusterresourcesv1beta1.ClusterBackupSpec{
ClusterID: pg.Status.ID,
ClusterKind: models.PgClusterKind,
},
}
Expand Down Expand Up @@ -195,7 +205,6 @@ func (pgs *PgSpec) ToInstAPI() *models.PGCluster {
PostgreSQLVersion: pgs.Version,
DataCentres: pgs.DCsToInstAPI(),
SynchronousModeStrict: pgs.SynchronousModeStrict,
Description: pgs.Description,
PrivateNetworkCluster: pgs.PrivateNetworkCluster,
SLATier: pgs.SLATier,
TwoFactorDelete: pgs.TwoFactorDeletesToInstAPI(),
Expand Down Expand Up @@ -555,7 +564,6 @@ func (pgs *PgSpec) FromInstAPI(iPg *models.PGCluster) PgSpec {
Version: iPg.PostgreSQLVersion,
PCICompliance: iPg.PCIComplianceMode,
PrivateNetworkCluster: iPg.PrivateNetworkCluster,
Description: iPg.Description,
SLATier: iPg.SLATier,
TwoFactorDelete: pgs.Cluster.TwoFactorDeleteFromInstAPI(iPg.TwoFactorDelete),
},
Expand Down
97 changes: 97 additions & 0 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.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ spec:
type:
type: string
required:
- clusterId
- securityGroupId
- type
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ spec:
peerVpcId:
type: string
required:
- cdcId
- peerAwsAccountId
- peerSubnets
- peerVpcId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ spec:
peerVirtualNetworkName:
type: string
required:
- cdcId
- peerResourceGroup
- peerSubnets
- peerSubscriptionId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ spec:
clusterKind:
type: string
required:
- clusterId
- clusterKind
type: object
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ spec:
type:
type: string
required:
- clusterId
- network
- type
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ spec:
minimum: 0
type: integer
required:
- clusterId
- dayOfWeek
- durationInHours
- startHour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ spec:
peerVpcNetworkName:
type: string
required:
- cdcId
- peerProjectId
- peerSubnets
- peerVpcNetworkName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ spec:
spec:
description: MaintenanceEventsSpec defines the desired state of MaintenanceEvents
properties:
clusterId:
type: string
maintenanceEventsReschedule:
items:
properties:
Expand All @@ -50,7 +48,6 @@ spec:
type: object
type: array
required:
- clusterId
- maintenanceEventsReschedule
type: object
status:
Expand Down
Loading

0 comments on commit 8d6411a

Please sign in to comment.