-
Notifications
You must be signed in to change notification settings - Fork 463
/
helpers.go
50 lines (42 loc) · 1.53 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package helper
import (
"errors"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"github.com/gardener/gardener/pkg/scheduler/apis/config"
"github.com/gardener/gardener/pkg/scheduler/apis/config/v1alpha1"
)
var scheme *runtime.Scheme
func init() {
scheme = runtime.NewScheme()
utilruntime.Must(config.AddToScheme(scheme))
utilruntime.Must(v1alpha1.AddToScheme(scheme))
}
// ConvertSchedulerConfiguration converts the given object to an internal SchedulerConfiguration version.
func ConvertSchedulerConfiguration(obj runtime.Object) (*config.SchedulerConfiguration, error) {
obj, err := scheme.ConvertToVersion(obj, config.SchemeGroupVersion)
if err != nil {
return nil, err
}
result, ok := obj.(*config.SchedulerConfiguration)
if !ok {
return nil, errors.New("could not convert SchedulerConfiguration to the internal version")
}
return result, nil
}
// ConvertSchedulerConfigurationExternal converts the given object to an external SchedulerConfiguration version.
func ConvertSchedulerConfigurationExternal(obj runtime.Object) (*v1alpha1.SchedulerConfiguration, error) {
obj, err := scheme.ConvertToVersion(obj, v1alpha1.SchemeGroupVersion)
if err != nil {
return nil, err
}
result, ok := obj.(*v1alpha1.SchedulerConfiguration)
if !ok {
return nil, fmt.Errorf("could not convert SchedulerConfiguration to the external version")
}
return result, nil
}