Reduce public methods for DryRunVerifier

This commit is contained in:
Julian V. Modesto 2020-01-23 09:51:15 +00:00 committed by Julian V. Modesto
parent 63df400778
commit 18fe96f629
2 changed files with 15 additions and 15 deletions

View File

@ -36,8 +36,8 @@ func VerifyDryRun(gvk schema.GroupVersionKind, dynamicClient dynamic.Interface,
func NewDryRunVerifier(dynamicClient dynamic.Interface, discoveryClient discovery.DiscoveryInterface) *DryRunVerifier {
return &DryRunVerifier{
Finder: NewCRDFinder(CRDFromDynamic(dynamicClient)),
OpenAPIGetter: discoveryClient,
finder: NewCRDFinder(CRDFromDynamic(dynamicClient)),
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
// requires an extra round-trip to the server.
type DryRunVerifier struct {
Finder CRDFinder
OpenAPIGetter discovery.OpenAPISchemaInterface
finder CRDFinder
openAPIGetter discovery.OpenAPISchemaInterface
}
// HasSupport verifies if the given gvk supports DryRun. An error is
// returned if it doesn't.
func (v *DryRunVerifier) HasSupport(gvk schema.GroupVersionKind) error {
oapi, err := v.OpenAPIGetter.OpenAPISchema()
oapi, err := v.openAPIGetter.OpenAPISchema()
if err != nil {
return fmt.Errorf("failed to download openapi: %v", err)
}
supports, err := SupportsDryRun(oapi, gvk)
supports, err := supportsDryRun(oapi, gvk)
if err != nil {
// 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 supports {
supports, err = v.Finder.HasCRD(gvk.GroupKind())
supports, err = v.finder.HasCRD(gvk.GroupKind())
if err != nil {
return fmt.Errorf("failed to check CRD: %v", err)
}
@ -100,10 +100,10 @@ func (v *DryRunVerifier) HasSupport(gvk schema.GroupVersionKind) error {
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
// 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() {
// Is this describing the gvk we're looking for?
if !hasGVKExtension(path.GetValue().GetPatch().GetVendorExtension(), gvk) {

View File

@ -66,7 +66,7 @@ func TestSupportsDryRun(t *testing.T) {
}
for _, test := range tests {
supports, err := SupportsDryRun(doc, test.gvk)
supports, err := supportsDryRun(doc, test.gvk)
if supports != test.supports || ((err == nil) != test.success) {
errStr := "nil"
if test.success == false {
@ -85,7 +85,7 @@ var fakeSchema = openapitesting.Fake{Path: filepath.Join("..", "..", "artifacts"
func TestDryRunVerifier(t *testing.T) {
dryRunVerifier := DryRunVerifier{
Finder: NewCRDFinder(func() ([]schema.GroupKind, error) {
finder: NewCRDFinder(func() ([]schema.GroupKind, error) {
return []schema.GroupKind{
{
Group: "crd.com",
@ -97,7 +97,7 @@ func TestDryRunVerifier(t *testing.T) {
},
}, nil
}),
OpenAPIGetter: &fakeSchema,
openAPIGetter: &fakeSchema,
}
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) {
dryRunVerifier := DryRunVerifier{
Finder: NewCRDFinder(func() ([]schema.GroupKind, error) {
finder: NewCRDFinder(func() ([]schema.GroupKind, error) {
return []schema.GroupKind{
{
Group: "crd.com",
@ -141,7 +141,7 @@ func TestDryRunVerifierNoOpenAPI(t *testing.T) {
},
}, nil
}),
OpenAPIGetter: EmptyOpenAPI{},
openAPIGetter: EmptyOpenAPI{},
}
err := dryRunVerifier.HasSupport(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"})