Skip to content

Commit 042fd35

Browse files
authored
Merge pull request #17526 from justinsb/enable_roundtrip_tests_2
Add round-trip tests / PodCIDR to all versions
2 parents e4c04c7 + fe436a4 commit 042fd35

File tree

30 files changed

+3172
-4
lines changed

30 files changed

+3172
-4
lines changed

pkg/apis/kops/host.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package kops
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// +genclient
24+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
25+
26+
// Host represents a bare-metal machine that could be registered as a Node.
27+
type Host struct {
28+
metav1.TypeMeta `json:",inline"`
29+
metav1.ObjectMeta `json:"metadata,omitempty"`
30+
31+
Spec HostSpec `json:"spec,omitempty"`
32+
}
33+
34+
type HostSpec struct {
35+
PublicKey string `json:"publicKey,omitempty"`
36+
InstanceGroup string `json:"instanceGroup,omitempty"`
37+
38+
// PodCIDRs configures the IP ranges to be used for pods on this node/host.
39+
PodCIDRs []string `json:"podCIDRs,omitempty"`
40+
}
41+
42+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
43+
44+
type HostList struct {
45+
metav1.TypeMeta `json:",inline"`
46+
metav1.ListMeta `json:"metadata,omitempty"`
47+
48+
Items []Host `json:"items"`
49+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package install
18+
19+
import (
20+
"strings"
21+
"testing"
22+
23+
"k8s.io/apimachinery/pkg/runtime"
24+
"k8s.io/apimachinery/pkg/runtime/schema"
25+
)
26+
27+
func TestTypesExistInAllVersions(t *testing.T) {
28+
scheme := runtime.NewScheme()
29+
Install(scheme)
30+
31+
group := "kops.k8s.io"
32+
internalVersion := schema.GroupVersion{Group: group, Version: runtime.APIVersionInternal}
33+
internalKindToGoType := scheme.KnownTypes(internalVersion)
34+
35+
internalKinds := make(map[string]bool)
36+
for kind := range internalKindToGoType {
37+
internalKinds[kind] = true
38+
}
39+
40+
for _, version := range []string{"v1alpha2", "v1alpha3"} {
41+
versionKinds := scheme.KnownTypes(schema.GroupVersion{Group: group, Version: version})
42+
for kind := range versionKinds {
43+
// Ignore ListOptions, DeleteOptions, etc.
44+
if strings.HasSuffix(kind, "Options") {
45+
continue
46+
}
47+
if !internalKinds[kind] {
48+
t.Errorf("version %s has kind %s, not found in internal API", version, kind)
49+
}
50+
}
51+
}
52+
}

pkg/apis/kops/install/roundtrip_test.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,42 @@ limitations under the License.
1717
package install
1818

1919
import (
20+
"math/rand"
2021
"testing"
22+
23+
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
24+
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
25+
metafuzzer "k8s.io/apimachinery/pkg/apis/meta/fuzzer"
26+
"k8s.io/apimachinery/pkg/runtime"
27+
"k8s.io/apimachinery/pkg/runtime/schema"
28+
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
2129
)
2230

2331
func TestRoundTripTypes(t *testing.T) {
24-
t.Skipped()
25-
// TODO: Reenable
26-
// roundtrip.RoundTripTestForAPIGroup(t, Install, nil)
32+
var fuzzingFuncs fuzzer.FuzzerFuncs
33+
34+
nonRoundTrippableTypes := make(map[schema.GroupVersionKind]bool)
35+
36+
// TODO: Eliminate this once all types round-trip
37+
for _, version := range []string{"v1alpha2", "v1alpha3"} {
38+
nonRoundTrippableTypes[schema.GroupVersionKind{Group: "kops.k8s.io", Version: version, Kind: "Cluster"}] = true
39+
nonRoundTrippableTypes[schema.GroupVersionKind{Group: "kops.k8s.io", Version: version, Kind: "ClusterList"}] = true
40+
nonRoundTrippableTypes[schema.GroupVersionKind{Group: "kops.k8s.io", Version: version, Kind: "InstanceGroup"}] = true
41+
nonRoundTrippableTypes[schema.GroupVersionKind{Group: "kops.k8s.io", Version: version, Kind: "InstanceGroupList"}] = true
42+
}
43+
44+
if len(nonRoundTrippableTypes) == 0 {
45+
roundtrip.RoundTripTestForAPIGroup(t, Install, fuzzingFuncs)
46+
} else {
47+
scheme := runtime.NewScheme()
48+
Install(scheme)
49+
50+
codecFactory := runtimeserializer.NewCodecFactory(scheme)
51+
f := fuzzer.FuzzerFor(
52+
fuzzer.MergeFuzzerFuncs(metafuzzer.Funcs, fuzzingFuncs),
53+
rand.NewSource(rand.Int63()),
54+
codecFactory,
55+
)
56+
roundtrip.RoundTripTypesWithoutProtobuf(t, scheme, codecFactory, f, nonRoundTrippableTypes)
57+
}
2758
}

pkg/apis/kops/register.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
6363
&KeysetList{},
6464
&SSHCredential{},
6565
&SSHCredentialList{},
66+
&Host{},
67+
&HostList{},
6668
)
6769
// metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
6870
return nil

pkg/apis/kops/v1alpha2/zz_generated.conversion.go

Lines changed: 122 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/kops/v1alpha3/host.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type Host struct {
3636
type HostSpec struct {
3737
PublicKey string `json:"publicKey,omitempty"`
3838
InstanceGroup string `json:"instanceGroup,omitempty"`
39+
40+
// PodCIDRs configures the IP ranges to be used for pods on this node/host.
41+
PodCIDRs []string `json:"podCIDRs,omitempty"`
3942
}
4043

4144
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

0 commit comments

Comments
 (0)