-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
convert_v1alpha4.go
99 lines (80 loc) · 3.28 KB
/
convert_v1alpha4.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
Copyright 2019 The Kubernetes Authors.
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 config
import (
v1alpha4 "sigs.k8s.io/kind/pkg/apis/config/v1alpha4"
)
// Convertv1alpha4 converts a v1alpha4 cluster to a cluster at the internal API version
func Convertv1alpha4(in *v1alpha4.Cluster) *Cluster {
in = in.DeepCopy() // deep copy first to avoid touching the original
out := &Cluster{
Nodes: make([]Node, len(in.Nodes)),
FeatureGates: in.FeatureGates,
KubeadmConfigPatches: in.KubeadmConfigPatches,
KubeadmConfigPatchesJSON6902: make([]PatchJSON6902, len(in.KubeadmConfigPatchesJSON6902)),
ContainerdConfigPatches: in.ContainerdConfigPatches,
ContainerdConfigPatchesJSON6902: in.ContainerdConfigPatchesJSON6902,
}
for i := range in.Nodes {
convertv1alpha4Node(&in.Nodes[i], &out.Nodes[i])
}
convertv1alpha4Networking(&in.Networking, &out.Networking)
for i := range in.KubeadmConfigPatchesJSON6902 {
convertv1alpha4PatchJSON6902(&in.KubeadmConfigPatchesJSON6902[i], &out.KubeadmConfigPatchesJSON6902[i])
}
return out
}
func convertv1alpha4Node(in *v1alpha4.Node, out *Node) {
out.Role = NodeRole(in.Role)
out.Image = in.Image
out.KubeadmConfigPatches = in.KubeadmConfigPatches
out.ExtraMounts = make([]Mount, len(in.ExtraMounts))
out.ExtraPortMappings = make([]PortMapping, len(in.ExtraPortMappings))
out.KubeadmConfigPatchesJSON6902 = make([]PatchJSON6902, len(in.KubeadmConfigPatchesJSON6902))
for i := range in.ExtraMounts {
convertv1alpha4Mount(&in.ExtraMounts[i], &out.ExtraMounts[i])
}
for i := range in.ExtraPortMappings {
convertv1alpha4PortMapping(&in.ExtraPortMappings[i], &out.ExtraPortMappings[i])
}
for i := range in.KubeadmConfigPatchesJSON6902 {
convertv1alpha4PatchJSON6902(&in.KubeadmConfigPatchesJSON6902[i], &out.KubeadmConfigPatchesJSON6902[i])
}
}
func convertv1alpha4PatchJSON6902(in *v1alpha4.PatchJSON6902, out *PatchJSON6902) {
out.Group = in.Group
out.Version = in.Version
out.Kind = in.Kind
out.Patch = in.Patch
}
func convertv1alpha4Networking(in *v1alpha4.Networking, out *Networking) {
out.IPFamily = ClusterIPFamily(in.IPFamily)
out.APIServerPort = in.APIServerPort
out.APIServerAddress = in.APIServerAddress
out.PodSubnet = in.PodSubnet
out.ServiceSubnet = in.ServiceSubnet
out.DisableDefaultCNI = in.DisableDefaultCNI
}
func convertv1alpha4Mount(in *v1alpha4.Mount, out *Mount) {
out.ContainerPath = in.ContainerPath
out.HostPath = in.HostPath
out.Readonly = in.Readonly
out.SelinuxRelabel = in.SelinuxRelabel
out.Propagation = MountPropagation(in.Propagation)
}
func convertv1alpha4PortMapping(in *v1alpha4.PortMapping, out *PortMapping) {
out.ContainerPort = in.ContainerPort
out.HostPort = in.HostPort
out.ListenAddress = in.ListenAddress
out.Protocol = PortMappingProtocol(in.Protocol)
}