Skip to content

Commit 1ad4da4

Browse files
committed
fix
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
1 parent 2628801 commit 1ad4da4

File tree

14 files changed

+14145
-182
lines changed

14 files changed

+14145
-182
lines changed

cmd/download-builtin-schemas/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ func main() {
3838
}
3939

4040
// Versions 1.0-1.22 did not have OpenAPIV3 schemas.
41+
one27Fetcher := openapiclient.NewGitHubBuiltins("1.27")
42+
one27Paths, err := one27Fetcher.Paths()
43+
44+
if err != nil {
45+
panic(err)
46+
}
47+
48+
apiregistrationV1Path := "apis/apiregistration.k8s.io/v1"
49+
one27APIRegistrationV1 := one27Paths[apiregistrationV1Path]
50+
4151
for i := 23; ; i++ {
4252
version := fmt.Sprintf("1.%d", i)
4353
fetcher := openapiclient.NewGitHubBuiltins(version)
@@ -47,6 +57,13 @@ func main() {
4757
break
4858
}
4959

60+
if i < 27 {
61+
// Copy over the APIRegistrationV1 schema from 1.27 in older
62+
// releasees due to
63+
// https://github.com/kubernetes/kubernetes/pull/118879
64+
schemas[apiregistrationV1Path] = one27APIRegistrationV1
65+
}
66+
5067
for k, v := range schemas {
5168
data, err := v.Schema("application/json")
5269
if err != nil {

pkg/cmd/validate.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"io/fs"
89
"net/http"
910
"os"
1011

@@ -164,16 +165,27 @@ func errorToStatus(err error) metav1.Status {
164165
}
165166

166167
func (c *commandFlags) Run(cmd *cobra.Command, args []string) error {
168+
var schemaPatchesFs, localSchemasFs fs.FS
169+
if c.schemaPatchesDir != "" {
170+
schemaPatchesFs = os.DirFS(c.schemaPatchesDir)
171+
}
172+
if c.localSchemasDir != "" {
173+
localSchemasFs = os.DirFS(c.localSchemasDir)
174+
}
175+
var localCRDsFileSystems []fs.FS
176+
for _, current := range c.localCRDsDir {
177+
localCRDsFileSystems = append(localCRDsFileSystems, os.DirFS(current))
178+
}
167179
// tool fetches openapi in the following priority order:
168180
factory, err := validator.New(
169181
openapiclient.NewOverlay(
170182
// apply user defined patches on top of the final schema
171-
openapiclient.PatchLoaderFromDirectory(nil, c.schemaPatchesDir),
183+
openapiclient.PatchLoaderFromDirectory(schemaPatchesFs),
172184
openapiclient.NewComposite(
173185
// consult local OpenAPI
174-
openapiclient.NewLocalSchemaFiles(nil, c.localSchemasDir),
186+
openapiclient.NewLocalSchemaFiles(localSchemasFs),
175187
// consult local CRDs
176-
openapiclient.NewLocalCRDFiles(nil, c.localCRDsDir),
188+
openapiclient.NewLocalCRDFiles(localCRDsFileSystems...),
177189
openapiclient.NewOverlay(
178190
// Hand-written hardcoded patches.
179191
openapiclient.HardcodedPatchLoader(c.version),

0 commit comments

Comments
 (0)