/
serialization.go
34 lines (28 loc) · 1.28 KB
/
serialization.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
package validator
import (
"github.com/gardener/gardener/extensions/pkg/util"
"github.com/metal-stack/gardener-extension-provider-metal/pkg/apis/metal"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
)
func decodeControlPlaneConfig(decoder runtime.Decoder, cp *runtime.RawExtension, fldPath *field.Path) (*metal.ControlPlaneConfig, error) {
controlPlaneConfig := &metal.ControlPlaneConfig{}
if err := util.Decode(decoder, cp.Raw, controlPlaneConfig); err != nil {
return nil, field.Invalid(fldPath, string(cp.Raw), "isn't a supported version")
}
return controlPlaneConfig, nil
}
func decodeInfrastructureConfig(decoder runtime.Decoder, infra *runtime.RawExtension, fldPath *field.Path) (*metal.InfrastructureConfig, error) {
infraConfig := &metal.InfrastructureConfig{}
if err := util.Decode(decoder, infra.Raw, infraConfig); err != nil {
return nil, field.Invalid(fldPath, string(infra.Raw), "isn't a supported version")
}
return infraConfig, nil
}
func decodeCloudProfileConfig(decoder runtime.Decoder, config *runtime.RawExtension) (*metal.CloudProfileConfig, error) {
cloudProfileConfig := &metal.CloudProfileConfig{}
if err := util.Decode(decoder, config.Raw, cloudProfileConfig); err != nil {
return nil, err
}
return cloudProfileConfig, nil
}