Skip to content

Commit

Permalink
Interface changes for upstream kubectl package
Browse files Browse the repository at this point in the history
  • Loading branch information
rquitales committed Dec 10, 2023
1 parent 5a5862f commit b2d5636
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions provider/pkg/openapi/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (

// ValidateAgainstSchema validates a document against the given schema.
func ValidateAgainstSchema(
resources openapi.Resources, obj *unstructured.Unstructured,
resourcesGetter openapi.OpenAPIResourcesGetter, resources openapi.Resources, obj *unstructured.Unstructured,
) error {
bytes, err := obj.MarshalJSON()
if err != nil {
Expand All @@ -66,7 +66,7 @@ func ValidateAgainstSchema(
// validation errors when there are multiple errors for usability purposes.

// Validate resource against schema.
specValidator := validation.NewSchemaValidation(resources)
specValidator := validation.NewSchemaValidation(resourcesGetter)
return specValidator.ValidateBytes(bytes)
}

Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/provider/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (k *KubeConfig) ToRESTMapper() (meta.RESTMapper, error) {
}

mapper := restmapper.NewDeferredDiscoveryRESTMapper(discoveryClient)
expander := restmapper.NewShortcutExpander(mapper, discoveryClient)
expander := restmapper.NewShortcutExpander(mapper, discoveryClient, nil)
return expander, nil
}

Expand Down
14 changes: 13 additions & 1 deletion provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ func (k *kubeProvider) getResources() (k8sopenapi.Resources, error) {
return k.resources, nil
}

type openAPIResourcesGetter struct {
k *kubeProvider
}

func (o *openAPIResourcesGetter) OpenAPISchema() (k8sopenapi.Resources, error) {
return o.k.getResources()
}

func (k *kubeProvider) getResourcesLazy() k8sopenapi.OpenAPIResourcesGetter {
return &openAPIResourcesGetter{k}
}

func (k *kubeProvider) invalidateResources() {
k.resourcesMutex.Lock()
defer k.resourcesMutex.Unlock()
Expand Down Expand Up @@ -1430,7 +1442,7 @@ func (k *kubeProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (
}

// Validate the object according to the OpenAPI schema for its GVK.
err = openapi.ValidateAgainstSchema(resources, newInputs)
err = openapi.ValidateAgainstSchema(k.getResourcesLazy(), resources, newInputs)
if err != nil {
resourceNotFound := apierrors.IsNotFound(err) ||
strings.Contains(err.Error(), "is not supported by the server")
Expand Down

0 comments on commit b2d5636

Please sign in to comment.