Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce public methods for DryRunVerifier #87489

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions staging/src/k8s.io/cli-runtime/pkg/resource/dry_run_verifier.go
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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)
}
Expand All @@ -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) {
Expand Down
Expand Up @@ -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 {
Expand All @@ -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",
Expand All @@ -97,7 +97,7 @@ func TestDryRunVerifier(t *testing.T) {
},
}, nil
}),
OpenAPIGetter: &fakeSchema,
openAPIGetter: &fakeSchema,
}

err := dryRunVerifier.HasSupport(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "NodeProxyOptions"})
Expand Down Expand Up @@ -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",
Expand All @@ -141,7 +141,7 @@ func TestDryRunVerifierNoOpenAPI(t *testing.T) {
},
}, nil
}),
OpenAPIGetter: EmptyOpenAPI{},
openAPIGetter: EmptyOpenAPI{},
}

err := dryRunVerifier.HasSupport(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"})
Expand Down