Skip to content

Commit

Permalink
implement-privateLink-and-shotoverProxy-for-cassandra
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksiienkoMykyta committed Jan 24, 2024
1 parent 9e0c547 commit 489943c
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 51 deletions.
50 changes: 48 additions & 2 deletions apis/clusters/v1beta1/cassandra_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ type CassandraDataCentre struct {

// Adds the specified version of Debezium Connector Cassandra to the Cassandra cluster
// +kubebuilder:validation:MaxItems=1
Debezium []DebeziumCassandraSpec `json:"debezium,omitempty"`
Debezium []DebeziumCassandraSpec `json:"debezium,omitempty"`
PrivateLink bool `json:"privateLink,omitempty"`
ShotoverProxy []ShotoverProxySpec `json:"shotoverProxy,omitempty"`
}

type ShotoverProxySpec struct {
NodeSize string `json:"nodeSize"`
}

type DebeziumCassandraSpec struct {
Expand All @@ -104,6 +110,16 @@ func (d *CassandraDataCentre) DebeziumToInstAPI() []*models.Debezium {
return instDebezium
}

func (d *CassandraDataCentre) ShotoverProxyToInstaAPI() []*models.ShotoverProxy {
var instaShotoverProxy []*models.ShotoverProxy
for _, k8sShotoverProxy := range d.ShotoverProxy {
instaShotoverProxy = append(instaShotoverProxy, &models.ShotoverProxy{
NodeSize: k8sShotoverProxy.NodeSize,
})
}
return instaShotoverProxy
}

func (d *CassandraDataCentre) DebeziumEquals(new *CassandraDataCentre) bool {
if len(d.Debezium) != len(new.Debezium) {
return false
Expand All @@ -122,6 +138,21 @@ func (d *CassandraDataCentre) DebeziumEquals(new *CassandraDataCentre) bool {
return true
}

func (d *CassandraDataCentre) ShotoverProxyEquals(new *CassandraDataCentre) bool {
if len(d.ShotoverProxy) != len(new.ShotoverProxy) {
return false
}

for _, oldSP := range d.ShotoverProxy {
for _, newSP := range new.ShotoverProxy {
if newSP.NodeSize != oldSP.NodeSize {
return false
}
}
}
return true
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
Expand Down Expand Up @@ -242,6 +273,15 @@ func (cs *CassandraSpec) DebeziumFromInstAPI(iDebeziums []*models.Debezium) (dcs
return debeziums
}

func (cs *CassandraSpec) ShotoverProxyFromInstAPI(iShotoverProxys []*models.ShotoverProxy) (sps []ShotoverProxySpec) {
for _, iShotoverProxy := range iShotoverProxys {
sps = append(sps, ShotoverProxySpec{
NodeSize: iShotoverProxy.NodeSize,
})
}
return sps
}

func (cs *CassandraSpec) DCsFromInstAPI(iDCs []*models.CassandraDataCentre) (dcs []*CassandraDataCentre) {
for _, iDC := range iDCs {
dcs = append(dcs, &CassandraDataCentre{
Expand All @@ -250,7 +290,9 @@ func (cs *CassandraSpec) DCsFromInstAPI(iDCs []*models.CassandraDataCentre) (dcs
PrivateIPBroadcastForDiscovery: iDC.PrivateIPBroadcastForDiscovery,
ClientToClusterEncryption: iDC.ClientToClusterEncryption,
ReplicationFactor: iDC.ReplicationFactor,
PrivateLink: iDC.PrivateLink,
Debezium: cs.DebeziumFromInstAPI(iDC.Debezium),
ShotoverProxy: cs.ShotoverProxyFromInstAPI(iDC.ShotoverProxy),
})
}
return
Expand Down Expand Up @@ -323,9 +365,11 @@ func (cs *CassandraSpec) AreDCsEqual(dcs []*CassandraDataCentre) bool {
if !dataCentre.IsEqual(iDC.DataCentre) ||
iDC.ClientToClusterEncryption != dataCentre.ClientToClusterEncryption ||
iDC.PrivateIPBroadcastForDiscovery != dataCentre.PrivateIPBroadcastForDiscovery ||
iDC.PrivateLink != dataCentre.PrivateLink ||
iDC.ContinuousBackup != dataCentre.ContinuousBackup ||
iDC.ReplicationFactor != dataCentre.ReplicationFactor ||
!dataCentre.DebeziumEquals(iDC) {
!dataCentre.DebeziumEquals(iDC) ||
!dataCentre.ShotoverProxyEquals(iDC) {
return false
}
}
Expand Down Expand Up @@ -356,10 +400,12 @@ func (cdc *CassandraDataCentre) ToInstAPI() *models.CassandraDataCentre {
return &models.CassandraDataCentre{
DataCentre: cdc.DataCentre.ToInstAPI(),
ClientToClusterEncryption: cdc.ClientToClusterEncryption,
PrivateLink: cdc.PrivateLink,
ContinuousBackup: cdc.ContinuousBackup,
PrivateIPBroadcastForDiscovery: cdc.PrivateIPBroadcastForDiscovery,
ReplicationFactor: cdc.ReplicationFactor,
Debezium: cdc.DebeziumToInstAPI(),
ShotoverProxy: cdc.ShotoverProxyToInstaAPI(),
}
}

Expand Down
6 changes: 6 additions & 0 deletions apis/clusters/v1beta1/cassandra_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ type immutableCassandraDCFields struct {
type specificCassandraDC struct {
replicationFactor int
continuousBackup bool
privateLink bool
privateIpBroadcastForDiscovery bool
clientToClusterEncryption bool
}
Expand Down Expand Up @@ -340,6 +341,10 @@ func (cs *CassandraSpec) validateDataCentresUpdate(oldSpec CassandraSpec) error
return models.ErrDebeziumImmutable
}

if !oldDC.ShotoverProxyEquals(newDC) {
return models.ErrShotoverProxyImmutable
}

}

return nil
Expand All @@ -357,6 +362,7 @@ func (cdc *CassandraDataCentre) newImmutableFields() *immutableCassandraDCFields
specificCassandraDC{
replicationFactor: cdc.ReplicationFactor,
continuousBackup: cdc.ContinuousBackup,
privateLink: cdc.PrivateLink,
privateIpBroadcastForDiscovery: cdc.PrivateIPBroadcastForDiscovery,
clientToClusterEncryption: cdc.ClientToClusterEncryption,
},
Expand Down
20 changes: 20 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.

11 changes: 11 additions & 0 deletions config/crd/bases/clusters.instaclustr.com_cassandras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,21 @@ spec:
type: integer
privateIpBroadcastForDiscovery:
type: boolean
privateLink:
type: boolean
region:
type: string
replicationFactor:
type: integer
shotoverProxy:
items:
properties:
nodeSize:
type: string
required:
- nodeSize
type: object
type: array
tags:
additionalProperties:
type: string
Expand Down
91 changes: 47 additions & 44 deletions config/samples/clusters_v1beta1_cassandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,65 @@ kind: Cassandra
metadata:
name: cassandra-cluster
spec:
name: "username-Cassandra"
version: "4.0.10"
privateNetworkCluster: false
name: "example-cassandra" #(immutable)
version: "4.0.10" #(immutable)
privateNetworkCluster: true #(immutable)
dataCentres:
- name: "AWS_cassandra"
region: "US_EAST_1"
debezium:
# - kafkaVpcType: "VPC_PEERED"
# kafkaTopicPrefix: "test"
# kafkaCdcId: "5134aed3-7b98-4ebd-95d0-2e181bdb073b"
# clusterRef:
# name: kafka
# namespace: default
# clusterKind: Kafka
# version: "2.0.1"
cloudProvider: "AWS_VPC"
continuousBackup: false
nodesNumber: 2
- name: "AWS_cassandra" #(mutable)
region: "US_EAST_1" #(immutable)
# debezium:
# - kafkaVpcType: "VPC_PEERED" #(immutable)
# kafkaTopicPrefix: "test" #(immutable)
# kafkaCdcId: "556b283e-d094-4bcf-a068-14fa68c2a43a" #(mutable)
## clusterRef:1
## name: kafka
## namespace: default
## clusterKind: Kafka
# version: "2.0.1" #(immutable)
cloudProvider: "AWS_VPC" #(immutable)
continuousBackup: false #(immutable)
nodesNumber: 4 #(mutable)
replicationFactor: 2
privateIpBroadcastForDiscovery: false
network: "172.16.0.0/19"
privateIpBroadcastForDiscovery: false #(immutable)
network: "172.16.0.0/19" #(immutable)
tags:
"tag": "testTag"
clientToClusterEncryption: false
# cloudProviderSettings:
# - customVirtualNetworkId: "vpc-0b69c781969e980a9"
nodeSize: "CAS-DEV-t4g.small-5"
# accountName: "InstaclustrRIYOA"
# - name: "AWS_cassandra2"
# region: "US_EAST_1"
# cloudProvider: "AWS_VPC"
# continuousBackup: false
# nodesNumber: 2
# replicationFactor: 2
# privateIpBroadcastForDiscovery: false
# network: "172.17.0.0/19"
# tags:
# "tag": "testTag"
# clientToClusterEncryption: false
# nodeSize: "CAS-DEV-t4g.small-30"
pciCompliance: false
luceneEnabled: false # can be enabled only on 3.11.13 version of Cassandra
passwordAndUserAuth: true
"tag": "testTag" #(immutable)
clientToClusterEncryption: true #(immutable)
# cloudProviderSettings:
# - customVirtualNetworkId: "vpc-0b69c781969e980a9"
# nodeSize: "CAS-DEV-t4g.small-5" #(mutable)
# nodeSize: "CAS-PRD-r6g.medium-80" #(mutable) # (production node size)
nodeSize: "CAS-PRD-r6g.medium-120" #(mutable) # (production node size)
privateLink: true
shotoverProxy:
- nodeSize: "CSO-PRD-c6g.xlarge-20"
# accountName: "InstaclustrRIYOA"
# - name: "AWS_cassandra2"
# region: "US_EAST_1"
# cloudProvider: "AWS_VPC"
# continuousBackup: false
# nodesNumber: 2
# replicationFactor: 2
# privateIpBroadcastForDiscovery: false
# network: "172.17.0.0/19"
# tags:
# "tag": "testTag"
# clientToClusterEncryption: false
# nodeSize: "CAS-DEV-t4g.small-30"
pciCompliance: false #(immutable)
luceneEnabled: false #(immutable) # can be enabled only on 3.11.13 version of Cassandra (currently it could be enabled on 4.0.10 version as well)
passwordAndUserAuth: true #(immutable)
# userRefs:
# - namespace: default
# name: cassandrauser-sample
# - namespace: default
# name: cassandrauser-sample2
# - namespace: default
# name: cassandrauser-sample3
slaTier: "NON_PRODUCTION"
slaTier: "NON_PRODUCTION" #(immutable)
# resizeSettings:
# - notifySupportContacts: false
# concurrency: 2
# description: "this is a sample of description"
# twoFactorDelete:
# - email: "[email protected]"
#spark:
# - version: "2.3.2" # 3.0.1 for 4.0.4 version of Cassandra | 2.3.2 for 3.11.13 version of Cassandra
# - email: "[email protected]"
16 changes: 11 additions & 5 deletions pkg/models/cassandra_apiv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ type CassandraCluster struct {

type CassandraDataCentre struct {
DataCentre `json:",inline"`
ReplicationFactor int `json:"replicationFactor"`
ContinuousBackup bool `json:"continuousBackup"`
PrivateIPBroadcastForDiscovery bool `json:"privateIpBroadcastForDiscovery"`
ClientToClusterEncryption bool `json:"clientToClusterEncryption"`
Debezium []*Debezium `json:"debezium,omitempty"`
ReplicationFactor int `json:"replicationFactor"`
ContinuousBackup bool `json:"continuousBackup"`
PrivateLink bool `json:"privateLink,omitempty"`
PrivateIPBroadcastForDiscovery bool `json:"privateIpBroadcastForDiscovery"`
ClientToClusterEncryption bool `json:"clientToClusterEncryption"`
Debezium []*Debezium `json:"debezium,omitempty"`
ShotoverProxy []*ShotoverProxy `json:"shotoverProxy,omitempty"`
}

type Debezium struct {
Expand All @@ -48,6 +50,10 @@ type Debezium struct {
Version string `json:"version"`
}

type ShotoverProxy struct {
NodeSize string `json:"nodeSize"`
}

type CassandraClusterAPIUpdate struct {
DataCentres []*CassandraDataCentre `json:"dataCentres"`
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions pkg/models/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var (
ErrOnlySingleConcurrentResizeAvailable = errors.New("only single concurrent resize is allowed")
ErrBundledUseOnlyResourceUpdateIsNotSupported = errors.New("updating of bundled use resource is not supported")
ErrDebeziumImmutable = errors.New("debezium array is immutable")
ErrShotoverProxyImmutable = errors.New("shotoverProxy array is immutable")
ErrEmptyNamespace = errors.New("namespace field is empty")
ErrEmptyName = errors.New("name field is empty")
ErrCreateClusterWithMultiDC = errors.New("multiple data center is still not supported. Please create a cluster with one data centre and add a second one when the cluster is in the running state")
Expand Down

0 comments on commit 489943c

Please sign in to comment.