From 3cadddf538219d5768ddcb2daab2f7c4a874e377 Mon Sep 17 00:00:00 2001 From: Amin Mohammadian Date: Wed, 16 Oct 2024 15:22:32 +0330 Subject: [PATCH 1/3] Refactor Storage and Database CRDs to integrate all CRDs to gobackup.io apiGroup --- ...sqls.yaml => gobackup.io_postgresqls.yaml} | 4 +- ...ackup.io_s3s.yaml => gobackup.io_s3s.yaml} | 4 +- config/crd/kustomization.yaml | 4 +- .../rbac/database_postgresql_editor_role.yaml | 4 +- .../rbac/database_postgresql_viewer_role.yaml | 4 +- config/rbac/role.yaml | 12 ++-- config/rbac/storage_s3_editor_role.yaml | 4 +- config/rbac/storage_s3_viewer_role.yaml | 4 +- config/samples/backup_v1_cronbackup.yaml | 4 +- config/samples/crd.yaml | 60 +++++++++---------- config/samples/database_v1_postgresql.yaml | 2 +- config/samples/example.yaml | 38 ++++++------ config/samples/storage_v1_s3.yaml | 2 +- example/database/postgresql.yaml | 2 +- example/gobackup-opetator/backup.yaml | 4 +- example/gobackup-opetator/cronbackup.yaml | 4 +- example/storage/s3.yaml | 2 +- 17 files changed, 79 insertions(+), 79 deletions(-) rename config/crd/bases/{database.gobackup.io_postgresqls.yaml => gobackup.io_postgresqls.yaml} (96%) rename config/crd/bases/{storage.gobackup.io_s3s.yaml => gobackup.io_s3s.yaml} (97%) diff --git a/config/crd/bases/database.gobackup.io_postgresqls.yaml b/config/crd/bases/gobackup.io_postgresqls.yaml similarity index 96% rename from config/crd/bases/database.gobackup.io_postgresqls.yaml rename to config/crd/bases/gobackup.io_postgresqls.yaml index 53249da..11c7cbb 100644 --- a/config/crd/bases/database.gobackup.io_postgresqls.yaml +++ b/config/crd/bases/gobackup.io_postgresqls.yaml @@ -4,9 +4,9 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.13.0 - name: postgresqls.database.gobackup.io + name: postgresqls.gobackup.io spec: - group: database.gobackup.io + group: gobackup.io names: kind: PostgreSQL listKind: PostgreSQLList diff --git a/config/crd/bases/storage.gobackup.io_s3s.yaml b/config/crd/bases/gobackup.io_s3s.yaml similarity index 97% rename from config/crd/bases/storage.gobackup.io_s3s.yaml rename to config/crd/bases/gobackup.io_s3s.yaml index 331f752..079fc29 100644 --- a/config/crd/bases/storage.gobackup.io_s3s.yaml +++ b/config/crd/bases/gobackup.io_s3s.yaml @@ -4,9 +4,9 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.13.0 - name: s3s.storage.gobackup.io + name: s3s.gobackup.io spec: - group: storage.gobackup.io + group: gobackup.io names: kind: S3 listKind: S3List diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index e147359..80bc759 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -5,8 +5,8 @@ resources: - bases/gobackup.io_backupmodels.yaml - bases/gobackup.io_cronbackups.yaml - bases/gobackup.io_backups.yaml -- bases/database.gobackup.io_postgresqls.yaml -- bases/storage.gobackup.io_s3s.yaml +- bases/gobackup.io_postgresqls.yaml +- bases/gobackup.io_s3s.yaml #+kubebuilder:scaffold:crdkustomizeresource patches: diff --git a/config/rbac/database_postgresql_editor_role.yaml b/config/rbac/database_postgresql_editor_role.yaml index 11b8501..25a72e3 100644 --- a/config/rbac/database_postgresql_editor_role.yaml +++ b/config/rbac/database_postgresql_editor_role.yaml @@ -8,7 +8,7 @@ metadata: name: database-postgresql-editor-role rules: - apiGroups: - - database.gobackup.io + - gobackup.io resources: - postgresqls verbs: @@ -20,7 +20,7 @@ rules: - update - watch - apiGroups: - - database.gobackup.io + - gobackup.io resources: - postgresqls/status verbs: diff --git a/config/rbac/database_postgresql_viewer_role.yaml b/config/rbac/database_postgresql_viewer_role.yaml index 9736286..7af7293 100644 --- a/config/rbac/database_postgresql_viewer_role.yaml +++ b/config/rbac/database_postgresql_viewer_role.yaml @@ -8,7 +8,7 @@ metadata: name: database-postgresql-viewer-role rules: - apiGroups: - - database.gobackup.io + - gobackup.io resources: - postgresqls verbs: @@ -16,7 +16,7 @@ rules: - list - watch - apiGroups: - - database.gobackup.io + - gobackup.io resources: - postgresqls/status verbs: diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 3ab4c2d..cc56b33 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -5,7 +5,7 @@ metadata: name: manager-role rules: - apiGroups: - - database.gobackup.io + - gobackup.io resources: - postgresqls verbs: @@ -17,13 +17,13 @@ rules: - update - watch - apiGroups: - - database.gobackup.io + - gobackup.io resources: - postgresqls/finalizers verbs: - update - apiGroups: - - database.gobackup.io + - gobackup.io resources: - postgresqls/status verbs: @@ -57,7 +57,7 @@ rules: - patch - update - apiGroups: - - storage.gobackup.io + - gobackup.io resources: - s3s verbs: @@ -69,13 +69,13 @@ rules: - update - watch - apiGroups: - - storage.gobackup.io + - gobackup.io resources: - s3s/finalizers verbs: - update - apiGroups: - - storage.gobackup.io + - gobackup.io resources: - s3s/status verbs: diff --git a/config/rbac/storage_s3_editor_role.yaml b/config/rbac/storage_s3_editor_role.yaml index 581fcee..7784a6f 100644 --- a/config/rbac/storage_s3_editor_role.yaml +++ b/config/rbac/storage_s3_editor_role.yaml @@ -8,7 +8,7 @@ metadata: name: storage-s3-editor-role rules: - apiGroups: - - storage.gobackup.io + - gobackup.io resources: - s3s verbs: @@ -20,7 +20,7 @@ rules: - update - watch - apiGroups: - - storage.gobackup.io + - gobackup.io resources: - s3s/status verbs: diff --git a/config/rbac/storage_s3_viewer_role.yaml b/config/rbac/storage_s3_viewer_role.yaml index 6a17ad2..6ad630c 100644 --- a/config/rbac/storage_s3_viewer_role.yaml +++ b/config/rbac/storage_s3_viewer_role.yaml @@ -8,7 +8,7 @@ metadata: name: storage-s3-viewer-role rules: - apiGroups: - - storage.gobackup.io + - gobackup.io resources: - s3s verbs: @@ -16,7 +16,7 @@ rules: - list - watch - apiGroups: - - storage.gobackup.io + - gobackup.io resources: - s3s/status verbs: diff --git a/config/samples/backup_v1_cronbackup.yaml b/config/samples/backup_v1_cronbackup.yaml index 31e5917..b6d1f49 100644 --- a/config/samples/backup_v1_cronbackup.yaml +++ b/config/samples/backup_v1_cronbackup.yaml @@ -16,12 +16,12 @@ backupModelRef: # every: "day" # at: "00:00" storageRefs: - - apiGroup: "storage.gobackup.io" + - apiGroup: "gobackup.io" type: "S3" name: "example-s3" keep: 5 timeout: 30 databaseRefs: - - apiGroup: "database.gobackup.io" + - apiGroup: "gobackup.io" type: "MySQL" name: "example-mysql" \ No newline at end of file diff --git a/config/samples/crd.yaml b/config/samples/crd.yaml index 6ce76d8..efd785e 100644 --- a/config/samples/crd.yaml +++ b/config/samples/crd.yaml @@ -89,9 +89,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: scps.storage.gobackup.io + name: scps.gobackup.io spec: - group: storage.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -143,9 +143,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: ftpes.storage.gobackup.io + name: ftpes.gobackup.io spec: - group: storage.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -190,9 +190,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: sftpes.storage.gobackup.io + name: sftpes.gobackup.io spec: - group: storage.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -237,9 +237,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: s3s.storage.gobackup.io + name: s3s.gobackup.io spec: - group: storage.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -286,9 +286,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: azures.storage.gobackup.io + name: azures.gobackup.io spec: - group: storage.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -326,9 +326,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: gcses.storage.gobackup.io + name: gcses.gobackup.io spec: - group: storage.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -362,9 +362,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: webdavs.storage.gobackup.io + name: webdavs.gobackup.io spec: - group: storage.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -396,9 +396,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: etcds.database.gobackup.io + name: etcds.gobackup.io spec: - group: database.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -430,9 +430,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: influxdbs.database.gobackup.io + name: influxdbs.gobackup.io spec: - group: database.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -475,9 +475,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: mariadbs.database.gobackup.io + name: mariadbs.gobackup.io spec: - group: database.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -517,9 +517,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: mongodbs.database.gobackup.io + name: mongodbs.gobackup.io spec: - group: database.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -568,9 +568,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: mssqls.database.gobackup.io + name: mssqls.gobackup.io spec: - group: database.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -613,9 +613,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: mysqls.database.gobackup.io + name: mysqls.gobackup.io spec: - group: database.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -663,9 +663,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: postgresqls.database.gobackup.io + name: postgresqls.gobackup.io spec: - group: database.gobackup.io + group: gobackup.io versions: - name: v1 served: true @@ -715,9 +715,9 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: redises.database.gobackup.io + name: redises.gobackup.io spec: - group: database.gobackup.io + group: gobackup.io versions: - name: v1 served: true diff --git a/config/samples/database_v1_postgresql.yaml b/config/samples/database_v1_postgresql.yaml index 9926a6e..c7a3b18 100644 --- a/config/samples/database_v1_postgresql.yaml +++ b/config/samples/database_v1_postgresql.yaml @@ -1,4 +1,4 @@ -apiVersion: database.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: PostgreSQL metadata: labels: diff --git a/config/samples/example.yaml b/config/samples/example.yaml index 6c2e1b0..b7c8251 100644 --- a/config/samples/example.yaml +++ b/config/samples/example.yaml @@ -18,7 +18,7 @@ spec: beforeScript: "echo 'Starting backup'" afterScript: "echo 'Backup completed'" --- -apiVersion: storage.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: SCP metadata: name: example-scp @@ -32,7 +32,7 @@ spec: username: "test" password: "testpassword" --- -apiVersion: storage.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: FTP metadata: name: example-ftp @@ -48,7 +48,7 @@ spec: explicitTLS: false noCheckCertificate: false --- -apiVersion: storage.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: SFTP metadata: name: example-sftp @@ -62,7 +62,7 @@ spec: username: "your-username" # password: "your-password" --- -apiVersion: storage.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: S3 metadata: name: example-s3 @@ -77,7 +77,7 @@ spec: forcePathStyle: false endpoint: "s3.amazonaws.com" --- -apiVersion: storage.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: Azure metadata: name: example-azure @@ -89,7 +89,7 @@ spec: clientID: "your-client-id" clientSecret: "your-client-secret" --- -apiVersion: storage.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: GCS metadata: name: example-gcs @@ -100,7 +100,7 @@ spec: # credentials: "your-credentials" credentialsSecret: "your-credentials-secret" --- -apiVersion: storage.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: WebDAV metadata: name: example-webdav @@ -110,7 +110,7 @@ spec: username: "your-username" password: "your-password" --- -apiVersion: database.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: ETCD metadata: name: example-etcd @@ -123,7 +123,7 @@ spec: - "--username=myuser" - "--password=mypassword" --- -apiVersion: database.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: InfluxDB metadata: name: example-influxdb @@ -138,7 +138,7 @@ spec: skipVerify: false httpDebug: false --- -apiVersion: database.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: MariaDB metadata: name: example-mariadb @@ -151,7 +151,7 @@ spec: database: "your-database" additionalOptions: "your-additional-options" --- -apiVersion: database.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: MongoDB metadata: name: example-mongodb @@ -169,7 +169,7 @@ spec: oplog: false additionalOptions: "your-additional-options" --- -apiVersion: database.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: MSSQL metadata: name: example-mssql @@ -183,7 +183,7 @@ spec: trustServerCertificate: false additionalOptions: "your-additional-options" --- -apiVersion: database.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: MySQL metadata: name: example-mysql @@ -202,7 +202,7 @@ spec: - "table4" additionalOptions: "your-additional-options" --- -apiVersion: database.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: PostgreSQL metadata: name: example-postgresql @@ -221,7 +221,7 @@ spec: - "table4" additionalOptions: "your-additional-options" --- -apiVersion: database.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: Redis metadata: name: example-redis @@ -243,13 +243,13 @@ backupModelRef: # every: "day" # at: "00:00" storageRefs: - - apiGroup: "storage.gobackup.io" + - apiGroup: "gobackup.io" type: "S3" name: "example-s3" keep: 5 timeout: 30 databaseRefs: - - apiGroup: "database.gobackup.io" + - apiGroup: "gobackup.io" type: "MySQL" name: "example-mysql" --- @@ -261,13 +261,13 @@ metadata: backupModelRef: name: "your-backup-model" storageRefs: - - apiGroup: "storage.gobackup.io" + - apiGroup: "gobackup.io" type: "S3" name: "example-s3" keep: 5 timeout: 30 databaseRefs: - - apiGroup: "database.gobackup.io" + - apiGroup: "gobackup.io" type: "MySQL" name: "example-mysql" diff --git a/config/samples/storage_v1_s3.yaml b/config/samples/storage_v1_s3.yaml index 44e86a1..76ebb38 100644 --- a/config/samples/storage_v1_s3.yaml +++ b/config/samples/storage_v1_s3.yaml @@ -1,4 +1,4 @@ -apiVersion: storage.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: S3 metadata: labels: diff --git a/example/database/postgresql.yaml b/example/database/postgresql.yaml index f5f526e..ff79034 100644 --- a/example/database/postgresql.yaml +++ b/example/database/postgresql.yaml @@ -1,4 +1,4 @@ -apiVersion: database.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: PostgreSQL metadata: name: example-postgresql diff --git a/example/gobackup-opetator/backup.yaml b/example/gobackup-opetator/backup.yaml index 8c8c0ba..7bbbd91 100644 --- a/example/gobackup-opetator/backup.yaml +++ b/example/gobackup-opetator/backup.yaml @@ -6,12 +6,12 @@ metadata: backupModelRef: name: "example-backupmodel" storageRefs: - - apiGroup: "storage.gobackup.io" + - apiGroup: "gobackup.io" type: "S3" name: "example-s3" keep: 5 timeout: 30 databaseRefs: - - apiGroup: "database.gobackup.io" + - apiGroup: "gobackup.io" type: "PostgreSQL" name: "example-postgresql" \ No newline at end of file diff --git a/example/gobackup-opetator/cronbackup.yaml b/example/gobackup-opetator/cronbackup.yaml index 9d243f7..445bf6b 100644 --- a/example/gobackup-opetator/cronbackup.yaml +++ b/example/gobackup-opetator/cronbackup.yaml @@ -8,12 +8,12 @@ backupModelRef: schedule: cron: "* * * * *" storageRefs: - - apiGroup: "storage.gobackup.io" + - apiGroup: "gobackup.io" type: "S3" name: "example-s3" keep: 5 timeout: 30 databaseRefs: - - apiGroup: "database.gobackup.io" + - apiGroup: "gobackup.io" type: "PostgreSQL" name: "example-postgresql" \ No newline at end of file diff --git a/example/storage/s3.yaml b/example/storage/s3.yaml index fec0e9c..d334aac 100644 --- a/example/storage/s3.yaml +++ b/example/storage/s3.yaml @@ -1,4 +1,4 @@ -apiVersion: storage.gobackup.io/v1 +apiVersion: gobackup.io/v1 kind: S3 metadata: name: example-s3 From a32b17bc2ffe9506b606802b9ab22e896cc5b8f2 Mon Sep 17 00:00:00 2001 From: Payam Qorbanpour Date: Wed, 16 Oct 2024 15:48:17 +0330 Subject: [PATCH 2/3] Add test commit --- internal/controller/backup_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controller/backup_controller.go b/internal/controller/backup_controller.go index b385993..5707eb0 100644 --- a/internal/controller/backup_controller.go +++ b/internal/controller/backup_controller.go @@ -74,7 +74,7 @@ func (r *BackupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr } // Ensure Storage and Database CRDs existence - // TODO: Extend this by checking every storage and database + // TODO: Extend this by checking every storage and database.. if len(backup.StorageRefs) == 0 || len(backup.DatabaseRefs) == 0 { return ctrl.Result{}, client.IgnoreNotFound(nil) } From 663f354731590cf02dcffe4727505c301ccd5bce Mon Sep 17 00:00:00 2001 From: Payam Qorbanpour Date: Wed, 16 Oct 2024 16:28:45 +0330 Subject: [PATCH 3/3] Modify code to remove database and storage from crds apigroups --- api/database/v1/groupversion_info.go | 36 --- api/database/v1/zz_generated.deepcopy.go | 149 ------------ api/storage/v1/groupversion_info.go | 36 --- api/storage/v1/zz_generated.deepcopy.go | 129 ---------- api/{database => }/v1/postgresql_types.go | 0 api/{storage => }/v1/s3_types.go | 0 api/v1/zz_generated.deepcopy.go | 230 ++++++++++++++++++ cmd/main.go | 20 -- config/rbac/role.yaml | 52 ---- .../database/postgresql_controller.go | 62 ----- .../database/postgresql_controller_test.go | 84 ------- internal/controller/database/suite_test.go | 90 ------- internal/controller/storage/s3_controller.go | 62 ----- .../controller/storage/s3_controller_test.go | 84 ------- internal/controller/storage/suite_test.go | 90 ------- pkg/k8sutil/secret.go | 14 +- 16 files changed, 236 insertions(+), 902 deletions(-) delete mode 100644 api/database/v1/groupversion_info.go delete mode 100644 api/database/v1/zz_generated.deepcopy.go delete mode 100644 api/storage/v1/groupversion_info.go delete mode 100644 api/storage/v1/zz_generated.deepcopy.go rename api/{database => }/v1/postgresql_types.go (100%) rename api/{storage => }/v1/s3_types.go (100%) delete mode 100644 internal/controller/database/postgresql_controller.go delete mode 100644 internal/controller/database/postgresql_controller_test.go delete mode 100644 internal/controller/database/suite_test.go delete mode 100644 internal/controller/storage/s3_controller.go delete mode 100644 internal/controller/storage/s3_controller_test.go delete mode 100644 internal/controller/storage/suite_test.go diff --git a/api/database/v1/groupversion_info.go b/api/database/v1/groupversion_info.go deleted file mode 100644 index d59c470..0000000 --- a/api/database/v1/groupversion_info.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package v1 contains API Schema definitions for the database v1 API group -// +kubebuilder:object:generate=true -// +groupName=database.gobackup.io -package v1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/scheme" -) - -var ( - // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "database.gobackup.io", Version: "v1"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} - - // AddToScheme adds the types in this group-version to the given scheme. - AddToScheme = SchemeBuilder.AddToScheme -) diff --git a/api/database/v1/zz_generated.deepcopy.go b/api/database/v1/zz_generated.deepcopy.go deleted file mode 100644 index 376ffec..0000000 --- a/api/database/v1/zz_generated.deepcopy.go +++ /dev/null @@ -1,149 +0,0 @@ -//go:build !ignore_autogenerated - -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PostgreSQL) DeepCopyInto(out *PostgreSQL) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostgreSQL. -func (in *PostgreSQL) DeepCopy() *PostgreSQL { - if in == nil { - return nil - } - out := new(PostgreSQL) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *PostgreSQL) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PostgreSQLList) DeepCopyInto(out *PostgreSQLList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]PostgreSQL, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostgreSQLList. -func (in *PostgreSQLList) DeepCopy() *PostgreSQLList { - if in == nil { - return nil - } - out := new(PostgreSQLList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *PostgreSQLList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PostgreSQLSpec) DeepCopyInto(out *PostgreSQLSpec) { - *out = *in - if in.Tables != nil { - in, out := &in.Tables, &out.Tables - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.ExcludeTables != nil { - in, out := &in.ExcludeTables, &out.ExcludeTables - *out = make([]string, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostgreSQLSpec. -func (in *PostgreSQLSpec) DeepCopy() *PostgreSQLSpec { - if in == nil { - return nil - } - out := new(PostgreSQLSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PostgreSQLSpecConfig) DeepCopyInto(out *PostgreSQLSpecConfig) { - *out = *in - if in.Tables != nil { - in, out := &in.Tables, &out.Tables - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.ExcludeTables != nil { - in, out := &in.ExcludeTables, &out.ExcludeTables - *out = make([]string, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostgreSQLSpecConfig. -func (in *PostgreSQLSpecConfig) DeepCopy() *PostgreSQLSpecConfig { - if in == nil { - return nil - } - out := new(PostgreSQLSpecConfig) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PostgreSQLStatus) DeepCopyInto(out *PostgreSQLStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostgreSQLStatus. -func (in *PostgreSQLStatus) DeepCopy() *PostgreSQLStatus { - if in == nil { - return nil - } - out := new(PostgreSQLStatus) - in.DeepCopyInto(out) - return out -} diff --git a/api/storage/v1/groupversion_info.go b/api/storage/v1/groupversion_info.go deleted file mode 100644 index d87aded..0000000 --- a/api/storage/v1/groupversion_info.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package v1 contains API Schema definitions for the storage v1 API group -// +kubebuilder:object:generate=true -// +groupName=storage.gobackup.io -package v1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/scheme" -) - -var ( - // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "storage.gobackup.io", Version: "v1"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} - - // AddToScheme adds the types in this group-version to the given scheme. - AddToScheme = SchemeBuilder.AddToScheme -) diff --git a/api/storage/v1/zz_generated.deepcopy.go b/api/storage/v1/zz_generated.deepcopy.go deleted file mode 100644 index 0ce8b9f..0000000 --- a/api/storage/v1/zz_generated.deepcopy.go +++ /dev/null @@ -1,129 +0,0 @@ -//go:build !ignore_autogenerated - -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *S3) DeepCopyInto(out *S3) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3. -func (in *S3) DeepCopy() *S3 { - if in == nil { - return nil - } - out := new(S3) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *S3) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *S3List) DeepCopyInto(out *S3List) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]S3, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3List. -func (in *S3List) DeepCopy() *S3List { - if in == nil { - return nil - } - out := new(S3List) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *S3List) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *S3Spec) DeepCopyInto(out *S3Spec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3Spec. -func (in *S3Spec) DeepCopy() *S3Spec { - if in == nil { - return nil - } - out := new(S3Spec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *S3SpecConfig) DeepCopyInto(out *S3SpecConfig) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3SpecConfig. -func (in *S3SpecConfig) DeepCopy() *S3SpecConfig { - if in == nil { - return nil - } - out := new(S3SpecConfig) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *S3Status) DeepCopyInto(out *S3Status) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3Status. -func (in *S3Status) DeepCopy() *S3Status { - if in == nil { - return nil - } - out := new(S3Status) - in.DeepCopyInto(out) - return out -} diff --git a/api/database/v1/postgresql_types.go b/api/v1/postgresql_types.go similarity index 100% rename from api/database/v1/postgresql_types.go rename to api/v1/postgresql_types.go diff --git a/api/storage/v1/s3_types.go b/api/v1/s3_types.go similarity index 100% rename from api/storage/v1/s3_types.go rename to api/v1/s3_types.go diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 4e60e6b..ede216a 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -428,3 +428,233 @@ func (in *StorageRef) DeepCopy() *StorageRef { in.DeepCopyInto(out) return out } + + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PostgreSQL) DeepCopyInto(out *PostgreSQL) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostgreSQL. +func (in *PostgreSQL) DeepCopy() *PostgreSQL { + if in == nil { + return nil + } + out := new(PostgreSQL) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PostgreSQL) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PostgreSQLList) DeepCopyInto(out *PostgreSQLList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]PostgreSQL, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostgreSQLList. +func (in *PostgreSQLList) DeepCopy() *PostgreSQLList { + if in == nil { + return nil + } + out := new(PostgreSQLList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PostgreSQLList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PostgreSQLSpec) DeepCopyInto(out *PostgreSQLSpec) { + *out = *in + if in.Tables != nil { + in, out := &in.Tables, &out.Tables + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.ExcludeTables != nil { + in, out := &in.ExcludeTables, &out.ExcludeTables + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostgreSQLSpec. +func (in *PostgreSQLSpec) DeepCopy() *PostgreSQLSpec { + if in == nil { + return nil + } + out := new(PostgreSQLSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PostgreSQLSpecConfig) DeepCopyInto(out *PostgreSQLSpecConfig) { + *out = *in + if in.Tables != nil { + in, out := &in.Tables, &out.Tables + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.ExcludeTables != nil { + in, out := &in.ExcludeTables, &out.ExcludeTables + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostgreSQLSpecConfig. +func (in *PostgreSQLSpecConfig) DeepCopy() *PostgreSQLSpecConfig { + if in == nil { + return nil + } + out := new(PostgreSQLSpecConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PostgreSQLStatus) DeepCopyInto(out *PostgreSQLStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostgreSQLStatus. +func (in *PostgreSQLStatus) DeepCopy() *PostgreSQLStatus { + if in == nil { + return nil + } + out := new(PostgreSQLStatus) + in.DeepCopyInto(out) + return out +} + + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *S3) DeepCopyInto(out *S3) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3. +func (in *S3) DeepCopy() *S3 { + if in == nil { + return nil + } + out := new(S3) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *S3) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *S3List) DeepCopyInto(out *S3List) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]S3, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3List. +func (in *S3List) DeepCopy() *S3List { + if in == nil { + return nil + } + out := new(S3List) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *S3List) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *S3Spec) DeepCopyInto(out *S3Spec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3Spec. +func (in *S3Spec) DeepCopy() *S3Spec { + if in == nil { + return nil + } + out := new(S3Spec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *S3SpecConfig) DeepCopyInto(out *S3SpecConfig) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3SpecConfig. +func (in *S3SpecConfig) DeepCopy() *S3SpecConfig { + if in == nil { + return nil + } + out := new(S3SpecConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *S3Status) DeepCopyInto(out *S3Status) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3Status. +func (in *S3Status) DeepCopy() *S3Status { + if in == nil { + return nil + } + out := new(S3Status) + in.DeepCopyInto(out) + return out +} diff --git a/cmd/main.go b/cmd/main.go index 9da0024..af17718 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -33,12 +33,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" - databasev1 "github.com/gobackup/gobackup-operator/api/database/v1" - storagev1 "github.com/gobackup/gobackup-operator/api/storage/v1" backupv1 "github.com/gobackup/gobackup-operator/api/v1" "github.com/gobackup/gobackup-operator/internal/controller" - databasecontroller "github.com/gobackup/gobackup-operator/internal/controller/database" - storagecontroller "github.com/gobackup/gobackup-operator/internal/controller/storage" "github.com/gobackup/gobackup-operator/pkg/k8sutil" //+kubebuilder:scaffold:imports ) @@ -52,8 +48,6 @@ func init() { utilruntime.Must(clientgoscheme.AddToScheme(scheme)) utilruntime.Must(backupv1.AddToScheme(scheme)) - utilruntime.Must(databasev1.AddToScheme(scheme)) - utilruntime.Must(storagev1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme } @@ -138,20 +132,6 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "Backup") os.Exit(1) } - if err = (&databasecontroller.PostgreSQLReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "PostgreSQL") - os.Exit(1) - } - if err = (&storagecontroller.S3Reconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "S3") - os.Exit(1) - } //+kubebuilder:scaffold:builder if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index cc56b33..9add7fb 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -4,32 +4,6 @@ kind: ClusterRole metadata: name: manager-role rules: -- apiGroups: - - gobackup.io - resources: - - postgresqls - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - gobackup.io - resources: - - postgresqls/finalizers - verbs: - - update -- apiGroups: - - gobackup.io - resources: - - postgresqls/status - verbs: - - get - - patch - - update - apiGroups: - gobackup.io resources: @@ -56,29 +30,3 @@ rules: - get - patch - update -- apiGroups: - - gobackup.io - resources: - - s3s - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - gobackup.io - resources: - - s3s/finalizers - verbs: - - update -- apiGroups: - - gobackup.io - resources: - - s3s/status - verbs: - - get - - patch - - update diff --git a/internal/controller/database/postgresql_controller.go b/internal/controller/database/postgresql_controller.go deleted file mode 100644 index 9c68bd2..0000000 --- a/internal/controller/database/postgresql_controller.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package database - -import ( - "context" - - "k8s.io/apimachinery/pkg/runtime" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/log" - - databasev1 "github.com/gobackup/gobackup-operator/api/database/v1" -) - -// PostgreSQLReconciler reconciles a PostgreSQL object -type PostgreSQLReconciler struct { - client.Client - Scheme *runtime.Scheme -} - -// +kubebuilder:rbac:groups=database.gobackup.io,resources=postgresqls,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=database.gobackup.io,resources=postgresqls/status,verbs=get;update;patch -// +kubebuilder:rbac:groups=database.gobackup.io,resources=postgresqls/finalizers,verbs=update - -// Reconcile is part of the main kubernetes reconciliation loop which aims to -// move the current state of the cluster closer to the desired state. -// TODO(user): Modify the Reconcile function to compare the state specified by -// the PostgreSQL object against the actual cluster state, and then -// perform operations to make the cluster state reflect the state specified by -// the user. -// -// For more details, check Reconcile and its Result here: -// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.18.2/pkg/reconcile -func (r *PostgreSQLReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - _ = log.FromContext(ctx) - - // TODO(user): your logic here - - return ctrl.Result{}, nil -} - -// SetupWithManager sets up the controller with the Manager. -func (r *PostgreSQLReconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr). - For(&databasev1.PostgreSQL{}). - Complete(r) -} diff --git a/internal/controller/database/postgresql_controller_test.go b/internal/controller/database/postgresql_controller_test.go deleted file mode 100644 index 72d88a1..0000000 --- a/internal/controller/database/postgresql_controller_test.go +++ /dev/null @@ -1,84 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package database - -import ( - "context" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - databasev1 "github.com/gobackup/gobackup-operator/api/database/v1" -) - -var _ = Describe("PostgreSQL Controller", func() { - Context("When reconciling a resource", func() { - const resourceName = "test-resource" - - ctx := context.Background() - - typeNamespacedName := types.NamespacedName{ - Name: resourceName, - Namespace: "default", // TODO(user):Modify as needed - } - postgresql := &databasev1.PostgreSQL{} - - BeforeEach(func() { - By("creating the custom resource for the Kind PostgreSQL") - err := k8sClient.Get(ctx, typeNamespacedName, postgresql) - if err != nil && errors.IsNotFound(err) { - resource := &databasev1.PostgreSQL{ - ObjectMeta: metav1.ObjectMeta{ - Name: resourceName, - Namespace: "default", - }, - // TODO(user): Specify other spec details if needed. - } - Expect(k8sClient.Create(ctx, resource)).To(Succeed()) - } - }) - - AfterEach(func() { - // TODO(user): Cleanup logic after each test, like removing the resource instance. - resource := &databasev1.PostgreSQL{} - err := k8sClient.Get(ctx, typeNamespacedName, resource) - Expect(err).NotTo(HaveOccurred()) - - By("Cleanup the specific resource instance PostgreSQL") - Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) - }) - It("should successfully reconcile the resource", func() { - By("Reconciling the created resource") - controllerReconciler := &PostgreSQLReconciler{ - Client: k8sClient, - Scheme: k8sClient.Scheme(), - } - - _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ - NamespacedName: typeNamespacedName, - }) - Expect(err).NotTo(HaveOccurred()) - // TODO(user): Add more specific assertions depending on your controller's reconciliation logic. - // Example: If you expect a certain status condition after reconciliation, verify it here. - }) - }) -}) diff --git a/internal/controller/database/suite_test.go b/internal/controller/database/suite_test.go deleted file mode 100644 index 677f1a3..0000000 --- a/internal/controller/database/suite_test.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package database - -import ( - "fmt" - "path/filepath" - "runtime" - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/log/zap" - - databasev1 "github.com/gobackup/gobackup-operator/api/database/v1" - // +kubebuilder:scaffold:imports -) - -// These tests use Ginkgo (BDD-style Go testing framework). Refer to -// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. - -var cfg *rest.Config -var k8sClient client.Client -var testEnv *envtest.Environment - -func TestControllers(t *testing.T) { - RegisterFailHandler(Fail) - - RunSpecs(t, "Controller Suite") -} - -var _ = BeforeSuite(func() { - logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) - - By("bootstrapping test environment") - testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, - ErrorIfCRDPathMissing: true, - - // The BinaryAssetsDirectory is only required if you want to run the tests directly - // without call the makefile target test. If not informed it will look for the - // default path defined in controller-runtime which is /usr/local/kubebuilder/. - // Note that you must have the required binaries setup under the bin directory to perform - // the tests directly. When we run make test it will be setup and used automatically. - BinaryAssetsDirectory: filepath.Join("..", "..", "..", "bin", "k8s", - fmt.Sprintf("1.30.0-%s-%s", runtime.GOOS, runtime.GOARCH)), - } - - var err error - // cfg is defined in this file globally. - cfg, err = testEnv.Start() - Expect(err).NotTo(HaveOccurred()) - Expect(cfg).NotTo(BeNil()) - - err = databasev1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) - Expect(err).NotTo(HaveOccurred()) - Expect(k8sClient).NotTo(BeNil()) - -}) - -var _ = AfterSuite(func() { - By("tearing down the test environment") - err := testEnv.Stop() - Expect(err).NotTo(HaveOccurred()) -}) diff --git a/internal/controller/storage/s3_controller.go b/internal/controller/storage/s3_controller.go deleted file mode 100644 index 4ee7b8a..0000000 --- a/internal/controller/storage/s3_controller.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package storage - -import ( - "context" - - "k8s.io/apimachinery/pkg/runtime" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/log" - - storagev1 "github.com/gobackup/gobackup-operator/api/storage/v1" -) - -// S3Reconciler reconciles a S3 object -type S3Reconciler struct { - client.Client - Scheme *runtime.Scheme -} - -// +kubebuilder:rbac:groups=storage.gobackup.io,resources=s3s,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=storage.gobackup.io,resources=s3s/status,verbs=get;update;patch -// +kubebuilder:rbac:groups=storage.gobackup.io,resources=s3s/finalizers,verbs=update - -// Reconcile is part of the main kubernetes reconciliation loop which aims to -// move the current state of the cluster closer to the desired state. -// TODO(user): Modify the Reconcile function to compare the state specified by -// the S3 object against the actual cluster state, and then -// perform operations to make the cluster state reflect the state specified by -// the user. -// -// For more details, check Reconcile and its Result here: -// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.18.2/pkg/reconcile -func (r *S3Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - _ = log.FromContext(ctx) - - // TODO(user): your logic here - - return ctrl.Result{}, nil -} - -// SetupWithManager sets up the controller with the Manager. -func (r *S3Reconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr). - For(&storagev1.S3{}). - Complete(r) -} diff --git a/internal/controller/storage/s3_controller_test.go b/internal/controller/storage/s3_controller_test.go deleted file mode 100644 index 07530a9..0000000 --- a/internal/controller/storage/s3_controller_test.go +++ /dev/null @@ -1,84 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package storage - -import ( - "context" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - storagev1 "github.com/gobackup/gobackup-operator/api/storage/v1" -) - -var _ = Describe("S3 Controller", func() { - Context("When reconciling a resource", func() { - const resourceName = "test-resource" - - ctx := context.Background() - - typeNamespacedName := types.NamespacedName{ - Name: resourceName, - Namespace: "default", // TODO(user):Modify as needed - } - s3 := &storagev1.S3{} - - BeforeEach(func() { - By("creating the custom resource for the Kind S3") - err := k8sClient.Get(ctx, typeNamespacedName, s3) - if err != nil && errors.IsNotFound(err) { - resource := &storagev1.S3{ - ObjectMeta: metav1.ObjectMeta{ - Name: resourceName, - Namespace: "default", - }, - // TODO(user): Specify other spec details if needed. - } - Expect(k8sClient.Create(ctx, resource)).To(Succeed()) - } - }) - - AfterEach(func() { - // TODO(user): Cleanup logic after each test, like removing the resource instance. - resource := &storagev1.S3{} - err := k8sClient.Get(ctx, typeNamespacedName, resource) - Expect(err).NotTo(HaveOccurred()) - - By("Cleanup the specific resource instance S3") - Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) - }) - It("should successfully reconcile the resource", func() { - By("Reconciling the created resource") - controllerReconciler := &S3Reconciler{ - Client: k8sClient, - Scheme: k8sClient.Scheme(), - } - - _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ - NamespacedName: typeNamespacedName, - }) - Expect(err).NotTo(HaveOccurred()) - // TODO(user): Add more specific assertions depending on your controller's reconciliation logic. - // Example: If you expect a certain status condition after reconciliation, verify it here. - }) - }) -}) diff --git a/internal/controller/storage/suite_test.go b/internal/controller/storage/suite_test.go deleted file mode 100644 index dcb861b..0000000 --- a/internal/controller/storage/suite_test.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package storage - -import ( - "fmt" - "path/filepath" - "runtime" - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/log/zap" - - storagev1 "github.com/gobackup/gobackup-operator/api/storage/v1" - // +kubebuilder:scaffold:imports -) - -// These tests use Ginkgo (BDD-style Go testing framework). Refer to -// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. - -var cfg *rest.Config -var k8sClient client.Client -var testEnv *envtest.Environment - -func TestControllers(t *testing.T) { - RegisterFailHandler(Fail) - - RunSpecs(t, "Controller Suite") -} - -var _ = BeforeSuite(func() { - logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) - - By("bootstrapping test environment") - testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, - ErrorIfCRDPathMissing: true, - - // The BinaryAssetsDirectory is only required if you want to run the tests directly - // without call the makefile target test. If not informed it will look for the - // default path defined in controller-runtime which is /usr/local/kubebuilder/. - // Note that you must have the required binaries setup under the bin directory to perform - // the tests directly. When we run make test it will be setup and used automatically. - BinaryAssetsDirectory: filepath.Join("..", "..", "..", "bin", "k8s", - fmt.Sprintf("1.30.0-%s-%s", runtime.GOOS, runtime.GOARCH)), - } - - var err error - // cfg is defined in this file globally. - cfg, err = testEnv.Start() - Expect(err).NotTo(HaveOccurred()) - Expect(cfg).NotTo(BeNil()) - - err = storagev1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) - Expect(err).NotTo(HaveOccurred()) - Expect(k8sClient).NotTo(BeNil()) - -}) - -var _ = AfterSuite(func() { - By("tearing down the test environment") - err := testEnv.Stop() - Expect(err).NotTo(HaveOccurred()) -}) diff --git a/pkg/k8sutil/secret.go b/pkg/k8sutil/secret.go index 342f20c..b2bd348 100644 --- a/pkg/k8sutil/secret.go +++ b/pkg/k8sutil/secret.go @@ -10,8 +10,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - databasev1 "github.com/gobackup/gobackup-operator/api/database/v1" - storagev1 "github.com/gobackup/gobackup-operator/api/storage/v1" backupv1 "github.com/gobackup/gobackup-operator/api/v1" ) @@ -35,18 +33,18 @@ type MyBackup struct { // Databases represents the database configurations type Databases struct { - Postgres databasev1.PostgreSQLSpecConfig `yaml:"postgres"` + Postgres backupv1.PostgreSQLSpecConfig `yaml:"postgres"` } // Storages represents the storage configurations type Storages struct { - S3 storagev1.S3SpecConfig `yaml:"s3"` + S3 backupv1.S3SpecConfig `yaml:"s3"` } // CreateSecret creates secret from config. func (k *K8s) CreateSecret(ctx context.Context, model backupv1.Model, namespace, name string) error { - var postgreSQLSpec databasev1.PostgreSQLSpec - var s3Spec storagev1.S3Spec + var postgreSQLSpec backupv1.PostgreSQLSpec + var s3Spec backupv1.S3Spec for _, database := range model.DatabaseRefs { version := strings.ToLower(database.Type) + "s" @@ -92,10 +90,10 @@ func (k *K8s) CreateSecret(ctx context.Context, model backupv1.Model, namespace, Models: Models{ MyBackup: MyBackup{ Databases: Databases{ - databasev1.PostgreSQLSpecConfig(postgreSQLSpec), + backupv1.PostgreSQLSpecConfig(postgreSQLSpec), }, Storages: Storages{ - storagev1.S3SpecConfig(s3Spec), + backupv1.S3SpecConfig(s3Spec), }, }, },