Skip to content

Commit

Permalink
on-premises provisioning for phase 1 was implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
testisnullus committed Feb 1, 2024
1 parent cebcb52 commit e40b687
Show file tree
Hide file tree
Showing 37 changed files with 87 additions and 1,235 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test-webhooks:
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./apis/clusters/v1beta1 -coverprofile cover.out

.PHONY: test
test: manifests generate fmt vet docker-build-server-stub run-server-stub envtest test-clusters test-clusterresources test-kafkamanagement test-users stop-server-stub
test: manifests generate fmt vet docker-build-server-stub run-server-stub envtest test-clusters test-clusterresources test-webhooks test-kafkamanagement test-users stop-server-stub

.PHONY: goimports
goimports:
Expand Down
3 changes: 1 addition & 2 deletions apis/clusters/v1beta1/cadence_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ type BundledOpenSearchSpec struct {

// CadenceSpec defines the desired state of Cadence
type CadenceSpec struct {
Cluster `json:",inline"`
OnPremisesSpec *OnPremisesSpec `json:"onPremisesSpec,omitempty"`
Cluster `json:",inline"`
//+kubebuilder:validation:MinItems:=1
//+kubebuilder:validation:MaxItems:=1
DataCentres []*CadenceDataCentre `json:"dataCentres"`
Expand Down
39 changes: 3 additions & 36 deletions apis/clusters/v1beta1/cadence_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,6 @@ func (cv *cadenceValidator) ValidateCreate(ctx context.Context, obj runtime.Obje
return err
}

contains, err := ContainsKubeVirtAddon(ctx, cv.Client)
if err != nil {
return err
}

if c.Spec.OnPremisesSpec != nil && c.Spec.OnPremisesSpec.EnableAutomation {
if !contains {
return models.ErrKubeVirtAddonNotFound
}
err = c.Spec.OnPremisesSpec.ValidateCreation()
if err != nil {
return err
}
if c.Spec.PrivateNetworkCluster {
err = c.Spec.OnPremisesSpec.ValidateSSHGatewayCreation()
if err != nil {
return err
}
}
}

appVersions, err := cv.API.ListAppVersions(models.CadenceAppKind)
if err != nil {
return fmt.Errorf("cannot list versions for kind: %v, err: %w",
Expand Down Expand Up @@ -198,22 +177,10 @@ func (cv *cadenceValidator) ValidateCreate(ctx context.Context, obj runtime.Obje
return fmt.Errorf("data centres field is empty")
}

//TODO: add support of multiple DCs for OnPrem clusters
if len(c.Spec.DataCentres) > 1 && c.Spec.OnPremisesSpec != nil {
return fmt.Errorf("on-premises cluster can be provisioned with only one data centre")
}

for _, dc := range c.Spec.DataCentres {
if c.Spec.OnPremisesSpec != nil {
err = dc.DataCentre.ValidateOnPremisesCreation()
if err != nil {
return err
}
} else {
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}

if !c.Spec.PrivateNetworkCluster && dc.PrivateLink != nil {
Expand Down
1 change: 0 additions & 1 deletion apis/clusters/v1beta1/cassandra_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type CassandraRestoreFrom struct {
// CassandraSpec defines the desired state of Cassandra
type CassandraSpec struct {
RestoreFrom *CassandraRestoreFrom `json:"restoreFrom,omitempty"`
OnPremisesSpec *OnPremisesSpec `json:"onPremisesSpec,omitempty"`
Cluster `json:",inline"`
DataCentres []*CassandraDataCentre `json:"dataCentres,omitempty"`
LuceneEnabled bool `json:"luceneEnabled,omitempty"`
Expand Down
47 changes: 8 additions & 39 deletions apis/clusters/v1beta1/cassandra_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ func (r *Cassandra) SetupWebhookWithManager(mgr ctrl.Manager, api validation.Val
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/mutate-clusters-instaclustr-com-v1beta1-cassandra,mutating=true,failurePolicy=fail,sideEffects=None,groups=clusters.instaclustr.com,resources=cassandras,verbs=create;update,versions=v1beta1,name=mcassandra.kb.io,admissionReviewVersions=v1
//+kubebuilder:webhook:path=/validate-clusters-instaclustr-com-v1beta1-cassandra,mutating=false,failurePolicy=fail,sideEffects=None,groups=clusters.instaclustr.com,resources=cassandras,verbs=create;update,versions=v1beta1,name=vcassandra.kb.io,admissionReviewVersions=v1
//+kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch
//+kubebuilder:rbac:groups="apps",resources=deployments,verbs=get;list;watch

var _ webhook.CustomValidator = &cassandraValidator{}
var _ webhook.Defaulter = &Cassandra{}
Expand Down Expand Up @@ -96,28 +94,6 @@ func (cv *cassandraValidator) ValidateCreate(ctx context.Context, obj runtime.Ob
return err
}

contains, err := ContainsKubeVirtAddon(ctx, cv.Client)
if err != nil {
return err
}

if c.Spec.OnPremisesSpec != nil && c.Spec.OnPremisesSpec.EnableAutomation {
if !contains {
return models.ErrKubeVirtAddonNotFound
}

err = c.Spec.OnPremisesSpec.ValidateCreation()
if err != nil {
return err
}
if c.Spec.PrivateNetworkCluster {
err = c.Spec.OnPremisesSpec.ValidateSSHGatewayCreation()
if err != nil {
return err
}
}
}

appVersions, err := cv.API.ListAppVersions(models.CassandraAppKind)
if err != nil {
return fmt.Errorf("cannot list versions for kind: %v, err: %w",
Expand All @@ -133,22 +109,15 @@ func (cv *cassandraValidator) ValidateCreate(ctx context.Context, obj runtime.Ob
return fmt.Errorf("data centres field is empty")
}

//TODO: add support of multiple DCs for OnPrem clusters
if len(c.Spec.DataCentres) > 1 && c.Spec.OnPremisesSpec != nil {
return fmt.Errorf("on-premises cluster can be provisioned with only one data centre")
}

for _, dc := range c.Spec.DataCentres {
if c.Spec.OnPremisesSpec != nil {
err = dc.DataCentre.ValidateOnPremisesCreation()
if err != nil {
return err
}
} else {
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}
//TODO: add support of multiple DCs for OnPrem clusters
if len(c.Spec.DataCentres) > 1 && dc.CloudProvider == models.ONPREMISES {
return models.ErrOnPremicesWithMultiDC
}

err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}

if !c.Spec.PrivateNetworkCluster && dc.PrivateIPBroadcastForDiscovery {
Expand Down
1 change: 0 additions & 1 deletion apis/clusters/v1beta1/kafka_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ type KarapaceSchemaRegistry struct {
// KafkaSpec defines the desired state of Kafka
type KafkaSpec struct {
Cluster `json:",inline"`
OnPremisesSpec *OnPremisesSpec `json:"onPremisesSpec,omitempty"`
SchemaRegistry []*SchemaRegistry `json:"schemaRegistry,omitempty"`

// ReplicationFactor to use for new topic.
Expand Down
43 changes: 7 additions & 36 deletions apis/clusters/v1beta1/kafka_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,6 @@ func (kv *kafkaValidator) ValidateCreate(ctx context.Context, obj runtime.Object
return err
}

contains, err := ContainsKubeVirtAddon(ctx, kv.Client)
if err != nil {
return err
}

if k.Spec.OnPremisesSpec != nil && k.Spec.OnPremisesSpec.EnableAutomation {
if !contains {
return models.ErrKubeVirtAddonNotFound
}
err = k.Spec.OnPremisesSpec.ValidateCreation()
if err != nil {
return err
}
if k.Spec.PrivateNetworkCluster {
err = k.Spec.OnPremisesSpec.ValidateSSHGatewayCreation()
if err != nil {
return err
}
}
}

appVersions, err := kv.API.ListAppVersions(models.KafkaAppKind)
if err != nil {
return fmt.Errorf("cannot list versions for kind: %v, err: %w",
Expand All @@ -123,22 +102,14 @@ func (kv *kafkaValidator) ValidateCreate(ctx context.Context, obj runtime.Object
return models.ErrZeroDataCentres
}

//TODO: add support of multiple DCs for OnPrem clusters
if len(k.Spec.DataCentres) > 1 && k.Spec.OnPremisesSpec != nil {
return fmt.Errorf("on-premises cluster can be provisioned with only one data centre")
}

for _, dc := range k.Spec.DataCentres {
if k.Spec.OnPremisesSpec != nil {
err = dc.DataCentre.ValidateOnPremisesCreation()
if err != nil {
return err
}
} else {
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}
//TODO: add support of multiple DCs for OnPrem clusters
if len(k.Spec.DataCentres) > 1 && dc.CloudProvider == models.ONPREMISES {
return models.ErrOnPremicesWithMultiDC
}
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}

if len(dc.PrivateLink) > 1 {
Expand Down
7 changes: 3 additions & 4 deletions apis/clusters/v1beta1/kafkaconnect_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ type KafkaConnectDataCentre struct {

// KafkaConnectSpec defines the desired state of KafkaConnect
type KafkaConnectSpec struct {
Cluster `json:",inline"`
OnPremisesSpec *OnPremisesSpec `json:"onPremisesSpec,omitempty"`
DataCentres []*KafkaConnectDataCentre `json:"dataCentres"`
TargetCluster []*TargetCluster `json:"targetCluster"`
Cluster `json:",inline"`
DataCentres []*KafkaConnectDataCentre `json:"dataCentres"`
TargetCluster []*TargetCluster `json:"targetCluster"`

// CustomConnectors defines the location for custom connector storage and access info.
CustomConnectors []*CustomConnectors `json:"customConnectors,omitempty"`
Expand Down
44 changes: 8 additions & 36 deletions apis/clusters/v1beta1/kafkaconnect_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,6 @@ func (kcv *kafkaConnectValidator) ValidateCreate(ctx context.Context, obj runtim
return err
}

contains, err := ContainsKubeVirtAddon(ctx, kcv.Client)
if err != nil {
return err
}

if kc.Spec.OnPremisesSpec != nil && kc.Spec.OnPremisesSpec.EnableAutomation {
if !contains {
return models.ErrKubeVirtAddonNotFound
}
err = kc.Spec.OnPremisesSpec.ValidateCreation()
if err != nil {
return err
}
if kc.Spec.PrivateNetworkCluster {
err = kc.Spec.OnPremisesSpec.ValidateSSHGatewayCreation()
if err != nil {
return err
}
}
}

appVersions, err := kcv.API.ListAppVersions(models.KafkaConnectAppKind)
if err != nil {
return fmt.Errorf("cannot list versions for kind: %v, err: %w",
Expand Down Expand Up @@ -161,22 +140,15 @@ func (kcv *kafkaConnectValidator) ValidateCreate(ctx context.Context, obj runtim
return fmt.Errorf("data centres field is empty")
}

//TODO: add support of multiple DCs for OnPrem clusters
if len(kc.Spec.DataCentres) > 1 && kc.Spec.OnPremisesSpec != nil {
return fmt.Errorf("on-premises cluster can be provisioned with only one data centre")
}

for _, dc := range kc.Spec.DataCentres {
if kc.Spec.OnPremisesSpec != nil {
err = dc.DataCentre.ValidateOnPremisesCreation()
if err != nil {
return err
}
} else {
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}
//TODO: add support of multiple DCs for OnPrem clusters
if len(kc.Spec.DataCentres) > 1 && dc.CloudProvider == models.ONPREMISES {
return models.ErrOnPremicesWithMultiDC
}

err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}

err = validateReplicationFactor(models.KafkaConnectReplicationFactors, dc.ReplicationFactor)
Expand Down
6 changes: 3 additions & 3 deletions apis/clusters/v1beta1/opensearch_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ func validateCreation(dc *OpenSearchDataCentre) error {
}

switch dc.CloudProvider {
case "AWS_VPC":
case models.AWSVPC:
if !validation.Contains(dc.Region, models.AWSRegions) {
return fmt.Errorf("AWS Region: %s is unavailable, available regions: %v",
dc.Region, models.AWSRegions)
}
case "AZURE_AZ":
case models.AZUREAZ:
if !validation.Contains(dc.Region, models.AzureRegions) {
return fmt.Errorf("azure Region: %s is unavailable, available regions: %v",
dc.Region, models.AzureRegions)
}
case "GCP":
case models.GCP:
if !validation.Contains(dc.Region, models.GCPRegions) {
return fmt.Errorf("GCP Region: %s is unavailable, available regions: %v",
dc.Region, models.GCPRegions)
Expand Down
1 change: 0 additions & 1 deletion apis/clusters/v1beta1/postgresql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ type PgRestoreFrom struct {
type PgSpec struct {
PgRestoreFrom *PgRestoreFrom `json:"pgRestoreFrom,omitempty"`
Cluster `json:",inline"`
OnPremisesSpec *OnPremisesSpec `json:"onPremisesSpec,omitempty"`
DataCentres []*PgDataCentre `json:"dataCentres,omitempty"`
ClusterConfigurations map[string]string `json:"clusterConfigurations,omitempty"`
SynchronousModeStrict bool `json:"synchronousModeStrict,omitempty"`
Expand Down
44 changes: 8 additions & 36 deletions apis/clusters/v1beta1/postgresql_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,6 @@ func (pgv *pgValidator) ValidateCreate(ctx context.Context, obj runtime.Object)
return err
}

contains, err := ContainsKubeVirtAddon(ctx, pgv.K8sClient)
if err != nil {
return err
}

if pg.Spec.OnPremisesSpec != nil && pg.Spec.OnPremisesSpec.EnableAutomation {
if !contains {
return models.ErrKubeVirtAddonNotFound
}
err = pg.Spec.OnPremisesSpec.ValidateCreation()
if err != nil {
return err
}
if pg.Spec.PrivateNetworkCluster {
err = pg.Spec.OnPremisesSpec.ValidateSSHGatewayCreation()
if err != nil {
return err
}
}
}

if pg.Spec.UserRefs != nil {
err = pgv.validatePostgreSQLUsers(ctx, pg)
if err != nil {
Expand All @@ -139,22 +118,15 @@ func (pgv *pgValidator) ValidateCreate(ctx context.Context, obj runtime.Object)
return models.ErrZeroDataCentres
}

//TODO: add support of multiple DCs for OnPrem clusters
if len(pg.Spec.DataCentres) > 1 && pg.Spec.OnPremisesSpec != nil {
return fmt.Errorf("on-premises cluster can be provisioned with only one data centre")
}

for _, dc := range pg.Spec.DataCentres {
if pg.Spec.OnPremisesSpec != nil {
err = dc.DataCentre.ValidateOnPremisesCreation()
if err != nil {
return err
}
} else {
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}
//TODO: add support of multiple DCs for OnPrem clusters
if len(pg.Spec.DataCentres) > 1 && dc.CloudProvider == models.ONPREMISES {
return models.ErrOnPremicesWithMultiDC
}

err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}

err = dc.ValidatePGBouncer()
Expand Down
5 changes: 2 additions & 3 deletions apis/clusters/v1beta1/redis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ type RedisRestoreFrom struct {

// RedisSpec defines the desired state of Redis
type RedisSpec struct {
RestoreFrom *RedisRestoreFrom `json:"restoreFrom,omitempty"`
Cluster `json:",inline"`
OnPremisesSpec *OnPremisesSpec `json:"onPremisesSpec,omitempty"`
RestoreFrom *RedisRestoreFrom `json:"restoreFrom,omitempty"`
Cluster `json:",inline"`

// Enables client to node encryption
ClientEncryption bool `json:"clientEncryption,omitempty"`
Expand Down
Loading

0 comments on commit e40b687

Please sign in to comment.