Signed-off-by: Rafael Brito <rbrito@vmware.com>pull/2362/head
parent
016df403f6
commit
f6cd53c6cb
|
@ -0,0 +1 @@
|
||||||
|
adding labels on backup CRD for k8s major, minor and git versions
|
|
@ -50,4 +50,16 @@ const (
|
||||||
// ResticVolumeNamespaceLabel is the label key used to identify which
|
// ResticVolumeNamespaceLabel is the label key used to identify which
|
||||||
// namespace a restic repository stores pod volume backups for.
|
// namespace a restic repository stores pod volume backups for.
|
||||||
ResticVolumeNamespaceLabel = "velero.io/volume-namespace"
|
ResticVolumeNamespaceLabel = "velero.io/volume-namespace"
|
||||||
|
|
||||||
|
// SourceClusterK8sVersionLabel is the label key used to identify the k8s
|
||||||
|
// git version of the backup , i.e. v1.16.4
|
||||||
|
SourceClusterK8sGitVersionLabel = "velero.io/source-cluster-k8s-gitversion"
|
||||||
|
|
||||||
|
// SourceClusterK8sMajorVersionLabel is the label key used to identify the k8s
|
||||||
|
// major version of the backup , i.e. 1
|
||||||
|
SourceClusterK8sMajorVersionLabel = "velero.io/source-cluster-k8s-major-version"
|
||||||
|
|
||||||
|
// SourceClusterK8sMajorVersionLabel is the label key used to identify the k8s
|
||||||
|
// minor version of the backup , i.e. 16
|
||||||
|
SourceClusterK8sMinorVersionLabel = "velero.io/source-cluster-k8s-minor-version"
|
||||||
)
|
)
|
||||||
|
|
|
@ -587,6 +587,7 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
|
||||||
backupController := controller.NewBackupController(
|
backupController := controller.NewBackupController(
|
||||||
s.sharedInformerFactory.Velero().V1().Backups(),
|
s.sharedInformerFactory.Velero().V1().Backups(),
|
||||||
s.veleroClient.VeleroV1(),
|
s.veleroClient.VeleroV1(),
|
||||||
|
s.discoveryHelper,
|
||||||
backupper,
|
backupper,
|
||||||
s.logger,
|
s.logger,
|
||||||
s.logLevel,
|
s.logLevel,
|
||||||
|
|
|
@ -39,6 +39,7 @@ import (
|
||||||
|
|
||||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||||
pkgbackup "github.com/vmware-tanzu/velero/pkg/backup"
|
pkgbackup "github.com/vmware-tanzu/velero/pkg/backup"
|
||||||
|
"github.com/vmware-tanzu/velero/pkg/discovery"
|
||||||
velerov1client "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
|
velerov1client "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
|
||||||
velerov1informers "github.com/vmware-tanzu/velero/pkg/generated/informers/externalversions/velero/v1"
|
velerov1informers "github.com/vmware-tanzu/velero/pkg/generated/informers/externalversions/velero/v1"
|
||||||
velerov1listers "github.com/vmware-tanzu/velero/pkg/generated/listers/velero/v1"
|
velerov1listers "github.com/vmware-tanzu/velero/pkg/generated/listers/velero/v1"
|
||||||
|
@ -55,7 +56,7 @@ import (
|
||||||
|
|
||||||
type backupController struct {
|
type backupController struct {
|
||||||
*genericController
|
*genericController
|
||||||
|
discoveryHelper discovery.Helper
|
||||||
backupper pkgbackup.Backupper
|
backupper pkgbackup.Backupper
|
||||||
lister velerov1listers.BackupLister
|
lister velerov1listers.BackupLister
|
||||||
client velerov1client.BackupsGetter
|
client velerov1client.BackupsGetter
|
||||||
|
@ -76,6 +77,7 @@ type backupController struct {
|
||||||
func NewBackupController(
|
func NewBackupController(
|
||||||
backupInformer velerov1informers.BackupInformer,
|
backupInformer velerov1informers.BackupInformer,
|
||||||
client velerov1client.BackupsGetter,
|
client velerov1client.BackupsGetter,
|
||||||
|
discoveryHelper discovery.Helper,
|
||||||
backupper pkgbackup.Backupper,
|
backupper pkgbackup.Backupper,
|
||||||
logger logrus.FieldLogger,
|
logger logrus.FieldLogger,
|
||||||
backupLogLevel logrus.Level,
|
backupLogLevel logrus.Level,
|
||||||
|
@ -91,6 +93,7 @@ func NewBackupController(
|
||||||
) Interface {
|
) Interface {
|
||||||
c := &backupController{
|
c := &backupController{
|
||||||
genericController: newGenericController("backup", logger),
|
genericController: newGenericController("backup", logger),
|
||||||
|
discoveryHelper: discoveryHelper,
|
||||||
backupper: backupper,
|
backupper: backupper,
|
||||||
lister: backupInformer.Lister(),
|
lister: backupInformer.Lister(),
|
||||||
client: client,
|
client: client,
|
||||||
|
@ -329,6 +332,11 @@ func (c *backupController) prepareBackupRequest(backup *velerov1api.Backup) *pkg
|
||||||
}
|
}
|
||||||
request.Labels[velerov1api.StorageLocationLabel] = label.GetValidName(request.Spec.StorageLocation)
|
request.Labels[velerov1api.StorageLocationLabel] = label.GetValidName(request.Spec.StorageLocation)
|
||||||
|
|
||||||
|
// Getting all information of cluster version - useful for future skip-level migration
|
||||||
|
request.Labels[velerov1api.SourceClusterK8sGitVersionLabel] = label.GetValidName(c.discoveryHelper.ServerVersion().String())
|
||||||
|
request.Labels[velerov1api.SourceClusterK8sMajorVersionLabel] = label.GetValidName(c.discoveryHelper.ServerVersion().Major)
|
||||||
|
request.Labels[velerov1api.SourceClusterK8sMinorVersionLabel] = label.GetValidName(c.discoveryHelper.ServerVersion().Minor)
|
||||||
|
|
||||||
// validate the included/excluded resources
|
// validate the included/excluded resources
|
||||||
for _, err := range collections.ValidateIncludesExcludes(request.Spec.IncludedResources, request.Spec.ExcludedResources) {
|
for _, err := range collections.ValidateIncludesExcludes(request.Spec.IncludedResources, request.Spec.ExcludedResources) {
|
||||||
request.Status.ValidationErrors = append(request.Status.ValidationErrors, fmt.Sprintf("Invalid included/excluded resource lists: %v", err))
|
request.Status.ValidationErrors = append(request.Status.ValidationErrors, fmt.Sprintf("Invalid included/excluded resource lists: %v", err))
|
||||||
|
|
|
@ -33,9 +33,12 @@ import (
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
"k8s.io/apimachinery/pkg/util/clock"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/version"
|
||||||
|
|
||||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||||
pkgbackup "github.com/vmware-tanzu/velero/pkg/backup"
|
pkgbackup "github.com/vmware-tanzu/velero/pkg/backup"
|
||||||
"github.com/vmware-tanzu/velero/pkg/builder"
|
"github.com/vmware-tanzu/velero/pkg/builder"
|
||||||
|
"github.com/vmware-tanzu/velero/pkg/discovery"
|
||||||
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/fake"
|
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/fake"
|
||||||
informers "github.com/vmware-tanzu/velero/pkg/generated/informers/externalversions"
|
informers "github.com/vmware-tanzu/velero/pkg/generated/informers/externalversions"
|
||||||
"github.com/vmware-tanzu/velero/pkg/metrics"
|
"github.com/vmware-tanzu/velero/pkg/metrics"
|
||||||
|
@ -44,6 +47,7 @@ import (
|
||||||
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt"
|
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt"
|
||||||
pluginmocks "github.com/vmware-tanzu/velero/pkg/plugin/mocks"
|
pluginmocks "github.com/vmware-tanzu/velero/pkg/plugin/mocks"
|
||||||
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
|
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
|
||||||
|
velerotest "github.com/vmware-tanzu/velero/pkg/test"
|
||||||
"github.com/vmware-tanzu/velero/pkg/util/logging"
|
"github.com/vmware-tanzu/velero/pkg/util/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -168,8 +172,13 @@ func TestProcessBackupValidationFailures(t *testing.T) {
|
||||||
logger = logging.DefaultLogger(logrus.DebugLevel, formatFlag)
|
logger = logging.DefaultLogger(logrus.DebugLevel, formatFlag)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
apiServer := velerotest.NewAPIServer(t)
|
||||||
|
discoveryHelper, err := discovery.NewHelper(apiServer.DiscoveryClient, logger)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
c := &backupController{
|
c := &backupController{
|
||||||
genericController: newGenericController("backup-test", logger),
|
genericController: newGenericController("backup-test", logger),
|
||||||
|
discoveryHelper: discoveryHelper,
|
||||||
client: clientset.VeleroV1(),
|
client: clientset.VeleroV1(),
|
||||||
lister: sharedInformers.Velero().V1().Backups().Lister(),
|
lister: sharedInformers.Velero().V1().Backups().Lister(),
|
||||||
backupLocationLister: sharedInformers.Velero().V1().BackupStorageLocations().Lister(),
|
backupLocationLister: sharedInformers.Velero().V1().BackupStorageLocations().Lister(),
|
||||||
|
@ -236,8 +245,13 @@ func TestBackupLocationLabel(t *testing.T) {
|
||||||
logger = logging.DefaultLogger(logrus.DebugLevel, formatFlag)
|
logger = logging.DefaultLogger(logrus.DebugLevel, formatFlag)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
apiServer := velerotest.NewAPIServer(t)
|
||||||
|
discoveryHelper, err := discovery.NewHelper(apiServer.DiscoveryClient, logger)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
c := &backupController{
|
c := &backupController{
|
||||||
genericController: newGenericController("backup-test", logger),
|
genericController: newGenericController("backup-test", logger),
|
||||||
|
discoveryHelper: discoveryHelper,
|
||||||
client: clientset.VeleroV1(),
|
client: clientset.VeleroV1(),
|
||||||
lister: sharedInformers.Velero().V1().Backups().Lister(),
|
lister: sharedInformers.Velero().V1().Backups().Lister(),
|
||||||
backupLocationLister: sharedInformers.Velero().V1().BackupStorageLocations().Lister(),
|
backupLocationLister: sharedInformers.Velero().V1().BackupStorageLocations().Lister(),
|
||||||
|
@ -293,8 +307,14 @@ func TestDefaultBackupTTL(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
apiServer := velerotest.NewAPIServer(t)
|
||||||
|
discoveryHelper, err := discovery.NewHelper(apiServer.DiscoveryClient, logger)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
c := &backupController{
|
c := &backupController{
|
||||||
genericController: newGenericController("backup-test", logger),
|
genericController: newGenericController("backup-test", logger),
|
||||||
|
discoveryHelper: discoveryHelper,
|
||||||
backupLocationLister: sharedInformers.Velero().V1().BackupStorageLocations().Lister(),
|
backupLocationLister: sharedInformers.Velero().V1().BackupStorageLocations().Lister(),
|
||||||
snapshotLocationLister: sharedInformers.Velero().V1().VolumeSnapshotLocations().Lister(),
|
snapshotLocationLister: sharedInformers.Velero().V1().VolumeSnapshotLocations().Lister(),
|
||||||
defaultBackupTTL: defaultBackupTTL.Duration,
|
defaultBackupTTL: defaultBackupTTL.Duration,
|
||||||
|
@ -340,7 +360,10 @@ func TestProcessBackupCompletions(t *testing.T) {
|
||||||
Namespace: velerov1api.DefaultNamespace,
|
Namespace: velerov1api.DefaultNamespace,
|
||||||
Name: "backup-1",
|
Name: "backup-1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"velero.io/storage-location": "loc-1",
|
"velero.io/source-cluster-k8s-major-version": "1",
|
||||||
|
"velero.io/source-cluster-k8s-minor-version": "16",
|
||||||
|
"velero.io/source-cluster-k8s-gitversion": "v1.16.4",
|
||||||
|
"velero.io/storage-location": "loc-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: velerov1api.BackupSpec{
|
Spec: velerov1api.BackupSpec{
|
||||||
|
@ -368,7 +391,10 @@ func TestProcessBackupCompletions(t *testing.T) {
|
||||||
Namespace: velerov1api.DefaultNamespace,
|
Namespace: velerov1api.DefaultNamespace,
|
||||||
Name: "backup-1",
|
Name: "backup-1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"velero.io/storage-location": "alt-loc",
|
"velero.io/source-cluster-k8s-major-version": "1",
|
||||||
|
"velero.io/source-cluster-k8s-minor-version": "16",
|
||||||
|
"velero.io/source-cluster-k8s-gitversion": "v1.16.4",
|
||||||
|
"velero.io/storage-location": "alt-loc",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: velerov1api.BackupSpec{
|
Spec: velerov1api.BackupSpec{
|
||||||
|
@ -399,7 +425,10 @@ func TestProcessBackupCompletions(t *testing.T) {
|
||||||
Namespace: velerov1api.DefaultNamespace,
|
Namespace: velerov1api.DefaultNamespace,
|
||||||
Name: "backup-1",
|
Name: "backup-1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"velero.io/storage-location": "read-write",
|
"velero.io/source-cluster-k8s-major-version": "1",
|
||||||
|
"velero.io/source-cluster-k8s-minor-version": "16",
|
||||||
|
"velero.io/source-cluster-k8s-gitversion": "v1.16.4",
|
||||||
|
"velero.io/storage-location": "read-write",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: velerov1api.BackupSpec{
|
Spec: velerov1api.BackupSpec{
|
||||||
|
@ -427,7 +456,10 @@ func TestProcessBackupCompletions(t *testing.T) {
|
||||||
Namespace: velerov1api.DefaultNamespace,
|
Namespace: velerov1api.DefaultNamespace,
|
||||||
Name: "backup-1",
|
Name: "backup-1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"velero.io/storage-location": "loc-1",
|
"velero.io/source-cluster-k8s-major-version": "1",
|
||||||
|
"velero.io/source-cluster-k8s-minor-version": "16",
|
||||||
|
"velero.io/source-cluster-k8s-gitversion": "v1.16.4",
|
||||||
|
"velero.io/storage-location": "loc-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: velerov1api.BackupSpec{
|
Spec: velerov1api.BackupSpec{
|
||||||
|
@ -457,7 +489,10 @@ func TestProcessBackupCompletions(t *testing.T) {
|
||||||
Namespace: velerov1api.DefaultNamespace,
|
Namespace: velerov1api.DefaultNamespace,
|
||||||
Name: "backup-1",
|
Name: "backup-1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"velero.io/storage-location": "loc-1",
|
"velero.io/source-cluster-k8s-major-version": "1",
|
||||||
|
"velero.io/source-cluster-k8s-minor-version": "16",
|
||||||
|
"velero.io/source-cluster-k8s-gitversion": "v1.16.4",
|
||||||
|
"velero.io/storage-location": "loc-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: velerov1api.BackupSpec{
|
Spec: velerov1api.BackupSpec{
|
||||||
|
@ -488,7 +523,10 @@ func TestProcessBackupCompletions(t *testing.T) {
|
||||||
Namespace: velerov1api.DefaultNamespace,
|
Namespace: velerov1api.DefaultNamespace,
|
||||||
Name: "backup-1",
|
Name: "backup-1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"velero.io/storage-location": "loc-1",
|
"velero.io/source-cluster-k8s-major-version": "1",
|
||||||
|
"velero.io/source-cluster-k8s-minor-version": "16",
|
||||||
|
"velero.io/source-cluster-k8s-gitversion": "v1.16.4",
|
||||||
|
"velero.io/storage-location": "loc-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: velerov1api.BackupSpec{
|
Spec: velerov1api.BackupSpec{
|
||||||
|
@ -517,7 +555,10 @@ func TestProcessBackupCompletions(t *testing.T) {
|
||||||
Namespace: velerov1api.DefaultNamespace,
|
Namespace: velerov1api.DefaultNamespace,
|
||||||
Name: "backup-1",
|
Name: "backup-1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"velero.io/storage-location": "loc-1",
|
"velero.io/source-cluster-k8s-major-version": "1",
|
||||||
|
"velero.io/source-cluster-k8s-minor-version": "16",
|
||||||
|
"velero.io/source-cluster-k8s-gitversion": "v1.16.4",
|
||||||
|
"velero.io/storage-location": "loc-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: velerov1api.BackupSpec{
|
Spec: velerov1api.BackupSpec{
|
||||||
|
@ -546,8 +587,26 @@ func TestProcessBackupCompletions(t *testing.T) {
|
||||||
backupper = new(fakeBackupper)
|
backupper = new(fakeBackupper)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
apiServer := velerotest.NewAPIServer(t)
|
||||||
|
|
||||||
|
apiServer.DiscoveryClient.FakedServerVersion = &version.Info{
|
||||||
|
Major: "1",
|
||||||
|
Minor: "16",
|
||||||
|
GitVersion: "v1.16.4",
|
||||||
|
GitCommit: "FakeTest",
|
||||||
|
GitTreeState: "",
|
||||||
|
BuildDate: "",
|
||||||
|
GoVersion: "",
|
||||||
|
Compiler: "",
|
||||||
|
Platform: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
discoveryHelper, err := discovery.NewHelper(apiServer.DiscoveryClient, logger)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
c := &backupController{
|
c := &backupController{
|
||||||
genericController: newGenericController("backup-test", logger),
|
genericController: newGenericController("backup-test", logger),
|
||||||
|
discoveryHelper: discoveryHelper,
|
||||||
client: clientset.VeleroV1(),
|
client: clientset.VeleroV1(),
|
||||||
lister: sharedInformers.Velero().V1().Backups().Lister(),
|
lister: sharedInformers.Velero().V1().Backups().Lister(),
|
||||||
backupLocationLister: sharedInformers.Velero().V1().BackupStorageLocations().Lister(),
|
backupLocationLister: sharedInformers.Velero().V1().BackupStorageLocations().Lister(),
|
||||||
|
@ -584,7 +643,7 @@ func TestProcessBackupCompletions(t *testing.T) {
|
||||||
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(test.backup))
|
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(test.backup))
|
||||||
|
|
||||||
// add the default backup storage location to the clientset and the informer/lister store
|
// add the default backup storage location to the clientset and the informer/lister store
|
||||||
_, err := clientset.VeleroV1().BackupStorageLocations(defaultBackupLocation.Namespace).Create(defaultBackupLocation)
|
_, err = clientset.VeleroV1().BackupStorageLocations(defaultBackupLocation.Namespace).Create(defaultBackupLocation)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.NoError(t, sharedInformers.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(defaultBackupLocation))
|
require.NoError(t, sharedInformers.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(defaultBackupLocation))
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
"k8s.io/apimachinery/pkg/version"
|
||||||
"k8s.io/client-go/discovery"
|
"k8s.io/client-go/discovery"
|
||||||
"k8s.io/client-go/restmapper"
|
"k8s.io/client-go/restmapper"
|
||||||
|
|
||||||
|
@ -49,6 +50,10 @@ type Helper interface {
|
||||||
// APIGroups gets the current set of supported APIGroups
|
// APIGroups gets the current set of supported APIGroups
|
||||||
// in the cluster.
|
// in the cluster.
|
||||||
APIGroups() []metav1.APIGroup
|
APIGroups() []metav1.APIGroup
|
||||||
|
|
||||||
|
// ServerVersion retrieves and parses the server's k8s version (git version)
|
||||||
|
// in the cluster.
|
||||||
|
ServerVersion() *version.Info
|
||||||
}
|
}
|
||||||
|
|
||||||
type serverResourcesInterface interface {
|
type serverResourcesInterface interface {
|
||||||
|
@ -60,11 +65,12 @@ type helper struct {
|
||||||
logger logrus.FieldLogger
|
logger logrus.FieldLogger
|
||||||
|
|
||||||
// lock guards mapper, resources and resourcesMap
|
// lock guards mapper, resources and resourcesMap
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
mapper meta.RESTMapper
|
mapper meta.RESTMapper
|
||||||
resources []*metav1.APIResourceList
|
resources []*metav1.APIResourceList
|
||||||
resourcesMap map[schema.GroupVersionResource]metav1.APIResource
|
resourcesMap map[schema.GroupVersionResource]metav1.APIResource
|
||||||
apiGroups []metav1.APIGroup
|
apiGroups []metav1.APIGroup
|
||||||
|
serverVersion *version.Info
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Helper = &helper{}
|
var _ Helper = &helper{}
|
||||||
|
@ -143,6 +149,13 @@ func (h *helper) Refresh() error {
|
||||||
}
|
}
|
||||||
h.apiGroups = apiGroupList.Groups
|
h.apiGroups = apiGroupList.Groups
|
||||||
|
|
||||||
|
serverVersion, err := h.discoveryClient.ServerVersion()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
h.serverVersion = serverVersion
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,3 +213,9 @@ func (h *helper) APIGroups() []metav1.APIGroup {
|
||||||
defer h.lock.RUnlock()
|
defer h.lock.RUnlock()
|
||||||
return h.apiGroups
|
return h.apiGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *helper) ServerVersion() *version.Info {
|
||||||
|
h.lock.RLock()
|
||||||
|
defer h.lock.RUnlock()
|
||||||
|
return h.serverVersion
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
"k8s.io/apimachinery/pkg/version"
|
||||||
"k8s.io/client-go/discovery"
|
"k8s.io/client-go/discovery"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ type FakeDiscoveryHelper struct {
|
||||||
Mapper meta.RESTMapper
|
Mapper meta.RESTMapper
|
||||||
AutoReturnResource bool
|
AutoReturnResource bool
|
||||||
APIGroupsList []metav1.APIGroup
|
APIGroupsList []metav1.APIGroup
|
||||||
|
ServerVersionData *version.Info
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFakeDiscoveryHelper(autoReturnResource bool, resources map[schema.GroupVersionResource]schema.GroupVersionResource) *FakeDiscoveryHelper {
|
func NewFakeDiscoveryHelper(autoReturnResource bool, resources map[schema.GroupVersionResource]schema.GroupVersionResource) *FakeDiscoveryHelper {
|
||||||
|
@ -70,6 +72,22 @@ func NewFakeDiscoveryHelper(autoReturnResource bool, resources map[schema.GroupV
|
||||||
helper.ResourceList = append(helper.ResourceList, &metav1.APIResourceList{GroupVersion: group, APIResources: resources})
|
helper.ResourceList = append(helper.ResourceList, &metav1.APIResourceList{GroupVersion: group, APIResources: resources})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FakeTest of version.Info
|
||||||
|
|
||||||
|
serverVersion := &version.Info{
|
||||||
|
Major: "1",
|
||||||
|
Minor: "16",
|
||||||
|
GitVersion: "v1.16.4",
|
||||||
|
GitCommit: "FakeTest",
|
||||||
|
GitTreeState: "",
|
||||||
|
BuildDate: "",
|
||||||
|
GoVersion: "",
|
||||||
|
Compiler: "",
|
||||||
|
Platform: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
helper.ServerVersionData = serverVersion
|
||||||
|
|
||||||
return helper
|
return helper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,3 +167,7 @@ func NewFakeServerResourcesInterface(resourceList []*metav1.APIResourceList, fai
|
||||||
}
|
}
|
||||||
return helper
|
return helper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dh *FakeDiscoveryHelper) ServerVersion() *version.Info {
|
||||||
|
return dh.ServerVersionData
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue