-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate external types with CRD spec
- Loading branch information
1 parent
02bc7c2
commit 01236bd
Showing
454 changed files
with
143,711 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package bridge | ||
|
||
import ( | ||
_ "embed" | ||
"errors" | ||
"fmt" | ||
"log" | ||
|
||
"k8s.io/apiextensions-apiserver/pkg/apihelpers" | ||
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" | ||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
apiservervalidation "k8s.io/apiextensions-apiserver/pkg/apiserver/validation" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
) | ||
|
||
//go:embed crds/node.eks.aws_nodeconfigs.yaml | ||
var customResourceDefinitionYAML []byte | ||
|
||
var customResourceDefinition *apiextensionsv1.CustomResourceDefinition | ||
|
||
func init() { | ||
scheme := runtime.NewScheme() | ||
if err := apiextensions.AddToScheme(scheme); err != nil { | ||
panic("Failed to register apiextensions on validation scheme") | ||
} | ||
if err := apiextensionsv1.AddToScheme(scheme); err != nil { | ||
panic("Failed to register apiextensionsv1 on validation scheme") | ||
} | ||
codecs := serializer.NewCodecFactory(scheme) | ||
obj, gvk, err := codecs.UniversalDeserializer().Decode(customResourceDefinitionYAML, nil, nil) | ||
if err != nil { | ||
log.Fatalf("failed to decode CRD: %v", err) | ||
} | ||
if crd, ok := obj.(*apiextensionsv1.CustomResourceDefinition); !ok { | ||
log.Fatalf("CRD YAML is not a valid apiextensionsv1.CustomResourceDefinition: %v", gvk) | ||
} else { | ||
customResourceDefinition = crd | ||
} | ||
} | ||
|
||
func ValidateExternalType(obj runtime.Object, gvk schema.GroupVersionKind) error { | ||
validationSchema, err := apihelpers.GetSchemaForVersion(customResourceDefinition, gvk.Version) | ||
if err != nil { | ||
return err | ||
} | ||
var internalSchemaProps *apiextensions.JSONSchemaProps | ||
var internalValidationSchema *apiextensions.CustomResourceValidation | ||
if validationSchema != nil { | ||
internalValidationSchema = &apiextensions.CustomResourceValidation{} | ||
if err := apiextensionsv1.Convert_v1_CustomResourceValidation_To_apiextensions_CustomResourceValidation(validationSchema, internalValidationSchema, nil); err != nil { | ||
return fmt.Errorf("failed to convert CRD validation to internal version: %v", err) | ||
} | ||
internalSchemaProps = internalValidationSchema.OpenAPIV3Schema | ||
} | ||
validator, _, err := apiservervalidation.NewSchemaValidator(internalSchemaProps) | ||
if err != nil { | ||
return err | ||
} | ||
res := validator.Validate(obj) | ||
if len(res.Errors) > 0 { | ||
return errors.Join(res.Errors...) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
nodeadm/vendor/github.com/antlr/antlr4/runtime/Go/antlr/v4/LICENSE
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
nodeadm/vendor/github.com/antlr/antlr4/runtime/Go/antlr/v4/antlrdoc.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.