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

Clusterresources refs for other clusters #625

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ func (fr *AWSSecurityGroupFirewallRule) NewPatch() client.Patch {
return client.MergeFrom(old)
}

func (fr *AWSSecurityGroupFirewallRule) AttachToCluster(id string) {
fr.Status.ClusterID = id
fr.Status.ResourceState = models.CreatingEvent
}

func (fr *AWSSecurityGroupFirewallRule) DetachFromCluster() {
fr.Status.ResourceState = models.DeletingEvent
}

func init() {
SchemeBuilder.Register(&AWSSecurityGroupFirewallRule{}, &AWSSecurityGroupFirewallRuleList{})
}
21 changes: 10 additions & 11 deletions apis/clusterresources/v1beta1/awsvpcpeering_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ func (aws *AWSVPCPeering) NewPatch() client.Patch {
return client.MergeFrom(old)
}

func (aws *AWSVPCPeering) AttachToCluster(id string) {
aws.Status.CDCID = id
aws.Status.ResourceState = models.CreatingEvent
}

func (aws *AWSVPCPeering) DetachFromCluster() {
aws.Status.ResourceState = models.DeletingEvent
}

func init() {
SchemeBuilder.Register(&AWSVPCPeering{}, &AWSVPCPeeringList{})
}

type immutableAWSVPCPeeringFields struct {
specificFields specificAWSVPCPeeringFields
peering immutablePeeringFields
}

type specificAWSVPCPeeringFields struct {
Expand All @@ -91,9 +99,6 @@ func (aws *AWSVPCPeeringSpec) newImmutableFields() *immutableAWSVPCPeeringFields
peerAWSAccountID: aws.PeerAWSAccountID,
peerRegion: aws.PeerRegion,
},
immutablePeeringFields{
DataCentreID: aws.DataCentreID,
},
}
}

Expand All @@ -106,8 +111,7 @@ func (aws *AWSVPCPeeringSpec) ValidateUpdate(oldSpec AWSVPCPeeringSpec) error {
return err
}

