/
serialization.go
30 lines (25 loc) · 1.06 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
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 cp != nil && cp.Raw != nil {
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 infra != nil && infra.Raw != nil {
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
}