mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-07-07 02:02:21 +02:00
chore: avoid using SchemeBuilder
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@gmail.com>
This commit is contained in:
parent
4384ec198b
commit
fdb9c495f7
@ -16,7 +16,7 @@ linters:
|
|||||||
- gocyclo
|
- gocyclo
|
||||||
- goheader
|
- goheader
|
||||||
- gomoddirectives
|
- gomoddirectives
|
||||||
- gomodguard
|
- gomodguard_v2
|
||||||
- goprintffuncname
|
- goprintffuncname
|
||||||
- gosec
|
- gosec
|
||||||
- govet
|
- govet
|
||||||
|
|||||||
@ -20,17 +20,19 @@ SPDX-License-Identifier: Apache-2.0
|
|||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/scheme"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// GroupVersion is group version used to register these objects.
|
// GroupVersion is group version used to register these objects.
|
||||||
GroupVersion = schema.GroupVersion{Group: "barmancloud.cnpg.io", Version: "v1"}
|
var GroupVersion = schema.GroupVersion{Group: "barmancloud.cnpg.io", Version: "v1"}
|
||||||
|
|
||||||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
|
// AddKnownTypes add to the passed schema the Kubernetes types
|
||||||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
|
// exposed by this package.
|
||||||
|
func AddKnownTypes(scheme *runtime.Scheme) {
|
||||||
|
scheme.AddKnownTypes(GroupVersion,
|
||||||
|
&ObjectStore{}, &ObjectStoreList{})
|
||||||
|
|
||||||
// AddToScheme adds the types in this group-version to the given scheme.
|
metav1.AddToGroupVersion(scheme, GroupVersion)
|
||||||
AddToScheme = SchemeBuilder.AddToScheme
|
}
|
||||||
)
|
|
||||||
|
|||||||
@ -124,7 +124,3 @@ type ObjectStoreList struct {
|
|||||||
metav1.ListMeta `json:"metadata,omitempty"`
|
metav1.ListMeta `json:"metadata,omitempty"`
|
||||||
Items []ObjectStore `json:"items"`
|
Items []ObjectStore `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
SchemeBuilder.Register(&ObjectStore{}, &ObjectStoreList{})
|
|
||||||
}
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@ package v1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
|||||||
@ -29,7 +29,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/scheme"
|
|
||||||
|
|
||||||
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
||||||
)
|
)
|
||||||
@ -40,7 +39,7 @@ import (
|
|||||||
func GenerateScheme(ctx context.Context) *runtime.Scheme {
|
func GenerateScheme(ctx context.Context) *runtime.Scheme {
|
||||||
result := runtime.NewScheme()
|
result := runtime.NewScheme()
|
||||||
|
|
||||||
utilruntime.Must(barmancloudv1.AddToScheme(result))
|
barmancloudv1.AddKnownTypes(result)
|
||||||
utilruntime.Must(clientgoscheme.AddToScheme(result))
|
utilruntime.Must(clientgoscheme.AddToScheme(result))
|
||||||
|
|
||||||
cnpgGroup := viper.GetString("custom-cnpg-group")
|
cnpgGroup := viper.GetString("custom-cnpg-group")
|
||||||
@ -54,11 +53,11 @@ func GenerateScheme(ctx context.Context) *runtime.Scheme {
|
|||||||
|
|
||||||
// Proceed with custom registration of the CNPG scheme
|
// Proceed with custom registration of the CNPG scheme
|
||||||
schemeGroupVersion := schema.GroupVersion{Group: cnpgGroup, Version: cnpgVersion}
|
schemeGroupVersion := schema.GroupVersion{Group: cnpgGroup, Version: cnpgVersion}
|
||||||
schemeBuilder := &scheme.Builder{GroupVersion: schemeGroupVersion}
|
result.AddKnownTypes(schemeGroupVersion,
|
||||||
schemeBuilder.Register(&cnpgv1.Cluster{}, &cnpgv1.ClusterList{})
|
&cnpgv1.Cluster{}, &cnpgv1.ClusterList{},
|
||||||
schemeBuilder.Register(&cnpgv1.Backup{}, &cnpgv1.BackupList{})
|
&cnpgv1.Backup{}, &cnpgv1.BackupList{},
|
||||||
schemeBuilder.Register(&cnpgv1.ScheduledBackup{}, &cnpgv1.ScheduledBackupList{})
|
&cnpgv1.ScheduledBackup{}, &cnpgv1.ScheduledBackupList{},
|
||||||
utilruntime.Must(schemeBuilder.AddToScheme(result))
|
)
|
||||||
|
|
||||||
schemeLog := log.FromContext(ctx)
|
schemeLog := log.FromContext(ctx)
|
||||||
schemeLog.Info("CNPG types registration", "schemeGroupVersion", schemeGroupVersion)
|
schemeLog.Info("CNPG types registration", "schemeGroupVersion", schemeGroupVersion)
|
||||||
|
|||||||
@ -39,7 +39,7 @@ var scheme = buildScheme()
|
|||||||
func buildScheme() *runtime.Scheme {
|
func buildScheme() *runtime.Scheme {
|
||||||
scheme := runtime.NewScheme()
|
scheme := runtime.NewScheme()
|
||||||
_ = corev1.AddToScheme(scheme)
|
_ = corev1.AddToScheme(scheme)
|
||||||
_ = barmancloudv1.AddToScheme(scheme)
|
barmancloudv1.AddKnownTypes(scheme)
|
||||||
|
|
||||||
return scheme
|
return scheme
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,7 +55,7 @@ var _ = Describe("Metrics Collect method", func() {
|
|||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
scheme := runtime.NewScheme()
|
scheme := runtime.NewScheme()
|
||||||
Expect(barmancloudv1.AddToScheme(scheme)).To(Succeed())
|
barmancloudv1.AddKnownTypes(scheme)
|
||||||
|
|
||||||
// Timestamps for the test
|
// Timestamps for the test
|
||||||
firstRecoverabilityPoint := metav1.NewTime(time.Now().Add(-24 * time.Hour))
|
firstRecoverabilityPoint := metav1.NewTime(time.Now().Add(-24 * time.Hour))
|
||||||
|
|||||||
@ -55,7 +55,7 @@ var _ = Describe("LifecycleImplementation", func() {
|
|||||||
// helper to build a fake client with our scheme and optional objects
|
// helper to build a fake client with our scheme and optional objects
|
||||||
buildClientFunc := func(objs ...runtime.Object) *fake.ClientBuilder {
|
buildClientFunc := func(objs ...runtime.Object) *fake.ClientBuilder {
|
||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
_ = barmancloudv1.AddToScheme(s)
|
barmancloudv1.AddKnownTypes(s)
|
||||||
return fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...)
|
return fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ var _ = Describe("LifecycleImplementation", func() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
_ = barmancloudv1.AddToScheme(s)
|
barmancloudv1.AddKnownTypes(s)
|
||||||
cli := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(store).Build()
|
cli := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(store).Build()
|
||||||
|
|
||||||
impl := LifecycleImplementation{Client: cli}
|
impl := LifecycleImplementation{Client: cli}
|
||||||
@ -378,7 +378,7 @@ var _ = Describe("LifecycleImplementation", func() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
_ = barmancloudv1.AddToScheme(s)
|
barmancloudv1.AddKnownTypes(s)
|
||||||
cli := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(store).Build()
|
cli := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(store).Build()
|
||||||
|
|
||||||
impl := LifecycleImplementation{Client: cli}
|
impl := LifecycleImplementation{Client: cli}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ var scheme = runtime.NewScheme()
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
|
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
|
||||||
utilruntime.Must(barmancloudv1.AddToScheme(scheme))
|
barmancloudv1.AddKnownTypes(scheme)
|
||||||
// +kubebuilder:scaffold:scheme
|
// +kubebuilder:scaffold:scheme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,7 @@ func newScheme() *runtime.Scheme {
|
|||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
utilruntime.Must(rbacv1.AddToScheme(s))
|
utilruntime.Must(rbacv1.AddToScheme(s))
|
||||||
utilruntime.Must(cnpgv1.AddToScheme(s))
|
utilruntime.Must(cnpgv1.AddToScheme(s))
|
||||||
utilruntime.Must(barmancloudv1.AddToScheme(s))
|
barmancloudv1.AddKnownTypes(s)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,7 @@ import (
|
|||||||
func newFakeScheme() *runtime.Scheme {
|
func newFakeScheme() *runtime.Scheme {
|
||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
utilruntime.Must(rbacv1.AddToScheme(s))
|
utilruntime.Must(rbacv1.AddToScheme(s))
|
||||||
utilruntime.Must(barmancloudv1.AddToScheme(s))
|
barmancloudv1.AddKnownTypes(s)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,8 +27,6 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
|
||||||
crscheme "sigs.k8s.io/controller-runtime/pkg/scheme"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddCNPGToScheme registers CNPG types into the given scheme using
|
// AddCNPGToScheme registers CNPG types into the given scheme using
|
||||||
@ -46,11 +44,11 @@ func AddCNPGToScheme(ctx context.Context, s *runtime.Scheme) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
schemeGroupVersion := schema.GroupVersion{Group: cnpgGroup, Version: cnpgVersion}
|
schemeGroupVersion := schema.GroupVersion{Group: cnpgGroup, Version: cnpgVersion}
|
||||||
schemeBuilder := &crscheme.Builder{GroupVersion: schemeGroupVersion}
|
s.AddKnownTypes(schemeGroupVersion,
|
||||||
schemeBuilder.Register(&cnpgv1.Cluster{}, &cnpgv1.ClusterList{})
|
&cnpgv1.Cluster{}, &cnpgv1.ClusterList{},
|
||||||
schemeBuilder.Register(&cnpgv1.Backup{}, &cnpgv1.BackupList{})
|
&cnpgv1.Backup{}, &cnpgv1.BackupList{},
|
||||||
schemeBuilder.Register(&cnpgv1.ScheduledBackup{}, &cnpgv1.ScheduledBackupList{})
|
&cnpgv1.ScheduledBackup{}, &cnpgv1.ScheduledBackupList{},
|
||||||
utilruntime.Must(schemeBuilder.AddToScheme(s))
|
)
|
||||||
|
|
||||||
log.FromContext(ctx).Info("CNPG types registration", "schemeGroupVersion", schemeGroupVersion)
|
log.FromContext(ctx).Info("CNPG types registration", "schemeGroupVersion", schemeGroupVersion)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,12 +91,11 @@ func addScheme(cl client.Client) error {
|
|||||||
if err := certmanagerv1.AddToScheme(scheme); err != nil {
|
if err := certmanagerv1.AddToScheme(scheme); err != nil {
|
||||||
return fmt.Errorf("failed to add cert-manager/v1 to scheme: %w", err)
|
return fmt.Errorf("failed to add cert-manager/v1 to scheme: %w", err)
|
||||||
}
|
}
|
||||||
if err := pluginBarmanCloudV1.AddToScheme(scheme); err != nil {
|
|
||||||
return fmt.Errorf("failed to add plugin-barman-cloud/v1 to scheme: %w", err)
|
|
||||||
}
|
|
||||||
if err := cloudnativepgv1.AddToScheme(scheme); err != nil {
|
if err := cloudnativepgv1.AddToScheme(scheme); err != nil {
|
||||||
return fmt.Errorf("failed to add cloudnativepg/v1 to scheme: %w", err)
|
return fmt.Errorf("failed to add cloudnativepg/v1 to scheme: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pluginBarmanCloudV1.AddKnownTypes(scheme)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user