diff --git a/.secrets.baseline b/.secrets.baseline index 545dcbd7..7daca68b 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -75,10 +75,6 @@ { "path": "detect_secrets.filters.allowlist.is_line_allowlisted" }, - { - "path": "detect_secrets.filters.common.is_baseline_file", - "filename": ".secrets.baseline" - }, { "path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies", "min_level": 2 @@ -118,15 +114,6 @@ } ], "results": { - ".idea/workspace.xml": [ - { - "type": "Base64 High Entropy String", - "filename": ".idea/workspace.xml", - "hashed_secret": "ceda554256d1b9fa42791b09d9798634f930ad04", - "is_verified": false, - "line_number": 42 - } - ], "apis/clusterresources/v1beta1/cassandrauser_types.go": [ { "type": "Secret Keyword", @@ -217,7 +204,7 @@ "filename": "apis/clusters/v1beta1/cassandra_webhook.go", "hashed_secret": "e0a46b27231f798fe22dc4d5d82b5feeb5dcf085", "is_verified": false, - "line_number": 232 + "line_number": 244 } ], "apis/clusters/v1beta1/kafka_types.go": [ @@ -360,7 +347,7 @@ "filename": "apis/clusters/v1beta1/redis_webhook.go", "hashed_secret": "bc1c5ae5fd4a238d86261f422e62c489de408c22", "is_verified": false, - "line_number": 323 + "line_number": 335 } ], "apis/clusters/v1beta1/zz_generated.deepcopy.go": [ @@ -505,12 +492,40 @@ } ], "controllers/clusters/cadence_controller.go": [ + { + "type": "Secret Keyword", + "filename": "controllers/clusters/cadence_controller.go", + "hashed_secret": "2d8ca9a11a2e2ef6931d0f0ef52b1896114a4558", + "is_verified": false, + "line_number": 167 + }, + { + "type": "Secret Keyword", + "filename": "controllers/clusters/cadence_controller.go", + "hashed_secret": "8902e39ab80b0808afb4654751df63517d106008", + "is_verified": false, + "line_number": 171 + }, + { + "type": "Secret Keyword", + "filename": "controllers/clusters/cadence_controller.go", + "hashed_secret": "dd8e1e714663d659a0b6932bfad048e0f0ef1f82", + "is_verified": false, + "line_number": 221 + }, + { + "type": "Secret Keyword", + "filename": "controllers/clusters/cadence_controller.go", + "hashed_secret": "2ba76f2b678a4173c4989c88db3505b0a0265d6f", + "is_verified": false, + "line_number": 222 + }, { "type": "Secret Keyword", "filename": "controllers/clusters/cadence_controller.go", "hashed_secret": "5ffe533b830f08a0326348a9160afafc8ada44db", "is_verified": false, - "line_number": 750 + "line_number": 831 } ], "controllers/clusters/datatest/kafka_v1beta1.yaml": [ @@ -1134,5 +1149,5 @@ } ] }, - "generated_at": "2024-03-06T14:06:22Z" + "generated_at": "2024-03-11T14:02:24Z" } diff --git a/apis/clusters/v1beta1/cadence_webhook.go b/apis/clusters/v1beta1/cadence_webhook.go index 2d884e11..c2ac9543 100644 --- a/apis/clusters/v1beta1/cadence_webhook.go +++ b/apis/clusters/v1beta1/cadence_webhook.go @@ -56,6 +56,14 @@ var _ webhook.Defaulter = &Cadence{} func (c *Cadence) Default() { cadencelog.Info("default", "name", c.Name) + if c.Spec.Inherits() && c.Status.ID == "" && c.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent { + c.Spec = CadenceSpec{ + GenericClusterSpec: GenericClusterSpec{InheritsFrom: c.Spec.InheritsFrom}, + DataCentres: []*CadenceDataCentre{{}}, + } + c.Spec.GenericClusterSpec.setDefaultValues() + } + if c.Spec.Name == "" { c.Spec.Name = c.Name } @@ -85,6 +93,10 @@ func (cv *cadenceValidator) ValidateCreate(ctx context.Context, obj runtime.Obje cadencelog.Info("validate create", "name", c.Name) + if c.Spec.Inherits() { + return nil + } + err := requiredfieldsvalidator.ValidateRequiredFields(c.Spec) if err != nil { return err diff --git a/apis/clusters/v1beta1/cassandra_webhook.go b/apis/clusters/v1beta1/cassandra_webhook.go index 67f87707..b03a96f5 100644 --- a/apis/clusters/v1beta1/cassandra_webhook.go +++ b/apis/clusters/v1beta1/cassandra_webhook.go @@ -58,6 +58,14 @@ var _ webhook.Defaulter = &Cassandra{} func (c *Cassandra) Default() { cassandralog.Info("default", "name", c.Name) + if c.Spec.Inherits() && c.Status.ID == "" && c.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent { + c.Spec = CassandraSpec{ + GenericClusterSpec: GenericClusterSpec{InheritsFrom: c.Spec.InheritsFrom}, + DataCentres: []*CassandraDataCentre{{}}, + } + c.Spec.GenericClusterSpec.setDefaultValues() + } + if c.Spec.Name == "" { c.Spec.Name = c.Name } @@ -76,6 +84,10 @@ func (cv *cassandraValidator) ValidateCreate(ctx context.Context, obj runtime.Ob return fmt.Errorf("cannot assert object %v to cassandra", obj.GetObjectKind()) } + if c.Spec.Inherits() { + return nil + } + cassandralog.Info("validate create", "name", c.Name) err := requiredfieldsvalidator.ValidateRequiredFields(c.Spec) diff --git a/apis/clusters/v1beta1/generic_spec.go b/apis/clusters/v1beta1/generic_spec.go index 776b756e..bd0a4e9e 100644 --- a/apis/clusters/v1beta1/generic_spec.go +++ b/apis/clusters/v1beta1/generic_spec.go @@ -233,3 +233,8 @@ func (s *GenericDataCentreSpec) cloudProviderSettingsFromInstAPI(instaModel *mod func (s *GenericClusterSpec) Inherits() bool { return s.InheritsFrom != "" } + +func (in *GenericClusterSpec) setDefaultValues() { + in.Version = "DEFAULT_VERSION" + in.SLATier = "NON_PRODUCTION" +} diff --git a/apis/clusters/v1beta1/kafka_webhook.go b/apis/clusters/v1beta1/kafka_webhook.go index ee558d33..3d376ec6 100644 --- a/apis/clusters/v1beta1/kafka_webhook.go +++ b/apis/clusters/v1beta1/kafka_webhook.go @@ -56,6 +56,14 @@ var _ webhook.Defaulter = &Kafka{} func (k *Kafka) Default() { kafkalog.Info("default", "name", k.Name) + if k.Spec.Inherits() && k.Status.ID == "" && k.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent { + k.Spec = KafkaSpec{ + GenericClusterSpec: GenericClusterSpec{InheritsFrom: k.Spec.InheritsFrom}, + DataCentres: []*KafkaDataCentre{{}}, + } + k.Spec.GenericClusterSpec.setDefaultValues() + } + if k.Spec.Name == "" { k.Spec.Name = k.Name } @@ -79,6 +87,10 @@ func (kv *kafkaValidator) ValidateCreate(ctx context.Context, obj runtime.Object return fmt.Errorf("cannot assert object %v to kafka", obj.GetObjectKind()) } + if k.Spec.Inherits() { + return nil + } + kafkalog.Info("validate create", "name", k.Name) err := requiredfieldsvalidator.ValidateRequiredFields(k.Spec) diff --git a/apis/clusters/v1beta1/kafkaconnect_webhook.go b/apis/clusters/v1beta1/kafkaconnect_webhook.go index 3e1ba3cc..2213eacf 100644 --- a/apis/clusters/v1beta1/kafkaconnect_webhook.go +++ b/apis/clusters/v1beta1/kafkaconnect_webhook.go @@ -53,15 +53,23 @@ func (r *KafkaConnect) SetupWebhookWithManager(mgr ctrl.Manager, api validation. var _ webhook.Defaulter = &KafkaConnect{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *KafkaConnect) Default() { - kafkaconnectlog.Info("default", "name", r.Name) +func (k *KafkaConnect) Default() { + kafkaconnectlog.Info("default", "name", k.Name) - if r.Spec.Name == "" { - r.Spec.Name = r.Name + if k.Spec.Inherits() && k.Status.ID == "" && k.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent { + k.Spec = KafkaConnectSpec{ + GenericClusterSpec: GenericClusterSpec{InheritsFrom: k.Spec.InheritsFrom}, + DataCentres: []*KafkaConnectDataCentre{{}}, + } + k.Spec.GenericClusterSpec.setDefaultValues() + } + + if k.Spec.Name == "" { + k.Spec.Name = k.Name } - if r.GetAnnotations() == nil { - r.SetAnnotations(map[string]string{ + if k.GetAnnotations() == nil { + k.SetAnnotations(map[string]string{ models.ResourceStateAnnotation: "", }) } @@ -79,6 +87,10 @@ func (kcv *kafkaConnectValidator) ValidateCreate(ctx context.Context, obj runtim return fmt.Errorf("cannot assert object %v to kafka connect", obj.GetObjectKind()) } + if kc.Spec.Inherits() { + return nil + } + kafkaconnectlog.Info("validate create", "name", kc.Name) err := requiredfieldsvalidator.ValidateRequiredFields(kc.Spec) diff --git a/apis/clusters/v1beta1/opensearch_webhook.go b/apis/clusters/v1beta1/opensearch_webhook.go index fd94e495..d9023064 100644 --- a/apis/clusters/v1beta1/opensearch_webhook.go +++ b/apis/clusters/v1beta1/opensearch_webhook.go @@ -52,6 +52,15 @@ var _ webhook.CustomValidator = &openSearchValidator{} var _ webhook.Defaulter = &OpenSearch{} func (os *OpenSearch) Default() { + if os.Spec.Inherits() && os.Status.ID == "" && os.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent { + os.Spec = OpenSearchSpec{ + GenericClusterSpec: GenericClusterSpec{InheritsFrom: os.Spec.InheritsFrom}, + DataCentres: []*OpenSearchDataCentre{{}}, + ClusterManagerNodes: []*ClusterManagerNodes{{}}, + } + os.Spec.GenericClusterSpec.setDefaultValues() + } + for _, dataCentre := range os.Spec.DataCentres { setDefaultValues(dataCentre) @@ -86,6 +95,10 @@ func (osv *openSearchValidator) ValidateCreate(ctx context.Context, obj runtime. return fmt.Errorf("cannot assert object %v to openSearch", obj.GetObjectKind()) } + if os.Spec.Inherits() { + return nil + } + opensearchlog.Info("validate create", "name", os.Name) err := requiredfieldsvalidator.ValidateRequiredFields(os.Spec) diff --git a/apis/clusters/v1beta1/postgresql_webhook.go b/apis/clusters/v1beta1/postgresql_webhook.go index 5e2a0ec0..6d41bd96 100644 --- a/apis/clusters/v1beta1/postgresql_webhook.go +++ b/apis/clusters/v1beta1/postgresql_webhook.go @@ -60,6 +60,14 @@ var _ webhook.Defaulter = &PostgreSQL{} func (pg *PostgreSQL) Default() { postgresqllog.Info("default", "name", pg.Name) + if pg.Spec.Inherits() && pg.Status.ID == "" && pg.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent { + pg.Spec = PgSpec{ + GenericClusterSpec: GenericClusterSpec{InheritsFrom: pg.Spec.InheritsFrom}, + DataCentres: []*PgDataCentre{}, + } + pg.Spec.GenericClusterSpec.setDefaultValues() + } + if pg.Spec.Name == "" { pg.Spec.Name = pg.Name } @@ -78,6 +86,10 @@ func (pgv *pgValidator) ValidateCreate(ctx context.Context, obj runtime.Object) return fmt.Errorf("cannot assert object %v to postgreSQL", obj.GetObjectKind()) } + if pg.Spec.Inherits() { + return nil + } + postgresqllog.Info("validate create", "name", pg.Name) err := requiredfieldsvalidator.ValidateRequiredFields(pg.Spec) diff --git a/apis/clusters/v1beta1/redis_webhook.go b/apis/clusters/v1beta1/redis_webhook.go index b0aaa117..6d2b47a2 100644 --- a/apis/clusters/v1beta1/redis_webhook.go +++ b/apis/clusters/v1beta1/redis_webhook.go @@ -55,6 +55,14 @@ var _ webhook.Defaulter = &Redis{} func (r *Redis) Default() { redislog.Info("default", "name", r.Name) + if r.Spec.Inherits() && r.Status.ID == "" && r.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent { + r.Spec = RedisSpec{ + GenericClusterSpec: GenericClusterSpec{InheritsFrom: r.Spec.InheritsFrom}, + DataCentres: []*RedisDataCentre{{}}, + } + r.Spec.GenericClusterSpec.setDefaultValues() + } + if r.Spec.Name == "" { r.Spec.Name = r.Name redislog.Info("default values are set", "name", r.Name) @@ -89,6 +97,10 @@ func (rv *redisValidator) ValidateCreate(ctx context.Context, obj runtime.Object return fmt.Errorf("cannot assert object %v to redis", obj.GetObjectKind()) } + if r.Spec.Inherits() { + return nil + } + redislog.Info("validate create", "name", r.Name) err := requiredfieldsvalidator.ValidateRequiredFields(r.Spec) diff --git a/apis/clusters/v1beta1/zookeeper_webhook.go b/apis/clusters/v1beta1/zookeeper_webhook.go index a4c67fe1..fd093edc 100644 --- a/apis/clusters/v1beta1/zookeeper_webhook.go +++ b/apis/clusters/v1beta1/zookeeper_webhook.go @@ -52,6 +52,14 @@ var _ webhook.Defaulter = &Zookeeper{} func (z *Zookeeper) Default() { redislog.Info("default", "name", z.Name) + if z.Spec.Inherits() && z.Status.ID == "" && z.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent { + z.Spec = ZookeeperSpec{ + GenericClusterSpec: GenericClusterSpec{InheritsFrom: z.Spec.InheritsFrom}, + DataCentres: []*ZookeeperDataCentre{{}}, + } + z.Spec.GenericClusterSpec.setDefaultValues() + } + if z.Spec.Name == "" { z.Spec.Name = z.Name } @@ -75,6 +83,10 @@ func (zv *zookeeperValidator) ValidateCreate(ctx context.Context, obj runtime.Ob return fmt.Errorf("cannot assert object %v to zookeeper", obj.GetObjectKind()) } + if z.Spec.Inherits() { + return nil + } + zookeeperlog.Info("validate create", "name", z.Name) err := requiredfieldsvalidator.ValidateRequiredFields(z.Spec) diff --git a/config/samples/clusters_v1beta1_cadence.yaml b/config/samples/clusters_v1beta1_cadence.yaml index 47cef1c4..82bad2c9 100644 --- a/config/samples/clusters_v1beta1_cadence.yaml +++ b/config/samples/clusters_v1beta1_cadence.yaml @@ -11,15 +11,16 @@ kind: Cadence metadata: name: cadence-sample spec: - name: "bohdan-cadence-test" + name: "example-cadence" version: "1.2.2" # standardProvisioning: # - targetCassandra: # dependencyCdcId: "9d43ac54-7317-4ce5-859a-e9d0443508a4" # dependencyVpcType: "VPC_PEERED" packagedProvisioning: - - useAdvancedVisibility: true - solutionSize: "Production-Small" + - +# useAdvancedVisibility: true + solutionSize: "Production-Small" # twoFactorDelete: # - email: "rostyslp@netapp.com" privateNetwork: false @@ -44,4 +45,9 @@ spec: # dependencyVpcType: "SEPARATE_VPC" resizeSettings: - notifySupportContacts: false - concurrency: 1 \ No newline at end of file + concurrency: 1 +# awsArchival: +# - archivalS3Uri: s3bucketURI +# archivalS3Region: US_EAST_1 +# awsAccessKeySecretNamespace: default +# awsAccessKeySecretName: inst-test-aws-cred-secret diff --git a/config/samples/clusters_v1beta1_cadence_inherits.yaml b/config/samples/clusters_v1beta1_cadence_inherits.yaml new file mode 100644 index 00000000..4599f3cd --- /dev/null +++ b/config/samples/clusters_v1beta1_cadence_inherits.yaml @@ -0,0 +1,6 @@ +apiVersion: clusters.instaclustr.com/v1beta1 +kind: Cadence +metadata: + name: cadence-inherited +spec: + inheritsFrom: "c8c80bf3-4489-426f-8a84-450b9acfefc3" \ No newline at end of file diff --git a/config/samples/clusters_v1beta1_cassandra.yaml b/config/samples/clusters_v1beta1_cassandra.yaml index e63c8ee6..258ea57f 100644 --- a/config/samples/clusters_v1beta1_cassandra.yaml +++ b/config/samples/clusters_v1beta1_cassandra.yaml @@ -3,7 +3,7 @@ kind: Cassandra metadata: name: cassandra-cluster spec: - name: "bohdan-cassandra" #(immutable) + name: "example-cassandra" #(immutable) version: "4.1.3" #(immutable) # inheritsFrom: "42a0fa34-a647-4a30-96e0-fde64aba0eae" privateNetwork: false #(immutable) diff --git a/config/samples/clusters_v1beta1_cassandra_inherits.yaml b/config/samples/clusters_v1beta1_cassandra_inherits.yaml new file mode 100644 index 00000000..2417b792 --- /dev/null +++ b/config/samples/clusters_v1beta1_cassandra_inherits.yaml @@ -0,0 +1,6 @@ +apiVersion: clusters.instaclustr.com/v1beta1 +kind: Cassandra +metadata: + name: cassandra-inherited +spec: + inheritsFrom: "c1a84b4f-9b67-43e0-ac33-038290aea71d" \ No newline at end of file diff --git a/config/samples/clusters_v1beta1_kafka_inherits.yaml b/config/samples/clusters_v1beta1_kafka_inherits.yaml new file mode 100644 index 00000000..c07ea331 --- /dev/null +++ b/config/samples/clusters_v1beta1_kafka_inherits.yaml @@ -0,0 +1,6 @@ +apiVersion: clusters.instaclustr.com/v1beta1 +kind: Kafka +metadata: + name: kafka-inherited +spec: + inheritsFrom: "681faf22-b305-45bb-bfcf-c85ea15dab37" \ No newline at end of file diff --git a/config/samples/clusters_v1beta1_kafkaconnect_inherits.yaml b/config/samples/clusters_v1beta1_kafkaconnect_inherits.yaml new file mode 100644 index 00000000..e19afa8a --- /dev/null +++ b/config/samples/clusters_v1beta1_kafkaconnect_inherits.yaml @@ -0,0 +1,6 @@ +apiVersion: clusters.instaclustr.com/v1beta1 +kind: KafkaConnect +metadata: + name: kafkaconnect-inherited +spec: + inheritsFrom: "c1a84b4f-9b67-43e0-ac33-038290aea71d" \ No newline at end of file diff --git a/config/samples/clusters_v1beta1_opensearch.yaml b/config/samples/clusters_v1beta1_opensearch.yaml index 3c87c9db..c184f33a 100644 --- a/config/samples/clusters_v1beta1_opensearch.yaml +++ b/config/samples/clusters_v1beta1_opensearch.yaml @@ -7,12 +7,11 @@ metadata: app.kubernetes.io/part-of: operator app.kuberentes.io/managed-by: kustomize app.kubernetes.io/created-by: operator - name: opensearch-sample2 + name: opensearch-sample annotations: test.annotation/first: testAnnotation spec: - name: bohdan-test2 - inheritsFrom: ed8a0dc3-0a41-4e94-a508-3d5cf4b1a28b + name: example-opensearch alertingPlugin: false anomalyDetectionPlugin: false asynchronousSearchPlugin: false diff --git a/config/samples/clusters_v1beta1_opensearch_inherits.yaml b/config/samples/clusters_v1beta1_opensearch_inherits.yaml new file mode 100644 index 00000000..798934c5 --- /dev/null +++ b/config/samples/clusters_v1beta1_opensearch_inherits.yaml @@ -0,0 +1,6 @@ +apiVersion: clusters.instaclustr.com/v1beta1 +kind: OpenSearch +metadata: + name: opensearch-inherited +spec: + inheritsFrom: "75ac9917-ba00-4ea1-b30e-45051c8dca63" \ No newline at end of file diff --git a/config/samples/clusters_v1beta1_postgresql_inherits.yaml b/config/samples/clusters_v1beta1_postgresql_inherits.yaml new file mode 100644 index 00000000..8aa3db67 --- /dev/null +++ b/config/samples/clusters_v1beta1_postgresql_inherits.yaml @@ -0,0 +1,6 @@ +apiVersion: clusters.instaclustr.com/v1beta1 +kind: PostgreSQL +metadata: + name: postgresql-inherited +spec: + inheritsFrom: "46857148-ca5b-4b80-9e03-fb8c6ebadf60" \ No newline at end of file diff --git a/config/samples/clusters_v1beta1_redis.yaml b/config/samples/clusters_v1beta1_redis.yaml index 67a99370..be074172 100644 --- a/config/samples/clusters_v1beta1_redis.yaml +++ b/config/samples/clusters_v1beta1_redis.yaml @@ -1,16 +1,9 @@ apiVersion: clusters.instaclustr.com/v1beta1 kind: Redis metadata: - labels: - app.kubernetes.io/name: redis - app.kubernetes.io/instance: redis-sample - app.kubernetes.io/part-of: operator - app.kuberentes.io/managed-by: kustomize - app.kubernetes.io/created-by: operator name: redis-sample - namespace: nm1 spec: - name: "bohdan-redis1" + name: "bohdan-redis" version: "7.0.14" slaTier: "NON_PRODUCTION" clientEncryption: false diff --git a/config/samples/clusters_v1beta1_redis_inherits.yaml b/config/samples/clusters_v1beta1_redis_inherits.yaml new file mode 100644 index 00000000..8b6b67ca --- /dev/null +++ b/config/samples/clusters_v1beta1_redis_inherits.yaml @@ -0,0 +1,6 @@ +apiVersion: clusters.instaclustr.com/v1beta1 +kind: Redis +metadata: + name: redis-inherited +spec: + inheritsFrom: "718c592e-760f-4ba6-9545-a5e643663afe" \ No newline at end of file diff --git a/config/samples/clusters_v1beta1_redis_restore.yaml b/config/samples/clusters_v1beta1_redis_restore.yaml index 762f5ce0..843ec6a8 100644 --- a/config/samples/clusters_v1beta1_redis_restore.yaml +++ b/config/samples/clusters_v1beta1_redis_restore.yaml @@ -12,5 +12,4 @@ spec: restoreFrom: clusterId: "1bece950-c79d-441b-8363-6b8cd9069db0" restoredClusterName: "redisRESTORED" - pointInTime: 1677505625158 - clusterNetwork: "10.13.0.0/16" \ No newline at end of file + pointInTime: 1677505625158 \ No newline at end of file diff --git a/config/samples/clusters_v1beta1_zookeeper_inherits.yaml b/config/samples/clusters_v1beta1_zookeeper_inherits.yaml new file mode 100644 index 00000000..34dc0095 --- /dev/null +++ b/config/samples/clusters_v1beta1_zookeeper_inherits.yaml @@ -0,0 +1,6 @@ +apiVersion: clusters.instaclustr.com/v1beta1 +kind: Zookeeper +metadata: + name: zookeeper-inherited +spec: + inheritsFrom: "61cad31f-3c5c-4d5d-b1c3-c553b786f428" \ No newline at end of file diff --git a/controllers/clusters/cadence_controller.go b/controllers/clusters/cadence_controller.go index 1d142e93..7e8dd65f 100644 --- a/controllers/clusters/cadence_controller.go +++ b/controllers/clusters/cadence_controller.go @@ -23,6 +23,7 @@ import ( "fmt" "github.com/go-logr/logr" + corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -148,6 +149,37 @@ func (r *CadenceReconciler) createCadence(ctx context.Context, c *v1beta1.Cadenc return instaModel, nil } +func (r *CadenceReconciler) createAWSArchivalSecret(ctx context.Context, c *v1beta1.Cadence, awsArchival []*models.AWSArchival) (*corev1.Secret, error) { + secret := &corev1.Secret{ + ObjectMeta: ctrl.ObjectMeta{ + Name: fmt.Sprintf("%s-aws-archival", c.Name), + Namespace: c.Namespace, + }, + } + + err := controllerutil.SetOwnerReference(c, secret, r.Scheme) + if err != nil { + return nil, fmt.Errorf("failed to set owner reference for aws-archival secret, err: %w", err) + } + + secret.StringData = make(map[string]string) + + const awsSecretAccessKey = "awsSecretAccessKey" + const awsAccessKeyID = "awsAccessKeyId" + + for _, archival := range awsArchival { + secret.StringData[awsSecretAccessKey] = archival.AWSSecretAccessKey + secret.StringData[awsAccessKeyID] = archival.AWSAccessKeyID + } + + err = r.Create(ctx, secret) + if err != nil { + return nil, fmt.Errorf("secret creating failed, err: %w", err) + } + + return secret, nil +} + func (r *CadenceReconciler) createCluster(ctx context.Context, c *v1beta1.Cadence, l logr.Logger) error { if !c.Spec.Inherits() { id, err := getClusterIDByName(r.API, models.CassandraAppType, c.Spec.Name) @@ -177,6 +209,20 @@ func (r *CadenceReconciler) createCluster(ctx context.Context, c *v1beta1.Cadenc patch := c.NewPatch() + if c.Spec.Inherits() && len(instaModel.AWSArchival) > 0 { + secret, err := r.createAWSArchivalSecret(ctx, c, instaModel.AWSArchival) + if err != nil { + return fmt.Errorf("failed to create aws-archival secret, err: %w", err) + } + + c.Spec.AWSArchival = []*v1beta1.AWSArchival{{ + ArchivalS3URI: instaModel.AWSArchival[0].ArchivalS3URI, + ArchivalS3Region: instaModel.AWSArchival[0].ArchivalS3Region, + AccessKeySecretNamespace: secret.Namespace, + AccessKeySecretName: secret.Name, + }} + } + c.Spec.FromInstAPI(instaModel) c.Annotations[models.ResourceStateAnnotation] = models.SyncingEvent err = r.Patch(ctx, c, patch) diff --git a/controllers/clusters/cassandra_controller.go b/controllers/clusters/cassandra_controller.go index 9761ff28..e5fbb957 100644 --- a/controllers/clusters/cassandra_controller.go +++ b/controllers/clusters/cassandra_controller.go @@ -242,15 +242,17 @@ func (r *CassandraReconciler) createCluster(ctx context.Context, c *v1beta1.Cass return fmt.Errorf("failed to create cluster, err: %w", err) } + patch := c.NewPatch() + c.Spec.FromInstAPI(instModel) c.Annotations[models.ResourceStateAnnotation] = models.SyncingEvent - err = r.Update(ctx, c) + err = r.Patch(ctx, c, patch) if err != nil { return fmt.Errorf("failed to update cassandra spec, err: %w", err) } c.Status.FromInstAPI(instModel) - err = r.Status().Update(ctx, c) + err = r.Status().Patch(ctx, c, patch) if err != nil { return fmt.Errorf("failed to update cassandra status, err: %w", err) }