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

on-premises provisioning for phase 1 was implemented #690

Closed
wants to merge 1 commit into from
Closed
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: 6 additions & 6 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,14 @@
"filename": "controllers/clusters/cadence_controller.go",
"hashed_secret": "bcf196cdeea4d7ed8b04dcbbd40111eb5e9abeac",
"is_verified": false,
"line_number": 773
"line_number": 659
},
{
"type": "Secret Keyword",
"filename": "controllers/clusters/cadence_controller.go",
"hashed_secret": "192d703e91a60432ce06bfe26adfd12f5c7b931f",
"is_verified": false,
"line_number": 815
"line_number": 701
}
],
"controllers/clusters/datatest/kafka_v1beta1.yaml": [
Expand Down Expand Up @@ -604,21 +604,21 @@
"filename": "controllers/clusters/postgresql_controller.go",
"hashed_secret": "a57ce131bd944bdf8ba2f2f93e179dc416ed0315",
"is_verified": false,
"line_number": 576
"line_number": 502
},
{
"type": "Secret Keyword",
"filename": "controllers/clusters/postgresql_controller.go",
"hashed_secret": "b5d01701d58992dc3e388a02b55f1780c5e395a4",
"is_verified": false,
"line_number": 597
"line_number": 523
},
{
"type": "Secret Keyword",
"filename": "controllers/clusters/postgresql_controller.go",
"hashed_secret": "5ffe533b830f08a0326348a9160afafc8ada44db",
"is_verified": false,
"line_number": 1674
"line_number": 1584
}
],
"controllers/clusters/zookeeper_controller_test.go": [
Expand Down Expand Up @@ -1174,5 +1174,5 @@
}
]
},
"generated_at": "2024-02-02T08:53:13Z"
"generated_at": "2024-02-05T10:14:49Z"
}
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
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
Loading
Loading