From ed9105de879f770cc3d7484a8130386b7301516e Mon Sep 17 00:00:00 2001 From: Leonardo Cecchi Date: Mon, 23 Dec 2024 10:46:12 +0100 Subject: [PATCH] chore: remove ExternalClusterList type (#6426) Our documentation generator is not able to handle that type alias, so let's get rid of it. Closes: #6427 Signed-off-by: Leonardo Cecchi Signed-off-by: Marco Nenciarini Co-authored-by: Marco Nenciarini --- .wordlist-en-custom.txt | 1 - api/v1/cluster_funcs.go | 8 +- api/v1/cluster_types.go | 5 +- api/v1/zz_generated.deepcopy.go | 23 +----- docs/config.yaml | 2 +- docs/src/cloudnative-pg.v1.md | 81 +++++++++++++++++-- internal/cmd/manager/walrestore/cmd.go | 5 +- internal/controller/cluster_controller.go | 5 +- .../subscription_controller_test.go | 4 +- 9 files changed, 93 insertions(+), 41 deletions(-) diff --git a/.wordlist-en-custom.txt b/.wordlist-en-custom.txt index 42d7a6fa5b..47260d5468 100644 --- a/.wordlist-en-custom.txt +++ b/.wordlist-en-custom.txt @@ -155,7 +155,6 @@ EphemeralVolumeSource EphemeralVolumesSizeLimit EphemeralVolumesSizeLimitConfiguration ExternalCluster -ExternalClusterList FQDN Fei Filesystem diff --git a/api/v1/cluster_funcs.go b/api/v1/cluster_funcs.go index 3ffba1a3da..b0345cdc16 100644 --- a/api/v1/cluster_funcs.go +++ b/api/v1/cluster_funcs.go @@ -82,13 +82,13 @@ func (pluginList PluginConfigurationList) GetEnabledPluginNames() (result []stri return pluginNames } -// GetEnabledPluginNames gets the name of the plugins that are +// GetExternalClustersEnabledPluginNames gets the name of the plugins that are // involved in the reconciliation of this external cluster list. This // list is usually composed by the plugins that need to be active to // recover data from the external clusters. -func (externalClusterList ExternalClusterList) GetEnabledPluginNames() (result []string) { - pluginNames := make([]string, 0, len(externalClusterList)) - for _, externalCluster := range externalClusterList { +func GetExternalClustersEnabledPluginNames(externalClusters []ExternalCluster) (result []string) { + pluginNames := make([]string, 0, len(externalClusters)) + for _, externalCluster := range externalClusters { if externalCluster.PluginConfiguration != nil { pluginNames = append(pluginNames, externalCluster.PluginConfiguration.Name) } diff --git a/api/v1/cluster_types.go b/api/v1/cluster_types.go index 2814f18cb6..ae6e6a181e 100644 --- a/api/v1/cluster_types.go +++ b/api/v1/cluster_types.go @@ -422,7 +422,7 @@ type ClusterSpec struct { // The list of external clusters which are used in the configuration // +optional - ExternalClusters ExternalClusterList `json:"externalClusters,omitempty"` + ExternalClusters []ExternalCluster `json:"externalClusters,omitempty"` // The instances' log level, one of the following values: error, warning, info (default), debug, trace // +kubebuilder:default:=info @@ -2060,9 +2060,6 @@ type ClusterMonitoringTLSConfiguration struct { Enabled bool `json:"enabled,omitempty"` } -// ExternalClusterList is a list of external clusters -type ExternalClusterList []ExternalCluster - // ExternalCluster represents the connection parameters to an // external cluster which is used in the other sections of the configuration type ExternalCluster struct { diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index fbaec944e2..8c6a2a71e6 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -790,7 +790,7 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) { } if in.ExternalClusters != nil { in, out := &in.ExternalClusters, &out.ExternalClusters - *out = make(ExternalClusterList, len(*in)) + *out = make([]ExternalCluster, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -1258,27 +1258,6 @@ func (in *ExternalCluster) DeepCopy() *ExternalCluster { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in ExternalClusterList) DeepCopyInto(out *ExternalClusterList) { - { - in := &in - *out = make(ExternalClusterList, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalClusterList. -func (in ExternalClusterList) DeepCopy() ExternalClusterList { - if in == nil { - return nil - } - out := new(ExternalClusterList) - in.DeepCopyInto(out) - return *out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ImageCatalog) DeepCopyInto(out *ImageCatalog) { *out = *in diff --git a/docs/config.yaml b/docs/config.yaml index 7b260f3bc8..9717ffa456 100644 --- a/docs/config.yaml +++ b/docs/config.yaml @@ -32,7 +32,7 @@ externalPackages: hideTypePatterns: - "ParseError$" - # We cannot exclude all `List$` because we declare PluginConfigurationList and ExternalClusterList + # We cannot exclude all `List$` because we declare PluginConfigurationList - "\\.BackupList$" - "\\.ClusterList$" - "\\.ClusterImageCatalogList$" diff --git a/docs/src/cloudnative-pg.v1.md b/docs/src/cloudnative-pg.v1.md index fa9d2c9242..3db291f4cd 100644 --- a/docs/src/cloudnative-pg.v1.md +++ b/docs/src/cloudnative-pg.v1.md @@ -1845,7 +1845,7 @@ it can be with a switchover (switchover) or in-place (restart externalClusters
-ExternalClusterList +[]ExternalCluster

The list of external clusters which are used in the configuration

@@ -2706,19 +2706,89 @@ storage

-## ExternalClusterList {#postgresql-cnpg-io-v1-ExternalClusterList} +## ExternalCluster {#postgresql-cnpg-io-v1-ExternalCluster} -(Alias of `[]github.com/cloudnative-pg/cloudnative-pg/api/v1.ExternalCluster`) **Appears in:** - [ClusterSpec](#postgresql-cnpg-io-v1-ClusterSpec) -

ExternalClusterList is a list of external clusters

- +

ExternalCluster represents the connection parameters to an +external cluster which is used in the other sections of the configuration

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FieldDescription
name [Required]
+string +
+

The server name, required

+
connectionParameters
+map[string]string +
+

The list of connection parameters, such as dbname, host, username, etc

+
sslCert
+core/v1.SecretKeySelector +
+

The reference to an SSL certificate to be used to connect to this +instance

+
sslKey
+core/v1.SecretKeySelector +
+

The reference to an SSL private key to be used to connect to this +instance

+
sslRootCert
+core/v1.SecretKeySelector +
+

The reference to an SSL CA public key to be used to connect to this +instance

+
password
+core/v1.SecretKeySelector +
+

The reference to the password to be used to connect to the server. +If a password is provided, CloudNativePG creates a PostgreSQL +passfile at /controller/external/NAME/pass (where "NAME" is the +cluster's name). This passfile is automatically referenced in the +connection string when establishing a connection to the remote +PostgreSQL server from the current PostgreSQL Cluster. This ensures +secure and efficient password management for external clusters.

+
barmanObjectStore
+github.com/cloudnative-pg/barman-cloud/pkg/api.BarmanObjectStoreConfiguration +
+

The configuration for the barman-cloud tool suite

+
plugin [Required]
+PluginConfiguration +
+

The configuration of the plugin that is taking care +of WAL archiving and backups for this external cluster

+
## ImageCatalogRef {#postgresql-cnpg-io-v1-ImageCatalogRef} @@ -3616,6 +3686,7 @@ the operator calls PgBouncer's PAUSE and RESUME comman **Appears in:** +- [ExternalCluster](#postgresql-cnpg-io-v1-ExternalCluster)

PluginConfiguration specifies a plugin that need to be loaded for this diff --git a/internal/cmd/manager/walrestore/cmd.go b/internal/cmd/manager/walrestore/cmd.go index 4accc2a023..8b1835a271 100644 --- a/internal/cmd/manager/walrestore/cmd.go +++ b/internal/cmd/manager/walrestore/cmd.go @@ -262,7 +262,10 @@ func restoreWALViaPlugins( availablePluginNamesSet := stringset.From(availablePluginNames) enabledPluginNames := cluster.Spec.Plugins.GetEnabledPluginNames() - enabledPluginNames = append(enabledPluginNames, cluster.Spec.ExternalClusters.GetEnabledPluginNames()...) + enabledPluginNames = append( + enabledPluginNames, + apiv1.GetExternalClustersEnabledPluginNames(cluster.Spec.ExternalClusters)..., + ) enabledPluginNamesSet := stringset.From(enabledPluginNames) client, err := pluginClient.WithPlugins( diff --git a/internal/controller/cluster_controller.go b/internal/controller/cluster_controller.go index 6194505985..958f98f1bd 100644 --- a/internal/controller/cluster_controller.go +++ b/internal/controller/cluster_controller.go @@ -176,7 +176,10 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct // Load the plugins required to bootstrap and reconcile this cluster enabledPluginNames := cluster.Spec.Plugins.GetEnabledPluginNames() - enabledPluginNames = append(enabledPluginNames, cluster.Spec.ExternalClusters.GetEnabledPluginNames()...) + enabledPluginNames = append( + enabledPluginNames, + apiv1.GetExternalClustersEnabledPluginNames(cluster.Spec.ExternalClusters)..., + ) pluginLoadingContext, cancelPluginLoading := context.WithTimeout(ctx, 5*time.Second) defer cancelPluginLoading() diff --git a/internal/management/controller/subscription_controller_test.go b/internal/management/controller/subscription_controller_test.go index f6afdc0c4e..f699324805 100644 --- a/internal/management/controller/subscription_controller_test.go +++ b/internal/management/controller/subscription_controller_test.go @@ -69,8 +69,8 @@ var _ = Describe("Managed subscription controller tests", func() { TargetPrimary: "cluster-example-1", }, Spec: apiv1.ClusterSpec{ - ExternalClusters: apiv1.ExternalClusterList{ - apiv1.ExternalCluster{ + ExternalClusters: []apiv1.ExternalCluster{ + { Name: "cluster-other", ConnectionParameters: map[string]string{ "host": "localhost",