Skip to content

Commit a725d1f

Browse files
solidDoWantmnenciaarmru
authored
feat: add kubernetes client-gen tool support (cloudnative-pg#6695)
This patch introduces support for the Kubernetes `client-gen` tool, enabling the automated generation of Go clients for all custom resources defined by the operator's CRDs. Closes cloudnative-pg#6585 Signed-off-by: Fred Heinecke <fred.heinecke@yahoo.com> Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com> Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
1 parent 98e2796 commit a725d1f

File tree

15 files changed

+26
-28
lines changed

15 files changed

+26
-28
lines changed

api/v1/backup_funcs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ func (backup *Backup) GetVolumeSnapshotConfiguration(
236236
// By setting the GVK, we ensure that components such as the plugins have enough metadata to typecheck the object.
237237
func (backup *Backup) EnsureGVKIsPresent() {
238238
backup.SetGroupVersionKind(schema.GroupVersionKind{
239-
Group: GroupVersion.Group,
240-
Version: GroupVersion.Version,
239+
Group: SchemeGroupVersion.Group,
240+
Version: SchemeGroupVersion.Version,
241241
Kind: BackupKind,
242242
})
243243
}

api/v1/cluster_funcs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,8 +1397,8 @@ func (cluster *Cluster) GetRecoverySourcePlugin() *PluginConfiguration {
13971397
// By setting the GVK, we ensure that components such as the plugins have enough metadata to typecheck the object.
13981398
func (cluster *Cluster) EnsureGVKIsPresent() {
13991399
cluster.SetGroupVersionKind(schema.GroupVersionKind{
1400-
Group: GroupVersion.Group,
1401-
Version: GroupVersion.Version,
1400+
Group: SchemeGroupVersion.Group,
1401+
Version: SchemeGroupVersion.Version,
14021402
Kind: ClusterKind,
14031403
})
14041404
}

api/v1/clusterimagecatalog_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1
1919
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020

2121
// +genclient
22+
// +genclient:nonNamespaced
2223
// +kubebuilder:object:root=true
2324
// +kubebuilder:resource:scope=Cluster
2425
// +kubebuilder:storageversion

api/v1/groupversion_info.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package v1 contains API Schema definitions for the postgresql v1 API group
18-
// +kubebuilder:object:generate=true
19-
// +groupName=postgresql.cnpg.io
2017
package v1
2118

2219
import (
@@ -51,11 +48,11 @@ const (
5148
)
5249

5350
var (
54-
// GroupVersion is group version used to register these objects
55-
GroupVersion = schema.GroupVersion{Group: "postgresql.cnpg.io", Version: "v1"}
51+
// SchemeGroupVersion is group version used to register these objects
52+
SchemeGroupVersion = schema.GroupVersion{Group: "postgresql.cnpg.io", Version: "v1"}
5653

5754
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
58-
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
55+
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
5956

6057
// AddToScheme adds the types in this group-version to the given scheme.
6158
AddToScheme = SchemeBuilder.AddToScheme

internal/cmd/plugin/report/operator_utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func getWebhooks(ctx context.Context, stopRedact bool) (
4444

4545
for _, item := range mutatingWebhookConfigList.Items {
4646
for _, webhook := range item.Webhooks {
47-
if len(webhook.Rules) > 0 && webhook.Rules[0].APIGroups[0] == apiv1.GroupVersion.Group {
47+
if len(webhook.Rules) > 0 && webhook.Rules[0].APIGroups[0] == apiv1.SchemeGroupVersion.Group {
4848
mWebhookConfig.Items = append(mWebhookConfig.Items, item)
4949
}
5050
}
@@ -63,7 +63,7 @@ func getWebhooks(ctx context.Context, stopRedact bool) (
6363

6464
for _, item := range validatingWebhookConfigList.Items {
6565
for _, webhook := range item.Webhooks {
66-
if len(webhook.Rules) > 0 && webhook.Rules[0].APIGroups[0] == apiv1.GroupVersion.Group {
66+
if len(webhook.Rules) > 0 && webhook.Rules[0].APIGroups[0] == apiv1.SchemeGroupVersion.Group {
6767
vWebhookConfig.Items = append(vWebhookConfig.Items, item)
6868
}
6969
}
@@ -79,7 +79,7 @@ func getWebhooks(ctx context.Context, stopRedact bool) (
7979
if len(mWebhookConfig.Items) == 0 || len(vWebhookConfig.Items) == 0 {
8080
return nil, nil, fmt.Errorf(
8181
"can't find the webhooks that targeting resources within the group %s",
82-
apiv1.GroupVersion.Group,
82+
apiv1.SchemeGroupVersion.Group,
8383
)
8484
}
8585

internal/controller/cluster_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const (
6969
imageCatalogKey = ".spec.imageCatalog.name"
7070
)
7171

72-
var apiGVString = apiv1.GroupVersion.String()
72+
var apiSGVString = apiv1.SchemeGroupVersion.String()
7373

7474
// errOldPrimaryDetected occurs when a primary Pod loses connectivity with the
7575
// API server and, upon reconnection, attempts to retain its previous primary
@@ -1205,7 +1205,7 @@ func IsOwnedByCluster(obj client.Object) (string, bool) {
12051205
return "", false
12061206
}
12071207

1208-
if owner.APIVersion != apiGVString {
1208+
if owner.APIVersion != apiSGVString {
12091209
return "", false
12101210
}
12111211

internal/controller/cluster_create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ var _ = Describe("createOrPatchClusterCredentialSecret", func() {
868868
cluster := apiv1.Cluster{
869869
TypeMeta: metav1.TypeMeta{
870870
Kind: apiv1.ClusterKind,
871-
APIVersion: apiGVString,
871+
APIVersion: apiSGVString,
872872
},
873873
ObjectMeta: metav1.ObjectMeta{Name: "test-cluster", Namespace: namespace},
874874
}
@@ -1159,7 +1159,7 @@ var _ = Describe("Service Reconciling", func() {
11591159
cluster = apiv1.Cluster{
11601160
TypeMeta: metav1.TypeMeta{
11611161
Kind: apiv1.ClusterKind,
1162-
APIVersion: apiv1.GroupVersion.String(),
1162+
APIVersion: apiv1.SchemeGroupVersion.String(),
11631163
},
11641164
ObjectMeta: metav1.ObjectMeta{
11651165
Name: "test-cluster",

internal/controller/cluster_image.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (r *ClusterReconciler) reconcileImage(ctx context.Context, cluster *apiv1.C
7676
}
7777

7878
apiGroup := cluster.Spec.ImageCatalogRef.APIGroup
79-
if apiGroup == nil || *apiGroup != apiv1.GroupVersion.Group {
79+
if apiGroup == nil || *apiGroup != apiv1.SchemeGroupVersion.Group {
8080
contextLogger.Info("Unknown catalog group")
8181
return &ctrl.Result{}, r.RegisterPhase(ctx, cluster, apiv1.PhaseImageCatalogError,
8282
"Invalid image catalog group")

internal/controller/cluster_restore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ var _ = Describe("ensureOrphanServicesAreNotPresent", func() {
483483
Namespace: cluster.Namespace,
484484
},
485485
}
486-
cluster.TypeMeta = metav1.TypeMeta{Kind: apiv1.ClusterKind, APIVersion: apiv1.GroupVersion.String()}
486+
cluster.TypeMeta = metav1.TypeMeta{Kind: apiv1.ClusterKind, APIVersion: apiv1.SchemeGroupVersion.String()}
487487
cluster.SetInheritedDataAndOwnership(&svc.ObjectMeta)
488488
mockCli = fake.NewClientBuilder().
489489
WithScheme(k8scheme.BuildWithAllKnownScheme()).

internal/controller/pooler_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func isOwnedByPoolerKind(obj client.Object) (string, bool) {
157157
return "", false
158158
}
159159

160-
if owner.APIVersion != apiGVString {
160+
if owner.APIVersion != apiSGVString {
161161
return "", false
162162
}
163163

0 commit comments

Comments
 (0)