if newImmutableFields.peering != oldImmutableFields.peering ||
newImmutableFields.specificFields != oldImmutableFields.specificFields {
if newImmutableFields.specificFields != oldImmutableFields.specificFields {
return fmt.Errorf("cannot update immutable fields: old spec: %+v: new spec: %+v", oldSpec, aws)
}

Expand All @@ -125,11 +129,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
17 changes: 9 additions & 8 deletions apis/clusterresources/v1beta1/azurevnetpeering_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,20 @@ func (azure *AzureVNetPeering) NewPatch() client.Patch {
return client.MergeFrom(old)
}

func (azure *AzureVNetPeering) AttachToCluster(id string) {
azure.Status.CDCID = id
azure.Status.ResourceState = models.CreatingEvent
}

func (azure *AzureVNetPeering) DetachFromCluster() {
azure.Status.ResourceState = models.DeletingEvent
}

func init() {
SchemeBuilder.Register(&AzureVNetPeering{}, &AzureVNetPeeringList{})
}

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
10 changes: 9 additions & 1 deletion apis/clusterresources/v1beta1/clusterbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

// ClusterBackupSpec defines the desired state of ClusterBackup
type ClusterBackupSpec struct {
ClusterID string `json:"clusterId"`
ClusterKind string `json:"clusterKind"`
}
Comment on lines 29 to 31
Copy link
Contributor

Choose a reason for hiding this comment

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

ClusterKind you can move simply into the Status and thus you will remove and simplify the code that calculates the appropriate Kind.
Another consideration is whether triggering a backup through a cluster spec enhances the user experience. Need to ask what others think.


Expand All @@ -37,6 +36,7 @@ type ClusterBackupStatus struct {
Progress string `json:"progress,omitempty"`
Start int `json:"start,omitempty"`
End int `json:"end,omitempty"`
ClusterID string `json:"clusterId,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -71,6 +71,14 @@ func (cbs *ClusterBackupStatus) UpdateStatus(instBackup *models.BackupEvent) {
cbs.Progress = fmt.Sprintf("%f", instBackup.Progress)
}

func (cb *ClusterBackup) AttachToCluster(id string) {
cb.Status.ClusterID = id
}

func (cb *ClusterBackup) DetachFromCluster() {

}

func init() {
SchemeBuilder.Register(&ClusterBackup{}, &ClusterBackupList{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ func (fr *ClusterNetworkFirewallRule) NewPatch() client.Patch {
return client.MergeFrom(old)
}

func (fr *ClusterNetworkFirewallRule) AttachToCluster(id string) {
fr.Status.ClusterID = id
fr.Status.ResourceState = models.CreatingEvent
}

func (fr *ClusterNetworkFirewallRule) DetachFromCluster() {
fr.Status.ResourceState = models.DeletingEvent
}

func init() {
SchemeBuilder.Register(&ClusterNetworkFirewallRule{}, &ClusterNetworkFirewallRuleList{})
}
20 changes: 16 additions & 4 deletions apis/clusterresources/v1beta1/exclusionwindow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package v1beta1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

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

// ExclusionWindowSpec defines the desired state of ExclusionWindow
type ExclusionWindowSpec struct {
ClusterID string `json:"clusterId"`
DayOfWeek string `json:"dayOfWeek"`
//+kubebuilder:validation:Minimum:=0
//+kubebuilder:validation:Maximum:=23
Expand All @@ -36,7 +37,9 @@ type ExclusionWindowSpec struct {

// ExclusionWindowStatus defines the observed state of ExclusionWindow
type ExclusionWindowStatus struct {
ID string `json:"id"`
ID string `json:"id,omitempty"`
ClusterID string `json:"clusterId,omitempty"`
ResourceState string `json:"resourceState,omitempty"`
}

//+kubebuilder:object:root=true
Expand All @@ -60,11 +63,20 @@ type ExclusionWindowList struct {
Items []ExclusionWindow `json:"items"`
}

func (ew *ExclusionWindow) AttachToCluster(id string) {
ew.Status.ClusterID = id
ew.Status.ResourceState = models.CreatingEvent
}

func (ew *ExclusionWindow) DetachFromCluster() {
ew.Status.ResourceState = models.DeletingEvent
}

func init() {
SchemeBuilder.Register(&ExclusionWindow{}, &ExclusionWindowList{})
}

func (r *ExclusionWindow) NewPatch() client.Patch {
old := r.DeepCopy()
func (ew *ExclusionWindow) NewPatch() client.Patch {
old := ew.DeepCopy()
return client.MergeFrom(old)
}
17 changes: 9 additions & 8 deletions apis/clusterresources/v1beta1/gcpvpcpeering_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,20 @@ func (gcp *GCPVPCPeering) NewPatch() client.Patch {
return client.MergeFrom(old)
}

func (gcp *GCPVPCPeering) AttachToCluster(id string) {
gcp.Status.CDCID = id
gcp.Status.ResourceState = models.CreatingEvent
}

func (gcp *GCPVPCPeering) DetachFromCluster() {
gcp.Status.ResourceState = models.DeletingEvent
}

func init() {
SchemeBuilder.Register(&GCPVPCPeering{}, &GCPVPCPeeringList{})
}

func (gcp *GCPVPCPeeringSpec) Validate() error {
dataCentreIDMatched, err := regexp.Match(models.UUIDStringRegExp, []byte(gcp.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 gcp.PeerSubnets {
peerSubnetMatched, err := regexp.Match(models.PeerSubnetsRegExp, []byte(subnet))
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions apis/clusterresources/v1beta1/gcpvpcpeering_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ func (r *GCPVPCPeering) ValidateCreate() error {
return fmt.Errorf("peer Project 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
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
14 changes: 6 additions & 8 deletions apis/clusterresources/v1beta1/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import (
)

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

type PeeringStatus struct {
ID string `json:"id,omitempty"`
StatusCode string `json:"statusCode,omitempty"`
Name string `json:"name,omitempty"`
FailureReason string `json:"failureReason,omitempty"`
CDCID string `json:"cdcid,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

camel case in json

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

ResourceState string `json:"resourceState,omitempty"`
}

type PatchRequest struct {
Expand All @@ -39,18 +40,15 @@ type PatchRequest struct {
}

type FirewallRuleSpec struct {
ClusterID string `json:"clusterId"`
Type string `json:"type"`
Type string `json:"type"`
}
Comment on lines 42 to 44
Copy link
Contributor

Choose a reason for hiding this comment

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

How about we abandon this generic struct with only one field? There is also another one called VPCPeeringSpec


type FirewallRuleStatus struct {
ID string `json:"id,omitempty"`
DeferredReason string `json:"deferredReason,omitempty"`
Status string `json:"status,omitempty"`
}

type immutablePeeringFields struct {
DataCentreID string
ClusterID string `json:"clusterId,omitempty"`
ResourceState string `json:"resourceState,omitempty"`
}

type SecretReference struct {
Expand Down
1 change: 1 addition & 0 deletions apis/clusters/v1beta1/cadence_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type CadenceSpec struct {
PackagedProvisioning []*PackagedProvisioning `json:"packagedProvisioning,omitempty"`
TargetPrimaryCadence []*TargetCadence `json:"targetPrimaryCadence,omitempty"`
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
ClusterResources ClusterResourceRefs `json:"clusterResources,omitempty"`
}

type AWSArchival struct {
Expand Down
2 changes: 1 addition & 1 deletion apis/clusters/v1beta1/cassandra_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type CassandraSpec struct {
Spark []*Spark `json:"spark,omitempty"`
BundledUseOnly bool `json:"bundledUseOnly,omitempty"`
UserRefs References `json:"userRefs,omitempty"`
ClusterResources ClusterResourceRefs `json:"clusterResources,omitempty"`
//+kubebuilder:validate:MaxItems:=1
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
}
Expand Down Expand Up @@ -152,7 +153,6 @@ func (c *Cassandra) NewBackupSpec(startTimestamp int) *clusterresourcesv1beta1.C
Finalizers: []string{models.DeletionFinalizer},
},
Spec: clusterresourcesv1beta1.ClusterBackupSpec{
ClusterID: c.Status.ID,
ClusterKind: models.CassandraClusterKind,
},
}
Expand Down
1 change: 1 addition & 0 deletions apis/clusters/v1beta1/kafka_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type KafkaSpec struct {
KarapaceSchemaRegistry []*KarapaceSchemaRegistry `json:"karapaceSchemaRegistry,omitempty"`
BundledUseOnly bool `json:"bundledUseOnly,omitempty"`
UserRefs References `json:"userRefs,omitempty"`
ClusterResources ClusterResourceRefs `json:"clusterResources,omitempty"`
Kraft []*Kraft `json:"kraft,omitempty"`
}

Expand Down
1 change: 1 addition & 0 deletions apis/clusters/v1beta1/kafkaconnect_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type KafkaConnectSpec struct {

// CustomConnectors defines the location for custom connector storage and access info.
CustomConnectors []*CustomConnectors `json:"customConnectors,omitempty"`
ClusterResources ClusterResourceRefs `json:"clusterResources,omitempty"`
}

// KafkaConnectStatus defines the observed state of KafkaConnect
Expand Down
2 changes: 1 addition & 1 deletion apis/clusters/v1beta1/opensearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type OpenSearchSpec struct {
AlertingPlugin bool `json:"alertingPlugin,omitempty"`
BundledUseOnly bool `json:"bundledUseOnly,omitempty"`
UserRefs References `json:"userRefs,omitempty"`
ClusterResources ClusterResourceRefs `json:"clusterResources,omitempty"`
//+kubuilder:validation:MaxItems:=1
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
//+kubuilder:validation:MaxItems:=1
Expand Down Expand Up @@ -584,7 +585,6 @@ func (os *OpenSearch) NewBackupSpec(startTimestamp int) *clusterresourcesv1beta1
Finalizers: []string{models.DeletionFinalizer},
},
Spec: clusterresourcesv1beta1.ClusterBackupSpec{
ClusterID: os.Status.ID,
ClusterKind: models.OsClusterKind,
},
}
Expand Down
10 changes: 5 additions & 5 deletions apis/clusters/v1beta1/postgresql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ type PgRestoreFrom struct {
type PgSpec struct {
PgRestoreFrom *PgRestoreFrom `json:"pgRestoreFrom,omitempty"`
Cluster `json:",inline"`
DataCentres []*PgDataCentre `json:"dataCentres,omitempty"`
ClusterConfigurations map[string]string `json:"clusterConfigurations,omitempty"`
SynchronousModeStrict bool `json:"synchronousModeStrict,omitempty"`
UserRefs []*Reference `json:"userRefs,omitempty"`
DataCentres []*PgDataCentre `json:"dataCentres,omitempty"`
ClusterConfigurations map[string]string `json:"clusterConfigurations,omitempty"`
SynchronousModeStrict bool `json:"synchronousModeStrict,omitempty"`
UserRefs []*Reference `json:"userRefs,omitempty"`
ClusterResources ClusterResourceRefs `json:"clusterResources,omitempty"`
//+kubebuilder:validate:MaxItems:=1
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
}
Expand Down Expand Up @@ -159,7 +160,6 @@ func (pg *PostgreSQL) NewBackupSpec(startTimestamp int) *clusterresourcesv1beta1
Finalizers: []string{models.DeletionFinalizer},
},
Spec: clusterresourcesv1beta1.ClusterBackupSpec{
ClusterID: pg.Status.ID,
ClusterKind: models.PgClusterKind,
},
}
Expand Down
Loading