Skip to content

Commit bad7d3c

Browse files
committed
Fix conversion-verifier and fix findings
1 parent da5cc32 commit bad7d3c

File tree

4 files changed

+25
-33
lines changed

4 files changed

+25
-33
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,11 @@ verify-gen: generate ## Verify go generated files are up to date
716716

717717
.PHONY: verify-conversions
718718
verify-conversions: $(CONVERSION_VERIFIER) ## Verifies expected API conversion are in place
719-
$(CONVERSION_VERIFIER)
719+
$(CONVERSION_VERIFIER) \
720+
./api/... \
721+
./internal/api/... \
722+
./test/infrastructure/docker/api/... \
723+
./test/infrastructure/docker/exp/api/...
720724

721725
.PHONY: verify-doctoc
722726
verify-doctoc: generate-doctoc

api/core/v1beta1/conversion.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ func (dst *MachinePool) ConvertFrom(srcRaw conversion.Hub) error {
167167
return nil
168168
}
169169

170+
func (src *MachineDrainRule) ConvertTo(dstRaw conversion.Hub) error {
171+
dst := dstRaw.(*clusterv1.MachineDrainRule)
172+
return Convert_v1beta1_MachineDrainRule_To_v1beta2_MachineDrainRule(src, dst, nil)
173+
}
174+
175+
func (dst *MachineDrainRule) ConvertFrom(srcRaw conversion.Hub) error {
176+
src := srcRaw.(*clusterv1.MachineDrainRule)
177+
return Convert_v1beta2_MachineDrainRule_To_v1beta1_MachineDrainRule(src, dst, nil)
178+
}
179+
170180
func Convert_v1beta2_ClusterClassSpec_To_v1beta1_ClusterClassSpec(in *clusterv1.ClusterClassSpec, out *ClusterClassSpec, s apimachineryconversion.Scope) error {
171181
if err := autoConvert_v1beta2_ClusterClassSpec_To_v1beta1_ClusterClassSpec(in, out, s); err != nil {
172182
return err

api/core/v1beta2/conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (*MachineSet) Hub() {}
3131
func (*MachineDeployment) Hub() {}
3232
func (*MachineHealthCheck) Hub() {}
3333
func (*MachinePool) Hub() {}
34+
func (*MachineDrainRule) Hub() {}
3435

3536
// ConvertToSeconds takes *metav1.Duration and returns a *int32.
3637
// Durations longer than MaxInt32 are capped.

hack/tools/conversion-verifier/main.go

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package main
1919
import (
2020
"fmt"
2121
"go/types"
22+
"os"
2223
"path"
23-
"strings"
2424

2525
"github.com/pkg/errors"
2626
"k8s.io/klog/v2"
@@ -88,10 +88,13 @@ func main() {
8888
}
8989

9090
// Load all packages.
91-
// TODO: Move the path parameter to a multi-string flag.
92-
packages, err := loader.LoadRoots("./...")
93-
if err != nil {
94-
klog.Fatal(err)
91+
var packages []*loader.Package
92+
for _, pkgPath := range os.Args[1:] {
93+
p, err := loader.LoadRoots(pkgPath)
94+
if err != nil {
95+
klog.Fatal(err)
96+
}
97+
packages = append(packages, p...)
9598
}
9699

97100
// First loop through all the packages
@@ -137,33 +140,6 @@ func main() {
137140
}
138141
}
139142

140-
// Find and populate all <Kind>List types.
141-
for _, pkg := range apiPackages {
142-
if err := markers.EachType(col, pkg.Package, func(info *markers.TypeInfo) {
143-
if !strings.HasSuffix(info.Name, "List") {
144-
// We're only interested in List types in this iteration.
145-
return
146-
}
147-
storage, ok := storageVersionTypes[path.Join(pkg.Group, strings.TrimSuffix(info.Name, "List"))]
148-
if !ok || pkg.PkgPath != storage.pkg.PkgPath {
149-
// Return early if the type isn't in the same storage package
150-
// or if there is no storage version registered for this type.
151-
return
152-
}
153-
154-
// If we're here, we've found <Kind>List type that's also a storage version.
155-
storageVersionTypes[path.Join(pkg.Group, info.Name)] = &storageVersionType{
156-
versionType: &versionType{
157-
pkg: pkg.Package,
158-
typ: info,
159-
},
160-
otherDecls: make(map[string]*versionType),
161-
}
162-
}); err != nil {
163-
klog.Fatal(err)
164-
}
165-
}
166-
167143
// Now that we have storage version information,
168144
// loop through every package again and collect info about all declarations.
169145
for _, pkg := range apiPackages {
@@ -215,6 +191,7 @@ func main() {
215191
for _, err := range errs {
216192
fmt.Printf("\t* %s\n", err)
217193
}
194+
os.Exit(1)
218195
}
219196
}
220197

0 commit comments

Comments
 (0)