mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-12 13:43:10 +01:00
Run basic backup and restore tests for the plugin. Use MinIO for S3, Azurite for ACS and fake-gcs-server for GCS. Signed-off-by: Francesco Canovai <francesco.canovai@enterprisedb.com>
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
/*
|
|
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 client
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
"k8s.io/client-go/rest"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/client/config"
|
|
)
|
|
|
|
// NewClient creates a new controller-runtime Kubernetes client.
|
|
//
|
|
//nolint:ireturn
|
|
func NewClient() (client.Client, *rest.Config, error) {
|
|
cfg, err := config.GetConfig()
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("failed to get Kubernetes config: %w", err)
|
|
}
|
|
cl, err := client.New(cfg, client.Options{})
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("failed to create Kubernetes client: %w", err)
|
|
}
|
|
|
|
return cl, cfg, nil
|
|
}
|
|
|
|
// NewClientSet creates a new k8s client-go clientset.
|
|
func NewClientSet() (*kubernetes.Clientset, *rest.Config, error) {
|
|
cfg, err := config.GetConfig()
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("failed to get Kubernetes config: %w", err)
|
|
}
|
|
clientSet, err := kubernetes.NewForConfig(cfg)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("failed to create Kubernetes client: %w", err)
|
|
}
|
|
|
|
return clientSet, cfg, nil
|
|
}
|