mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-16 07:13:53 +00:00
Reduce public methods for DryRunVerifier
This commit is contained in:
parent
63df400778
commit
18fe96f629
@ -36,8 +36,8 @@ func VerifyDryRun(gvk schema.GroupVersionKind, dynamicClient dynamic.Interface,
|
|||||||
|
|
||||||
func NewDryRunVerifier(dynamicClient dynamic.Interface, discoveryClient discovery.DiscoveryInterface) *DryRunVerifier {
|
func NewDryRunVerifier(dynamicClient dynamic.Interface, discoveryClient discovery.DiscoveryInterface) *DryRunVerifier {
|
||||||
return &DryRunVerifier{
|
return &DryRunVerifier{
|
||||||
Finder: NewCRDFinder(CRDFromDynamic(dynamicClient)),
|
finder: NewCRDFinder(CRDFromDynamic(dynamicClient)),
|
||||||
OpenAPIGetter: discoveryClient,
|
openAPIGetter: discoveryClient,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,24 +71,24 @@ func hasGVKExtension(extensions []*openapi_v2.NamedAny, gvk schema.GroupVersionK
|
|||||||
// delay the check for CRDs as much as possible though, since it
|
// delay the check for CRDs as much as possible though, since it
|
||||||
// requires an extra round-trip to the server.
|
// requires an extra round-trip to the server.
|
||||||
type DryRunVerifier struct {
|
type DryRunVerifier struct {
|
||||||
Finder CRDFinder
|
finder CRDFinder
|
||||||
OpenAPIGetter discovery.OpenAPISchemaInterface
|
openAPIGetter discovery.OpenAPISchemaInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasSupport verifies if the given gvk supports DryRun. An error is
|
// HasSupport verifies if the given gvk supports DryRun. An error is
|
||||||
// returned if it doesn't.
|
// returned if it doesn't.
|
||||||
func (v *DryRunVerifier) HasSupport(gvk schema.GroupVersionKind) error {
|
func (v *DryRunVerifier) HasSupport(gvk schema.GroupVersionKind) error {
|
||||||
oapi, err := v.OpenAPIGetter.OpenAPISchema()
|
oapi, err := v.openAPIGetter.OpenAPISchema()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to download openapi: %v", err)
|
return fmt.Errorf("failed to download openapi: %v", err)
|
||||||
}
|
}
|
||||||
supports, err := SupportsDryRun(oapi, gvk)
|
supports, err := supportsDryRun(oapi, gvk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// We assume that we couldn't find the type, then check for namespace:
|
// We assume that we couldn't find the type, then check for namespace:
|
||||||
supports, _ = SupportsDryRun(oapi, schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"})
|
supports, _ = supportsDryRun(oapi, schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"})
|
||||||
// If namespace supports dryRun, then we will support dryRun for CRDs only.
|
// If namespace supports dryRun, then we will support dryRun for CRDs only.
|
||||||
if supports {
|
if supports {
|
||||||
supports, err = v.Finder.HasCRD(gvk.GroupKind())
|
supports, err = v.finder.HasCRD(gvk.GroupKind())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to check CRD: %v", err)
|
return fmt.Errorf("failed to check CRD: %v", err)
|
||||||
}
|
}
|
||||||
@ -100,10 +100,10 @@ func (v *DryRunVerifier) HasSupport(gvk schema.GroupVersionKind) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportsDryRun is a method that let's us look in the OpenAPI if the
|
// supportsDryRun is a method that let's us look in the OpenAPI if the
|
||||||
// specific group-version-kind supports the dryRun query parameter for
|
// specific group-version-kind supports the dryRun query parameter for
|
||||||
// the PATCH end-point.
|
// the PATCH end-point.
|
||||||
func SupportsDryRun(doc *openapi_v2.Document, gvk schema.GroupVersionKind) (bool, error) {
|
func supportsDryRun(doc *openapi_v2.Document, gvk schema.GroupVersionKind) (bool, error) {
|
||||||
for _, path := range doc.GetPaths().GetPath() {
|
for _, path := range doc.GetPaths().GetPath() {
|
||||||
// Is this describing the gvk we're looking for?
|
// Is this describing the gvk we're looking for?
|
||||||
if !hasGVKExtension(path.GetValue().GetPatch().GetVendorExtension(), gvk) {
|
if !hasGVKExtension(path.GetValue().GetPatch().GetVendorExtension(), gvk) {
|
||||||
|
@ -66,7 +66,7 @@ func TestSupportsDryRun(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
supports, err := SupportsDryRun(doc, test.gvk)
|
supports, err := supportsDryRun(doc, test.gvk)
|
||||||
if supports != test.supports || ((err == nil) != test.success) {
|
if supports != test.supports || ((err == nil) != test.success) {
|
||||||
errStr := "nil"
|
errStr := "nil"
|
||||||
if test.success == false {
|
if test.success == false {
|
||||||
@ -85,7 +85,7 @@ var fakeSchema = openapitesting.Fake{Path: filepath.Join("..", "..", "artifacts"
|
|||||||
|
|
||||||
func TestDryRunVerifier(t *testing.T) {
|
func TestDryRunVerifier(t *testing.T) {
|
||||||
dryRunVerifier := DryRunVerifier{
|
dryRunVerifier := DryRunVerifier{
|
||||||
Finder: NewCRDFinder(func() ([]schema.GroupKind, error) {
|
finder: NewCRDFinder(func() ([]schema.GroupKind, error) {
|
||||||
return []schema.GroupKind{
|
return []schema.GroupKind{
|
||||||
{
|
{
|
||||||
Group: "crd.com",
|
Group: "crd.com",
|
||||||
@ -97,7 +97,7 @@ func TestDryRunVerifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
OpenAPIGetter: &fakeSchema,
|
openAPIGetter: &fakeSchema,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := dryRunVerifier.HasSupport(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "NodeProxyOptions"})
|
err := dryRunVerifier.HasSupport(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "NodeProxyOptions"})
|
||||||
@ -129,7 +129,7 @@ func (EmptyOpenAPI) OpenAPISchema() (*openapi_v2.Document, error) {
|
|||||||
|
|
||||||
func TestDryRunVerifierNoOpenAPI(t *testing.T) {
|
func TestDryRunVerifierNoOpenAPI(t *testing.T) {
|
||||||
dryRunVerifier := DryRunVerifier{
|
dryRunVerifier := DryRunVerifier{
|
||||||
Finder: NewCRDFinder(func() ([]schema.GroupKind, error) {
|
finder: NewCRDFinder(func() ([]schema.GroupKind, error) {
|
||||||
return []schema.GroupKind{
|
return []schema.GroupKind{
|
||||||
{
|
{
|
||||||
Group: "crd.com",
|
Group: "crd.com",
|
||||||
@ -141,7 +141,7 @@ func TestDryRunVerifierNoOpenAPI(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
OpenAPIGetter: EmptyOpenAPI{},
|
openAPIGetter: EmptyOpenAPI{},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := dryRunVerifier.HasSupport(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"})
|
err := dryRunVerifier.HasSupport(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"})
|
||||||
|
Loading…
Reference in New Issue
Block a user