diff --git a/Makefile b/Makefile index 4af6522bf..c78b40d88 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/apis/clusters/v1beta1/cadence_types.go b/apis/clusters/v1beta1/cadence_types.go index 50d80930a..579336a79 100644 --- a/apis/clusters/v1beta1/cadence_types.go +++ b/apis/clusters/v1beta1/cadence_types.go @@ -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"` diff --git a/apis/clusters/v1beta1/cadence_webhook.go b/apis/clusters/v1beta1/cadence_webhook.go index f51a1078b..28c682f74 100644 --- a/apis/clusters/v1beta1/cadence_webhook.go +++ b/apis/clusters/v1beta1/cadence_webhook.go @@ -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", @@ -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 { diff --git a/apis/clusters/v1beta1/cassandra_types.go b/apis/clusters/v1beta1/cassandra_types.go index 8129e7a1b..b9e2280d9 100644 --- a/apis/clusters/v1beta1/cassandra_types.go +++ b/apis/clusters/v1beta1/cassandra_types.go @@ -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"` diff --git a/apis/clusters/v1beta1/cassandra_webhook.go b/apis/clusters/v1beta1/cassandra_webhook.go index 2673ad9e7..0928ef1dd 100644 --- a/apis/clusters/v1beta1/cassandra_webhook.go +++ b/apis/clusters/v1beta1/cassandra_webhook.go @@ -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{} @@ -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", @@ -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 { diff --git a/apis/clusters/v1beta1/kafka_types.go b/apis/clusters/v1beta1/kafka_types.go index 6c1a5bdd3..96c166f61 100644 --- a/apis/clusters/v1beta1/kafka_types.go +++ b/apis/clusters/v1beta1/kafka_types.go @@ -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. diff --git a/apis/clusters/v1beta1/kafka_webhook.go b/apis/clusters/v1beta1/kafka_webhook.go index 8eb717efa..29e328379 100644 --- a/apis/clusters/v1beta1/kafka_webhook.go +++ b/apis/clusters/v1beta1/kafka_webhook.go @@ -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", @@ -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 { diff --git a/apis/clusters/v1beta1/kafkaconnect_types.go b/apis/clusters/v1beta1/kafkaconnect_types.go index 55e456dba..d4363e15e 100644 --- a/apis/clusters/v1beta1/kafkaconnect_types.go +++ b/apis/clusters/v1beta1/kafkaconnect_types.go @@ -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"` diff --git a/apis/clusters/v1beta1/kafkaconnect_webhook.go b/apis/clusters/v1beta1/kafkaconnect_webhook.go index 0f550f945..cc188edb0 100644 --- a/apis/clusters/v1beta1/kafkaconnect_webhook.go +++ b/apis/clusters/v1beta1/kafkaconnect_webhook.go @@ -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", @@ -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) diff --git a/apis/clusters/v1beta1/opensearch_webhook.go b/apis/clusters/v1beta1/opensearch_webhook.go index 507d33190..8233f1241 100644 --- a/apis/clusters/v1beta1/opensearch_webhook.go +++ b/apis/clusters/v1beta1/opensearch_webhook.go @@ -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) diff --git a/apis/clusters/v1beta1/postgresql_types.go b/apis/clusters/v1beta1/postgresql_types.go index eeb3c9591..ce9a023ce 100644 --- a/apis/clusters/v1beta1/postgresql_types.go +++ b/apis/clusters/v1beta1/postgresql_types.go @@ -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"` diff --git a/apis/clusters/v1beta1/postgresql_webhook.go b/apis/clusters/v1beta1/postgresql_webhook.go index 82a3de23d..b1a0e8164 100644 --- a/apis/clusters/v1beta1/postgresql_webhook.go +++ b/apis/clusters/v1beta1/postgresql_webhook.go @@ -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 { @@ -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() diff --git a/apis/clusters/v1beta1/redis_types.go b/apis/clusters/v1beta1/redis_types.go index 9d3d3c4d1..2aef42116 100644 --- a/apis/clusters/v1beta1/redis_types.go +++ b/apis/clusters/v1beta1/redis_types.go @@ -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"` diff --git a/apis/clusters/v1beta1/redis_webhook.go b/apis/clusters/v1beta1/redis_webhook.go index d2984038d..5e1f2712b 100644 --- a/apis/clusters/v1beta1/redis_webhook.go +++ b/apis/clusters/v1beta1/redis_webhook.go @@ -105,27 +105,6 @@ func (rv *redisValidator) ValidateCreate(ctx context.Context, obj runtime.Object return err } - contains, err := ContainsKubeVirtAddon(ctx, rv.Client) - if err != nil { - return err - } - - if r.Spec.OnPremisesSpec != nil && r.Spec.OnPremisesSpec.EnableAutomation { - if !contains { - return models.ErrKubeVirtAddonNotFound - } - err = r.Spec.OnPremisesSpec.ValidateCreation() - if err != nil { - return err - } - if r.Spec.PrivateNetworkCluster { - err = r.Spec.OnPremisesSpec.ValidateSSHGatewayCreation() - if err != nil { - return err - } - } - } - err = r.Spec.ValidatePrivateLink() if err != nil { return err @@ -146,24 +125,15 @@ func (rv *redisValidator) ValidateCreate(ctx context.Context, obj runtime.Object return fmt.Errorf("data centres field is empty") } - if len(r.Spec.DataCentres) > 1 { - if r.Spec.OnPremisesSpec != nil { + for _, dc := range r.Spec.DataCentres { + //TODO: add support of multiple DCs for OnPrem clusters + if len(r.Spec.DataCentres) > 1 && dc.CloudProvider == models.ONPREMISES { return models.ErrOnPremicesWithMultiDC } - return models.ErrCreateClusterWithMultiDC - } - for _, dc := range r.Spec.DataCentres { - if r.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 !r.Spec.PrivateNetworkCluster && dc.PrivateLink != nil { diff --git a/apis/clusters/v1beta1/validation.go b/apis/clusters/v1beta1/validation.go index 7042121a7..6def4679f 100644 --- a/apis/clusters/v1beta1/validation.go +++ b/apis/clusters/v1beta1/validation.go @@ -60,21 +60,26 @@ func (dc *DataCentre) ValidateCreation() 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) } + case models.ONPREMISES: + if dc.Region != models.CLIENTDC { + return fmt.Errorf("ONPREMISES Region: %s is unavailable, available regions: %v", + dc.Region, models.CLIENTDC) + } } if dc.ProviderAccountName == models.DefaultAccountName && len(dc.CloudProviderSettings) != 0 { diff --git a/apis/clusters/v1beta1/webhook_suite_test.go b/apis/clusters/v1beta1/webhook_suite_test.go index b83da4bcf..a1cbf87e2 100644 --- a/apis/clusters/v1beta1/webhook_suite_test.go +++ b/apis/clusters/v1beta1/webhook_suite_test.go @@ -29,6 +29,8 @@ import ( . "github.com/onsi/gomega" admissionv1beta1 "k8s.io/api/admission/v1beta1" + k8sappsv1 "k8s.io/api/apps/v1" + k8scorev1 "k8s.io/api/core/v1" //+kubebuilder:scaffold:imports "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/rest" @@ -81,6 +83,10 @@ var _ = BeforeSuite(func() { err = admissionv1beta1.AddToScheme(scheme) Expect(err).NotTo(HaveOccurred()) + err = k8sappsv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + err = k8scorev1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) //+kubebuilder:scaffold:scheme diff --git a/apis/clusters/v1beta1/zz_generated.deepcopy.go b/apis/clusters/v1beta1/zz_generated.deepcopy.go index 61f8974e9..b23e3a3eb 100644 --- a/apis/clusters/v1beta1/zz_generated.deepcopy.go +++ b/apis/clusters/v1beta1/zz_generated.deepcopy.go @@ -233,11 +233,6 @@ func (in *CadenceList) DeepCopyObject() runtime.Object { func (in *CadenceSpec) DeepCopyInto(out *CadenceSpec) { *out = *in in.Cluster.DeepCopyInto(&out.Cluster) - if in.OnPremisesSpec != nil { - in, out := &in.OnPremisesSpec, &out.OnPremisesSpec - *out = new(OnPremisesSpec) - (*in).DeepCopyInto(*out) - } if in.DataCentres != nil { in, out := &in.DataCentres, &out.DataCentres *out = make([]*CadenceDataCentre, len(*in)) @@ -475,11 +470,6 @@ func (in *CassandraSpec) DeepCopyInto(out *CassandraSpec) { *out = new(CassandraRestoreFrom) (*in).DeepCopyInto(*out) } - if in.OnPremisesSpec != nil { - in, out := &in.OnPremisesSpec, &out.OnPremisesSpec - *out = new(OnPremisesSpec) - (*in).DeepCopyInto(*out) - } in.Cluster.DeepCopyInto(&out.Cluster) if in.DataCentres != nil { in, out := &in.DataCentres, &out.DataCentres @@ -1081,11 +1071,6 @@ func (in *KafkaConnectList) DeepCopyObject() runtime.Object { func (in *KafkaConnectSpec) DeepCopyInto(out *KafkaConnectSpec) { *out = *in in.Cluster.DeepCopyInto(&out.Cluster) - if in.OnPremisesSpec != nil { - in, out := &in.OnPremisesSpec, &out.OnPremisesSpec - *out = new(OnPremisesSpec) - (*in).DeepCopyInto(*out) - } if in.DataCentres != nil { in, out := &in.DataCentres, &out.DataCentres *out = make([]*KafkaConnectDataCentre, len(*in)) @@ -1210,11 +1195,6 @@ func (in *KafkaList) DeepCopyObject() runtime.Object { func (in *KafkaSpec) DeepCopyInto(out *KafkaSpec) { *out = *in in.Cluster.DeepCopyInto(&out.Cluster) - if in.OnPremisesSpec != nil { - in, out := &in.OnPremisesSpec, &out.OnPremisesSpec - *out = new(OnPremisesSpec) - (*in).DeepCopyInto(*out) - } if in.SchemaRegistry != nil { in, out := &in.SchemaRegistry, &out.SchemaRegistry *out = make([]*SchemaRegistry, len(*in)) @@ -1990,11 +1970,6 @@ func (in *PgSpec) DeepCopyInto(out *PgSpec) { (*in).DeepCopyInto(*out) } in.Cluster.DeepCopyInto(&out.Cluster) - if in.OnPremisesSpec != nil { - in, out := &in.OnPremisesSpec, &out.OnPremisesSpec - *out = new(OnPremisesSpec) - (*in).DeepCopyInto(*out) - } if in.DataCentres != nil { in, out := &in.DataCentres, &out.DataCentres *out = make([]*PgDataCentre, len(*in)) @@ -2308,11 +2283,6 @@ func (in *RedisSpec) DeepCopyInto(out *RedisSpec) { (*in).DeepCopyInto(*out) } in.Cluster.DeepCopyInto(&out.Cluster) - if in.OnPremisesSpec != nil { - in, out := &in.OnPremisesSpec, &out.OnPremisesSpec - *out = new(OnPremisesSpec) - (*in).DeepCopyInto(*out) - } if in.DataCentres != nil { in, out := &in.DataCentres, &out.DataCentres *out = make([]*RedisDataCentre, len(*in)) diff --git a/config/crd/bases/clusters.instaclustr.com_cadences.yaml b/config/crd/bases/clusters.instaclustr.com_cadences.yaml index 09fde9983..7a5745092 100644 --- a/config/crd/bases/clusters.instaclustr.com_cadences.yaml +++ b/config/crd/bases/clusters.instaclustr.com_cadences.yaml @@ -125,49 +125,6 @@ spec: name: description: Name [ 3 .. 32 ] characters. type: string - onPremisesSpec: - properties: - cloudInitScriptRef: - description: ObjectReference is namespaced reference to an object - properties: - name: - type: string - namespace: - type: string - required: - - name - - namespace - type: object - dataDiskSize: - type: string - enableAutomation: - type: boolean - nodeCPU: - format: int64 - type: integer - nodeMemory: - type: string - osDiskSize: - type: string - osImageURL: - type: string - sshGatewayCPU: - format: int64 - type: integer - sshGatewayMemory: - type: string - storageClassName: - type: string - required: - - cloudInitScriptRef - - dataDiskSize - - enableAutomation - - nodeCPU - - nodeMemory - - osDiskSize - - osImageURL - - storageClassName - type: object packagedProvisioning: items: properties: diff --git a/config/crd/bases/clusters.instaclustr.com_cassandras.yaml b/config/crd/bases/clusters.instaclustr.com_cassandras.yaml index e45b94920..44ced0526 100644 --- a/config/crd/bases/clusters.instaclustr.com_cassandras.yaml +++ b/config/crd/bases/clusters.instaclustr.com_cassandras.yaml @@ -152,49 +152,6 @@ spec: name: description: Name [ 3 .. 32 ] characters. type: string - onPremisesSpec: - properties: - cloudInitScriptRef: - description: ObjectReference is namespaced reference to an object - properties: - name: - type: string - namespace: - type: string - required: - - name - - namespace - type: object - dataDiskSize: - type: string - enableAutomation: - type: boolean - nodeCPU: - format: int64 - type: integer - nodeMemory: - type: string - osDiskSize: - type: string - osImageURL: - type: string - sshGatewayCPU: - format: int64 - type: integer - sshGatewayMemory: - type: string - storageClassName: - type: string - required: - - cloudInitScriptRef - - dataDiskSize - - enableAutomation - - nodeCPU - - nodeMemory - - osDiskSize - - osImageURL - - storageClassName - type: object passwordAndUserAuth: type: boolean pciCompliance: diff --git a/config/crd/bases/clusters.instaclustr.com_kafkaconnects.yaml b/config/crd/bases/clusters.instaclustr.com_kafkaconnects.yaml index f1fc4648b..18da5b0be 100644 --- a/config/crd/bases/clusters.instaclustr.com_kafkaconnects.yaml +++ b/config/crd/bases/clusters.instaclustr.com_kafkaconnects.yaml @@ -179,49 +179,6 @@ spec: name: description: Name [ 3 .. 32 ] characters. type: string - onPremisesSpec: - properties: - cloudInitScriptRef: - description: ObjectReference is namespaced reference to an object - properties: - name: - type: string - namespace: - type: string - required: - - name - - namespace - type: object - dataDiskSize: - type: string - enableAutomation: - type: boolean - nodeCPU: - format: int64 - type: integer - nodeMemory: - type: string - osDiskSize: - type: string - osImageURL: - type: string - sshGatewayCPU: - format: int64 - type: integer - sshGatewayMemory: - type: string - storageClassName: - type: string - required: - - cloudInitScriptRef - - dataDiskSize - - enableAutomation - - nodeCPU - - nodeMemory - - osDiskSize - - osImageURL - - storageClassName - type: object pciCompliance: description: The PCI compliance standards relate to the security of user data and transactional information. Can only be applied clusters diff --git a/config/crd/bases/clusters.instaclustr.com_kafkas.yaml b/config/crd/bases/clusters.instaclustr.com_kafkas.yaml index f600391f6..18e0d9c9d 100644 --- a/config/crd/bases/clusters.instaclustr.com_kafkas.yaml +++ b/config/crd/bases/clusters.instaclustr.com_kafkas.yaml @@ -165,49 +165,6 @@ spec: name: description: Name [ 3 .. 32 ] characters. type: string - onPremisesSpec: - properties: - cloudInitScriptRef: - description: ObjectReference is namespaced reference to an object - properties: - name: - type: string - namespace: - type: string - required: - - name - - namespace - type: object - dataDiskSize: - type: string - enableAutomation: - type: boolean - nodeCPU: - format: int64 - type: integer - nodeMemory: - type: string - osDiskSize: - type: string - osImageURL: - type: string - sshGatewayCPU: - format: int64 - type: integer - sshGatewayMemory: - type: string - storageClassName: - type: string - required: - - cloudInitScriptRef - - dataDiskSize - - enableAutomation - - nodeCPU - - nodeMemory - - osDiskSize - - osImageURL - - storageClassName - type: object partitionsNumber: description: PartitionsNumber number of partitions to use when created new topics. diff --git a/config/crd/bases/clusters.instaclustr.com_postgresqls.yaml b/config/crd/bases/clusters.instaclustr.com_postgresqls.yaml index 1dec7a3db..b8c70e340 100644 --- a/config/crd/bases/clusters.instaclustr.com_postgresqls.yaml +++ b/config/crd/bases/clusters.instaclustr.com_postgresqls.yaml @@ -149,49 +149,6 @@ spec: name: description: Name [ 3 .. 32 ] characters. type: string - onPremisesSpec: - properties: - cloudInitScriptRef: - description: ObjectReference is namespaced reference to an object - properties: - name: - type: string - namespace: - type: string - required: - - name - - namespace - type: object - dataDiskSize: - type: string - enableAutomation: - type: boolean - nodeCPU: - format: int64 - type: integer - nodeMemory: - type: string - osDiskSize: - type: string - osImageURL: - type: string - sshGatewayCPU: - format: int64 - type: integer - sshGatewayMemory: - type: string - storageClassName: - type: string - required: - - cloudInitScriptRef - - dataDiskSize - - enableAutomation - - nodeCPU - - nodeMemory - - osDiskSize - - osImageURL - - storageClassName - type: object pciCompliance: description: The PCI compliance standards relate to the security of user data and transactional information. Can only be applied clusters diff --git a/config/crd/bases/clusters.instaclustr.com_redis.yaml b/config/crd/bases/clusters.instaclustr.com_redis.yaml index 3c1732831..d2efdb4c5 100644 --- a/config/crd/bases/clusters.instaclustr.com_redis.yaml +++ b/config/crd/bases/clusters.instaclustr.com_redis.yaml @@ -119,49 +119,6 @@ spec: name: description: Name [ 3 .. 32 ] characters. type: string - onPremisesSpec: - properties: - cloudInitScriptRef: - description: ObjectReference is namespaced reference to an object - properties: - name: - type: string - namespace: - type: string - required: - - name - - namespace - type: object - dataDiskSize: - type: string - enableAutomation: - type: boolean - nodeCPU: - format: int64 - type: integer - nodeMemory: - type: string - osDiskSize: - type: string - osImageURL: - type: string - sshGatewayCPU: - format: int64 - type: integer - sshGatewayMemory: - type: string - storageClassName: - type: string - required: - - cloudInitScriptRef - - dataDiskSize - - enableAutomation - - nodeCPU - - nodeMemory - - osDiskSize - - osImageURL - - storageClassName - type: object passwordAndUserAuth: type: boolean pciCompliance: diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 66f1e5990..1a0ec694e 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -24,14 +24,6 @@ rules: verbs: - create - patch -- apiGroups: - - "" - resources: - - namespaces - verbs: - - get - - list - - watch - apiGroups: - "" resources: @@ -91,14 +83,6 @@ rules: - patch - update - watch -- apiGroups: - - apps - resources: - - deployments - verbs: - - get - - list - - watch - apiGroups: - cdi.kubevirt.io resources: diff --git a/config/samples/onpremises/clusters_v1beta1_cadence.yaml b/config/samples/onpremises/clusters_v1beta1_cadence.yaml deleted file mode 100644 index 5d9df66d8..000000000 --- a/config/samples/onpremises/clusters_v1beta1_cadence.yaml +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: clusters.instaclustr.com/v1beta1 -kind: Cadence -metadata: - name: cadence-sample -spec: - name: "cadence-test" - version: "1.0.0" - onPremisesSpec: - enableAutomation: true - storageClassName: managed-csi-premium - osDiskSize: 20Gi - dataDiskSize: 200Gi - sshGatewayCPU: 2 - sshGatewayMemory: 4096Mi - nodeCPU: 2 - nodeMemory: 8192Mi - osImageURL: "https://s3.amazonaws.com/debian-bucket/debian-11-generic-amd64-20230601-1398.raw" - cloudInitScriptRef: - namespace: default - name: instaclustr-cloud-init-secret - standardProvisioning: - - targetCassandra: - dependencyCdcId: "9d43ac54-7317-4ce5-859a-e9d0443508a4" - dependencyVpcType: "TARGET_VPC" - privateNetworkCluster: false - dataCentres: - - region: "CLIENT_DC" - network: "10.1.0.0/16" - cloudProvider: "ONPREMISES" - name: "testdc" - nodeSize: "CAD-DEV-OP.4.8-200" - nodesNumber: 2 - clientEncryption: false - slaTier: "NON_PRODUCTION" - useCadenceWebAuth: false \ No newline at end of file diff --git a/config/samples/onpremises/clusters_v1beta1_cassandra.yaml b/config/samples/onpremises/clusters_v1beta1_cassandra.yaml index b7d4e5a99..ccaacc71b 100644 --- a/config/samples/onpremises/clusters_v1beta1_cassandra.yaml +++ b/config/samples/onpremises/clusters_v1beta1_cassandra.yaml @@ -1,24 +1,11 @@ apiVersion: clusters.instaclustr.com/v1beta1 kind: Cassandra metadata: - name: cassandra-on-prem-cluster + name: cassandra-on-prem-sample spec: - name: "danylo-on-prem-cassandra" - version: "4.0.10" - privateNetworkCluster: false - onPremisesSpec: - enableAutomation: true - storageClassName: managed-csi-premium - osDiskSize: 20Gi - dataDiskSize: 200Gi - sshGatewayCPU: 2 - sshGatewayMemory: 4096Mi - nodeCPU: 2 - nodeMemory: 8192Mi - osImageURL: "https://s3.amazonaws.com/debian-bucket/debian-11-generic-amd64-20230601-1398.raw" - cloudInitScriptRef: - namespace: default - name: instaclustr-cloud-init-secret + name: "cassandra-on-prem-sample" + version: "4.1.3" + privateNetworkCluster: true dataCentres: - name: "onPremCassandra" region: "CLIENT_DC" @@ -26,13 +13,10 @@ spec: continuousBackup: false nodesNumber: 2 replicationFactor: 2 - privateIpBroadcastForDiscovery: false + privateIpBroadcastForDiscovery: true network: "192.168.0.0/16" tags: "onprem": "test" - clientToClusterEncryption: false nodeSize: "CAS-PRD-OP.4.8-200" - pciCompliance: false - luceneEnabled: false # can be enabled only on 3.11.13 version of Cassandra - passwordAndUserAuth: false + passwordAndUserAuth: true slaTier: "NON_PRODUCTION" diff --git a/config/samples/onpremises/clusters_v1beta1_kafka.yaml b/config/samples/onpremises/clusters_v1beta1_kafka.yaml index 9fe0e1754..e79077869 100644 --- a/config/samples/onpremises/clusters_v1beta1_kafka.yaml +++ b/config/samples/onpremises/clusters_v1beta1_kafka.yaml @@ -1,9 +1,9 @@ apiVersion: clusters.instaclustr.com/v1beta1 kind: Kafka metadata: - name: danylo-kafka + name: kafka-on-prem-sample spec: - name: "danylo-kafka" + name: "kafka-on-prem-sample" version: "3.3.1" pciCompliance: false replicationFactor: 3 @@ -13,19 +13,6 @@ spec: clientToClusterEncryption: false privateNetworkCluster: false slaTier: "NON_PRODUCTION" - onPremisesSpec: - enableAutomation: true - storageClassName: managed-csi-premium - osDiskSize: 20Gi - dataDiskSize: 200Gi - sshGatewayCPU: 2 - sshGatewayMemory: 4096Mi - nodeCPU: 2 - nodeMemory: 8192Mi - osImageURL: "https://s3.amazonaws.com/debian-bucket/debian-11-generic-amd64-20230601-1398.raw" - cloudInitScriptRef: - namespace: default - name: instaclustr-cloud-init-secret dataCentres: - name: "onPremKafka" nodesNumber: 3 diff --git a/config/samples/onpremises/clusters_v1beta1_kafkaconnect.yaml b/config/samples/onpremises/clusters_v1beta1_kafkaconnect.yaml index 75a47a502..da51bee5a 100644 --- a/config/samples/onpremises/clusters_v1beta1_kafkaconnect.yaml +++ b/config/samples/onpremises/clusters_v1beta1_kafkaconnect.yaml @@ -1,29 +1,16 @@ apiVersion: clusters.instaclustr.com/v1beta1 kind: KafkaConnect metadata: - name: kafkaconnect-sample + name: kafkaconnect-on-prem-sample spec: - name: "kafkaconnect-onprem" + name: "kafkaconnect-on-prem-sample" version: "3.5.1" - onPremisesSpec: - enableAutomation: true - storageClassName: managed-csi-premium - osDiskSize: 20Gi - dataDiskSize: 200Gi - sshGatewayCPU: 2 - sshGatewayMemory: 4096Mi - nodeCPU: 2 - nodeMemory: 8192Mi - osImageURL: "https://s3.amazonaws.com/debian-bucket/debian-11-generic-amd64-20230601-1398.raw" - cloudInitScriptRef: - namespace: default - name: instaclustr-cloud-init-secret privateNetworkCluster: false slaTier: "NON_PRODUCTION" targetCluster: - managedCluster: - - targetKafkaClusterId: "34dfc53c-c8c1-4be8-bd2f-cfdb77ec7349" - kafkaConnectVpcType: "KAFKA_VPC" + - targetKafkaClusterId: "377ebef6-f07c-4c59-b1da-feab2540568b" + kafkaConnectVpcType: "SEPARATE_VPC" dataCentres: - name: "kafkaconnect-onprem" nodesNumber: 3 diff --git a/config/samples/onpremises/clusters_v1beta1_postgresql.yaml b/config/samples/onpremises/clusters_v1beta1_postgresql.yaml index 35a3c78fe..0cf104421 100644 --- a/config/samples/onpremises/clusters_v1beta1_postgresql.yaml +++ b/config/samples/onpremises/clusters_v1beta1_postgresql.yaml @@ -1,28 +1,15 @@ apiVersion: clusters.instaclustr.com/v1beta1 kind: PostgreSQL metadata: - name: postgresql-sample + name: postgresql-on-prem-sample spec: - name: "postgresql-sample" + name: "postgresql-on-prem-sample" version: "15.4.0" - onPremisesSpec: - enableAutomation: true - storageClassName: managed-csi-premium - osDiskSize: 20Gi - dataDiskSize: 200Gi - sshGatewayCPU: 2 - sshGatewayMemory: 4096Mi - nodeCPU: 2 - nodeMemory: 8192Mi - osImageURL: "https://s3.amazonaws.com/debian-bucket/debian-11-generic-amd64-20230601-1398.raw" - cloudInitScriptRef: - namespace: default - name: instaclustr-cloud-init-secret dataCentres: - region: "CLIENT_DC" network: "10.1.0.0/16" cloudProvider: "ONPREMISES" - nodeSize: "PGS-DEV-OP.4.8-200" + nodeSize: "PSQL-DEV-OP.4.8-200" nodesNumber: 2 clientEncryption: false name: "testDC1" diff --git a/config/samples/onpremises/clusters_v1beta1_redis.yaml b/config/samples/onpremises/clusters_v1beta1_redis.yaml index 7a092423a..15c91a4d9 100644 --- a/config/samples/onpremises/clusters_v1beta1_redis.yaml +++ b/config/samples/onpremises/clusters_v1beta1_redis.yaml @@ -1,23 +1,10 @@ apiVersion: clusters.instaclustr.com/v1beta1 kind: Redis metadata: - name: danylo-redis + name: redis-on-prem-redis spec: - name: "danylo-redis" + name: "redis-on-prem-redis" version: "7.0.14" - onPremisesSpec: - enableAutomation: true - storageClassName: managed-csi-premium - osDiskSize: 20Gi - dataDiskSize: 200Gi - sshGatewayCPU: 2 - sshGatewayMemory: 4096Mi - nodeCPU: 2 - nodeMemory: 8192Mi - osImageURL: "https://s3.amazonaws.com/debian-bucket/debian-11-generic-amd64-20230601-1398.raw" - cloudInitScriptRef: - namespace: default - name: instaclustr-cloud-init-secret slaTier: "NON_PRODUCTION" clientEncryption: false passwordAndUserAuth: true diff --git a/controllers/clusters/cadence_controller.go b/controllers/clusters/cadence_controller.go index b07160a38..f13c83635 100644 --- a/controllers/clusters/cadence_controller.go +++ b/controllers/clusters/cadence_controller.go @@ -36,7 +36,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/ratelimiter" - "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/instaclustr/operator/apis/clusters/v1beta1" "github.com/instaclustr/operator/pkg/exposeservice" @@ -249,83 +248,6 @@ func (r *CadenceReconciler) handleCreateCluster( r.EventRecorder.Event(c, models.Normal, models.Created, "Cluster status check job is started") } - if c.Spec.OnPremisesSpec != nil && c.Spec.OnPremisesSpec.EnableAutomation { - iData, err := r.API.GetCadence(c.Status.ID) - if err != nil { - l.Error(err, "Cannot get cluster from the Instaclustr API", - "cluster name", c.Spec.Name, - "data centres", c.Spec.DataCentres, - "cluster ID", c.Status.ID, - ) - r.EventRecorder.Eventf( - c, models.Warning, models.FetchFailed, - "Cluster fetch from the Instaclustr API is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - iCadence, err := c.FromInstAPI(iData) - if err != nil { - l.Error( - err, "Cannot convert cluster from the Instaclustr API", - "cluster name", c.Spec.Name, - "cluster ID", c.Status.ID, - ) - r.EventRecorder.Eventf( - c, models.Warning, models.ConversionFailed, - "Cluster convertion from the Instaclustr API to k8s resource is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - bootstrap := newOnPremisesBootstrap( - r.Client, - c, - r.EventRecorder, - iCadence.Status.ClusterStatus, - c.Spec.OnPremisesSpec, - newExposePorts(c.GetExposePorts()), - c.GetHeadlessPorts(), - c.Spec.PrivateNetworkCluster, - ) - - err = handleCreateOnPremisesClusterResources(ctx, bootstrap) - if err != nil { - l.Error( - err, "Cannot create resources for on-premises cluster", - "cluster spec", c.Spec.OnPremisesSpec, - ) - r.EventRecorder.Eventf( - c, models.Warning, models.CreationFailed, - "Resources creation for on-premises cluster is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - err = r.startClusterOnPremisesIPsJob(c, bootstrap) - if err != nil { - l.Error(err, "Cannot start on-premises cluster IPs check job", - "cluster ID", c.Status.ID, - ) - - r.EventRecorder.Eventf( - c, models.Warning, models.CreationFailed, - "On-premises cluster IPs check job is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - l.Info( - "On-premises resources have been created", - "cluster name", c.Spec.Name, - "on-premises Spec", c.Spec.OnPremisesSpec, - "cluster ID", c.Status.ID, - ) - return models.ExitReconcile, nil - } return ctrl.Result{}, nil } @@ -490,42 +412,6 @@ func (r *CadenceReconciler) handleDeleteCluster( "Two-Factor Delete is enabled, please confirm cluster deletion via email or phone.") return ctrl.Result{}, nil } - if c.Spec.OnPremisesSpec != nil && c.Spec.OnPremisesSpec.EnableAutomation { - err = deleteOnPremResources(ctx, r.Client, c.Status.ID, c.Namespace) - if err != nil { - l.Error(err, "Cannot delete cluster on-premises resources", - "cluster ID", c.Status.ID) - r.EventRecorder.Eventf(c, models.Warning, models.DeletionFailed, - "Cluster on-premises resources deletion is failed. Reason: %v", err) - return reconcile.Result{}, err - } - - l.Info("Cluster on-premises resources are deleted", - "cluster ID", c.Status.ID) - r.EventRecorder.Eventf(c, models.Normal, models.Deleted, - "Cluster on-premises resources are deleted") - - patch := c.NewPatch() - controllerutil.RemoveFinalizer(c, models.DeletionFinalizer) - - err = r.Patch(ctx, c, patch) - if err != nil { - l.Error(err, "Cannot patch cluster resource", - "cluster name", c.Spec.Name, - "cluster ID", c.Status.ID, - "kind", c.Kind, - "api Version", c.APIVersion, - "namespace", c.Namespace, - "cluster metadata", c.ObjectMeta, - ) - r.EventRecorder.Eventf(c, models.Warning, models.PatchFailed, - "Cluster resource patch is failed. Reason: %v", err) - return reconcile.Result{}, err - } - - return reconcile.Result{}, err - } - r.Scheduler.RemoveJob(c.GetJobID(scheduler.OnPremisesIPsChecker)) } l.Info("Cadence cluster is being deleted", diff --git a/controllers/clusters/cassandra_controller.go b/controllers/clusters/cassandra_controller.go index 71a65db23..2f3d9e951 100644 --- a/controllers/clusters/cassandra_controller.go +++ b/controllers/clusters/cassandra_controller.go @@ -264,81 +264,7 @@ func (r *CassandraReconciler) handleCreateCluster( ) } - if c.Spec.OnPremisesSpec != nil && c.Spec.OnPremisesSpec.EnableAutomation { - iData, err := r.API.GetCassandra(c.Status.ID) - if err != nil { - l.Error(err, "Cannot get cluster from the Instaclustr API", - "cluster name", c.Spec.Name, - "data centres", c.Spec.DataCentres, - "cluster ID", c.Status.ID, - ) - r.EventRecorder.Eventf( - c, models.Warning, models.FetchFailed, - "Cluster fetch from the Instaclustr API is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - iCassandra, err := c.FromInstAPI(iData) - if err != nil { - l.Error( - err, "Cannot convert cluster from the Instaclustr API", - "cluster name", c.Spec.Name, - "cluster ID", c.Status.ID, - ) - r.EventRecorder.Eventf( - c, models.Warning, models.ConversionFailed, - "Cluster convertion from the Instaclustr API to k8s resource is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - bootstrap := newOnPremisesBootstrap( - r.Client, - c, - r.EventRecorder, - iCassandra.Status.ClusterStatus, - c.Spec.OnPremisesSpec, - newExposePorts(c.GetExposePorts()), - c.GetHeadlessPorts(), - c.Spec.PrivateNetworkCluster, - ) - - err = handleCreateOnPremisesClusterResources(ctx, bootstrap) - if err != nil { - l.Error( - err, "Cannot create resources for on-premises cluster", - "cluster spec", c.Spec.OnPremisesSpec, - ) - r.EventRecorder.Eventf( - c, models.Warning, models.CreationFailed, - "Resources creation for on-premises cluster is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - err = r.startClusterOnPremisesIPsJob(c, bootstrap) - if err != nil { - l.Error(err, "Cannot start on-premises cluster IPs check job", - "cluster ID", c.Status.ID, - ) - - r.EventRecorder.Eventf( - c, models.Warning, models.CreationFailed, - "On-premises cluster IPs check job is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - l.Info( - "On-premises resources have been created", - "cluster name", c.Spec.Name, - "on-premises Spec", c.Spec.OnPremisesSpec, - "cluster ID", c.Status.ID, - ) + if c.Spec.DataCentres[0].CloudProvider == models.ONPREMISES { return models.ExitReconcile, nil } @@ -569,23 +495,6 @@ func (r *CassandraReconciler) handleDeleteCluster( r.Scheduler.RemoveJob(c.GetJobID(scheduler.BackupsChecker)) r.Scheduler.RemoveJob(c.GetJobID(scheduler.StatusChecker)) - if c.Spec.OnPremisesSpec != nil && c.Spec.OnPremisesSpec.EnableAutomation { - err = deleteOnPremResources(ctx, r.Client, c.Status.ID, c.Namespace) - if err != nil { - l.Error(err, "Cannot delete cluster on-premises resources", - "cluster ID", c.Status.ID) - r.EventRecorder.Eventf(c, models.Warning, models.DeletionFailed, - "Cluster on-premises resources deletion is failed. Reason: %v", err) - return reconcile.Result{}, err - } - - l.Info("Cluster on-premises resources are deleted", - "cluster ID", c.Status.ID) - r.EventRecorder.Eventf(c, models.Normal, models.Deleted, - "Cluster on-premises resources are deleted") - r.Scheduler.RemoveJob(c.GetJobID(scheduler.OnPremisesIPsChecker)) - } - l.Info("Deleting cluster backup resources", "cluster ID", c.Status.ID) err = r.deleteBackups(ctx, c.Status.ID, c.Namespace) diff --git a/controllers/clusters/kafka_controller.go b/controllers/clusters/kafka_controller.go index e5d49d1fb..27e9b5eff 100644 --- a/controllers/clusters/kafka_controller.go +++ b/controllers/clusters/kafka_controller.go @@ -199,81 +199,7 @@ func (r *KafkaReconciler) handleCreateCluster(ctx context.Context, k *v1beta1.Ka ) } - if k.Spec.OnPremisesSpec != nil && k.Spec.OnPremisesSpec.EnableAutomation { - iData, err := r.API.GetKafka(k.Status.ID) - if err != nil { - l.Error(err, "Cannot get cluster from the Instaclustr API", - "cluster name", k.Spec.Name, - "data centres", k.Spec.DataCentres, - "cluster ID", k.Status.ID, - ) - r.EventRecorder.Eventf( - k, models.Warning, models.FetchFailed, - "Cluster fetch from the Instaclustr API is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - iKafka, err := k.FromInstAPI(iData) - if err != nil { - l.Error( - err, "Cannot convert cluster from the Instaclustr API", - "cluster name", k.Spec.Name, - "cluster ID", k.Status.ID, - ) - r.EventRecorder.Eventf( - k, models.Warning, models.ConversionFailed, - "Cluster convertion from the Instaclustr API to k8s resource is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - bootstrap := newOnPremisesBootstrap( - r.Client, - k, - r.EventRecorder, - iKafka.Status.ClusterStatus, - k.Spec.OnPremisesSpec, - newExposePorts(k.GetExposePorts()), - k.GetHeadlessPorts(), - k.Spec.PrivateNetworkCluster, - ) - - err = handleCreateOnPremisesClusterResources(ctx, bootstrap) - if err != nil { - l.Error( - err, "Cannot create resources for on-premises cluster", - "cluster spec", k.Spec.OnPremisesSpec, - ) - r.EventRecorder.Eventf( - k, models.Warning, models.CreationFailed, - "Resources creation for on-premises cluster is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - err = r.startClusterOnPremisesIPsJob(k, bootstrap) - if err != nil { - l.Error(err, "Cannot start on-premises cluster IPs check job", - "cluster ID", k.Status.ID, - ) - - r.EventRecorder.Eventf( - k, models.Warning, models.CreationFailed, - "On-premises cluster IPs check job is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - l.Info( - "On-premises resources have been created", - "cluster name", k.Spec.Name, - "on-premises Spec", k.Spec.OnPremisesSpec, - "cluster ID", k.Status.ID, - ) + if k.Spec.DataCentres[0].CloudProvider == models.ONPREMISES { return models.ExitReconcile, nil } } @@ -448,23 +374,6 @@ func (r *KafkaReconciler) handleDeleteCluster(ctx context.Context, k *v1beta1.Ka return reconcile.Result{}, err } - if k.Spec.OnPremisesSpec != nil && k.Spec.OnPremisesSpec.EnableAutomation { - err = deleteOnPremResources(ctx, r.Client, k.Status.ID, k.Namespace) - if err != nil { - l.Error(err, "Cannot delete cluster on-premises resources", - "cluster ID", k.Status.ID) - r.EventRecorder.Eventf(k, models.Warning, models.DeletionFailed, - "Cluster on-premises resources deletion is failed. Reason: %v", err) - return reconcile.Result{}, err - } - - l.Info("Cluster on-premises resources are deleted", - "cluster ID", k.Status.ID) - r.EventRecorder.Eventf(k, models.Normal, models.Deleted, - "Cluster on-premises resources are deleted") - r.Scheduler.RemoveJob(k.GetJobID(scheduler.OnPremisesIPsChecker)) - } - r.Scheduler.RemoveJob(k.GetJobID(scheduler.StatusChecker)) r.Scheduler.RemoveJob(k.GetJobID(scheduler.UserCreator)) controllerutil.RemoveFinalizer(k, models.DeletionFinalizer) diff --git a/controllers/clusters/kafkaconnect_controller.go b/controllers/clusters/kafkaconnect_controller.go index 80e29ec27..81d0074bb 100644 --- a/controllers/clusters/kafkaconnect_controller.go +++ b/controllers/clusters/kafkaconnect_controller.go @@ -217,81 +217,8 @@ func (r *KafkaConnectReconciler) handleCreateCluster(ctx context.Context, kc *v1 "Cluster status check job is started", ) } - if kc.Spec.OnPremisesSpec != nil && kc.Spec.OnPremisesSpec.EnableAutomation { - iData, err := r.API.GetKafkaConnect(kc.Status.ID) - if err != nil { - l.Error(err, "Cannot get cluster from the Instaclustr API", - "cluster name", kc.Spec.Name, - "data centres", kc.Spec.DataCentres, - "cluster ID", kc.Status.ID, - ) - r.EventRecorder.Eventf( - kc, models.Warning, models.FetchFailed, - "Cluster fetch from the Instaclustr API is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - iKafkaConnect, err := kc.FromInst(iData) - if err != nil { - l.Error( - err, "Cannot convert cluster from the Instaclustr API", - "cluster name", kc.Spec.Name, - "cluster ID", kc.Status.ID, - ) - r.EventRecorder.Eventf( - kc, models.Warning, models.ConversionFailed, - "Cluster convertion from the Instaclustr API to k8s resource is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - bootstrap := newOnPremisesBootstrap( - r.Client, - kc, - r.EventRecorder, - iKafkaConnect.Status.ClusterStatus, - kc.Spec.OnPremisesSpec, - newExposePorts(kc.GetExposePorts()), - kc.GetHeadlessPorts(), - kc.Spec.PrivateNetworkCluster, - ) - - err = handleCreateOnPremisesClusterResources(ctx, bootstrap) - if err != nil { - l.Error( - err, "Cannot create resources for on-premises cluster", - "cluster spec", kc.Spec.OnPremisesSpec, - ) - r.EventRecorder.Eventf( - kc, models.Warning, models.CreationFailed, - "Resources creation for on-premises cluster is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - err = r.startClusterOnPremisesIPsJob(kc, bootstrap) - if err != nil { - l.Error(err, "Cannot start on-premises cluster IPs check job", - "cluster ID", kc.Status.ID, - ) - - r.EventRecorder.Eventf( - kc, models.Warning, models.CreationFailed, - "On-premises cluster IPs check job is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - l.Info( - "On-premises resources have been created", - "cluster name", kc.Spec.Name, - "on-premises Spec", kc.Spec.OnPremisesSpec, - "cluster ID", kc.Status.ID, - ) + if kc.Spec.DataCentres[0].CloudProvider == models.ONPREMISES { return models.ExitReconcile, nil } @@ -453,23 +380,6 @@ func (r *KafkaConnectReconciler) handleDeleteCluster(ctx context.Context, kc *v1 return models.ExitReconcile, nil } - - if kc.Spec.OnPremisesSpec != nil && kc.Spec.OnPremisesSpec.EnableAutomation { - err = deleteOnPremResources(ctx, r.Client, kc.Status.ID, kc.Namespace) - if err != nil { - l.Error(err, "Cannot delete cluster on-premises resources", - "cluster ID", kc.Status.ID) - r.EventRecorder.Eventf(kc, models.Warning, models.DeletionFailed, - "Cluster on-premises resources deletion is failed. Reason: %v", err) - return reconcile.Result{}, err - } - - l.Info("Cluster on-premises resources are deleted", - "cluster ID", kc.Status.ID) - r.EventRecorder.Eventf(kc, models.Normal, models.Deleted, - "Cluster on-premises resources are deleted") - r.Scheduler.RemoveJob(kc.GetJobID(scheduler.OnPremisesIPsChecker)) - } } err = deleteDefaultUserSecret(ctx, r.Client, client.ObjectKeyFromObject(kc)) diff --git a/controllers/clusters/postgresql_controller.go b/controllers/clusters/postgresql_controller.go index 4164885ca..a366167e7 100644 --- a/controllers/clusters/postgresql_controller.go +++ b/controllers/clusters/postgresql_controller.go @@ -258,81 +258,7 @@ func (r *PostgreSQLReconciler) handleCreateCluster( "Cluster status check job is started", ) - if pg.Spec.OnPremisesSpec != nil && pg.Spec.OnPremisesSpec.EnableAutomation { - iData, err := r.API.GetPostgreSQL(pg.Status.ID) - if err != nil { - l.Error(err, "Cannot get cluster from the Instaclustr API", - "cluster name", pg.Spec.Name, - "data centres", pg.Spec.DataCentres, - "cluster ID", pg.Status.ID, - ) - r.EventRecorder.Eventf( - pg, models.Warning, models.FetchFailed, - "Cluster fetch from the Instaclustr API is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - iPostgreSQL, err := pg.FromInstAPI(iData) - if err != nil { - l.Error( - err, "Cannot convert cluster from the Instaclustr API", - "cluster name", pg.Spec.Name, - "cluster ID", pg.Status.ID, - ) - r.EventRecorder.Eventf( - pg, models.Warning, models.ConversionFailed, - "Cluster convertion from the Instaclustr API to k8s resource is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - bootstrap := newOnPremisesBootstrap( - r.Client, - pg, - r.EventRecorder, - iPostgreSQL.Status.ClusterStatus, - pg.Spec.OnPremisesSpec, - newExposePorts(pg.GetExposePorts()), - pg.GetHeadlessPorts(), - pg.Spec.PrivateNetworkCluster, - ) - - err = handleCreateOnPremisesClusterResources(ctx, bootstrap) - if err != nil { - l.Error( - err, "Cannot create resources for on-premises cluster", - "cluster spec", pg.Spec.OnPremisesSpec, - ) - r.EventRecorder.Eventf( - pg, models.Warning, models.CreationFailed, - "Resources creation for on-premises cluster is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - err = r.startClusterOnPremisesIPsJob(pg, bootstrap) - if err != nil { - l.Error(err, "Cannot start on-premises cluster IPs check job", - "cluster ID", pg.Status.ID, - ) - - r.EventRecorder.Eventf( - pg, models.Warning, models.CreationFailed, - "On-premises cluster IPs check job is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - l.Info( - "On-premises resources have been created", - "cluster name", pg.Spec.Name, - "on-premises Spec", pg.Spec.OnPremisesSpec, - "cluster ID", pg.Status.ID, - ) + if pg.Spec.DataCentres[0].CloudProvider == models.ONPREMISES { return models.ExitReconcile, nil } @@ -859,23 +785,6 @@ func (r *PostgreSQLReconciler) handleDeleteCluster( return models.ExitReconcile, nil } - - if pg.Spec.OnPremisesSpec != nil && pg.Spec.OnPremisesSpec.EnableAutomation { - err = deleteOnPremResources(ctx, r.Client, pg.Status.ID, pg.Namespace) - if err != nil { - l.Error(err, "Cannot delete cluster on-premises resources", - "cluster ID", pg.Status.ID) - r.EventRecorder.Eventf(pg, models.Warning, models.DeletionFailed, - "Cluster on-premises resources deletion is failed. Reason: %v", err) - return reconcile.Result{}, err - } - - l.Info("Cluster on-premises resources are deleted", - "cluster ID", pg.Status.ID) - r.EventRecorder.Eventf(pg, models.Normal, models.Deleted, - "Cluster on-premises resources are deleted") - r.Scheduler.RemoveJob(pg.GetJobID(scheduler.OnPremisesIPsChecker)) - } } l.Info("PostgreSQL cluster is being deleted. Deleting PostgreSQL default user secret", diff --git a/controllers/clusters/redis_controller.go b/controllers/clusters/redis_controller.go index f70874fe3..63d9249af 100644 --- a/controllers/clusters/redis_controller.go +++ b/controllers/clusters/redis_controller.go @@ -242,81 +242,7 @@ func (r *RedisReconciler) handleCreateCluster( "Cluster status check job is started", ) - if redis.Spec.OnPremisesSpec != nil && redis.Spec.OnPremisesSpec.EnableAutomation { - iData, err := r.API.GetRedis(redis.Status.ID) - if err != nil { - l.Error(err, "Cannot get cluster from the Instaclustr API", - "cluster name", redis.Spec.Name, - "data centres", redis.Spec.DataCentres, - "cluster ID", redis.Status.ID, - ) - r.EventRecorder.Eventf( - redis, models.Warning, models.FetchFailed, - "Cluster fetch from the Instaclustr API is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - iRedis, err := redis.FromInstAPI(iData) - if err != nil { - l.Error( - err, "Cannot convert cluster from the Instaclustr API", - "cluster name", redis.Spec.Name, - "cluster ID", redis.Status.ID, - ) - r.EventRecorder.Eventf( - redis, models.Warning, models.ConversionFailed, - "Cluster convertion from the Instaclustr API to k8s resource is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - bootstrap := newOnPremisesBootstrap( - r.Client, - redis, - r.EventRecorder, - iRedis.Status.ClusterStatus, - redis.Spec.OnPremisesSpec, - newExposePorts(redis.GetExposePorts()), - redis.GetHeadlessPorts(), - redis.Spec.PrivateNetworkCluster, - ) - - err = handleCreateOnPremisesClusterResources(ctx, bootstrap) - if err != nil { - l.Error( - err, "Cannot create resources for on-premises cluster", - "cluster spec", redis.Spec.OnPremisesSpec, - ) - r.EventRecorder.Eventf( - redis, models.Warning, models.CreationFailed, - "Resources creation for on-premises cluster is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - err = r.startClusterOnPremisesIPsJob(redis, bootstrap) - if err != nil { - l.Error(err, "Cannot start on-premises cluster IPs check job", - "cluster ID", redis.Status.ID, - ) - - r.EventRecorder.Eventf( - redis, models.Warning, models.CreationFailed, - "On-premises cluster IPs check job is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } - - l.Info( - "On-premises resources have been created", - "cluster name", redis.Spec.Name, - "on-premises Spec", redis.Spec.OnPremisesSpec, - "cluster ID", redis.Status.ID, - ) + if redis.Spec.DataCentres[0].CloudProvider == models.ONPREMISES { return models.ExitReconcile, nil } @@ -561,22 +487,6 @@ func (r *RedisReconciler) handleDeleteCluster( return models.ExitReconcile, nil } - if redis.Spec.OnPremisesSpec != nil && redis.Spec.OnPremisesSpec.EnableAutomation { - err = deleteOnPremResources(ctx, r.Client, redis.Status.ID, redis.Namespace) - if err != nil { - l.Error(err, "Cannot delete cluster on-premises resources", - "cluster ID", redis.Status.ID) - r.EventRecorder.Eventf(redis, models.Warning, models.DeletionFailed, - "Cluster on-premises resources deletion is failed. Reason: %v", err) - return reconcile.Result{}, err - } - - l.Info("Cluster on-premises resources are deleted", - "cluster ID", redis.Status.ID) - r.EventRecorder.Eventf(redis, models.Normal, models.Deleted, - "Cluster on-premises resources are deleted") - r.Scheduler.RemoveJob(redis.GetJobID(scheduler.OnPremisesIPsChecker)) - } } r.Scheduler.RemoveJob(redis.GetJobID(scheduler.StatusChecker)) diff --git a/pkg/models/validation.go b/pkg/models/validation.go index 410275d55..8dea232c3 100644 --- a/pkg/models/validation.go +++ b/pkg/models/validation.go @@ -21,7 +21,7 @@ var ( KafkaConnectVPCTypes = []string{"KAFKA_VPC", "VPC_PEERED", "SEPARATE_VPC"} PoolModes = []string{"TRANSACTION", "SESSION", "STATEMENT"} ReplicationModes = []string{"ASYNCHRONOUS", "SYNCHRONOUS"} - CloudProviders = []string{"AWS_VPC", "GCP", "AZURE_AZ"} + CloudProviders = []string{"AWS_VPC", "GCP", "AZURE_AZ", "ONPREMISES"} SLATiers = []string{"PRODUCTION", "NON_PRODUCTION"} ClusterNameRegExp = "^[a-zA-Z0-9][a-zA-Z0-9_-]{2,31}$" BundleTypes = []string{"APACHE_ZOOKEEPER", "CADENCE", "CADENCE_GRPC",