1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00
Files
installer/pkg/explain/schema.go
Abhinav Dahiya a194303a0d pkg: add explain package
The explain package provides an `explain` cobra command that can use used to add it as subcommand.

The package includes 2 major functions,

- fields_lookup
Given a list of paths, this finds the schema for the path from the install config schema.

- printer
The printer printers the schema provided to the function

The printer always prints the InstallConfig apiVersion, kind to the provided io.Writer
It prints the description of the field using the schema provided,
and for object type, it also prints all the properties of the object and their descriptions.
2020-05-07 09:22:31 -07:00

28 lines
822 B
Go

package explain
import (
"github.com/pkg/errors"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
)
func loadSchema(b []byte) (*apiextv1.JSONSchemaProps, error) {
scheme := runtime.NewScheme()
codecs := serializer.NewCodecFactory(scheme)
apiextv1.AddToScheme(scheme)
obj, err := runtime.Decode(codecs.UniversalDecoder(apiextv1.SchemeGroupVersion), b)
if err != nil {
return nil, err
}
crd, ok := obj.(*apiextv1.CustomResourceDefinition)
if !ok {
return nil, errors.Errorf("invalid object, should be *apiextv1.CustomResourceDefinition but found %T", obj)
}
if len(crd.Spec.Versions) != 1 {
return nil, errors.New("missing versions in CRD")
}
return crd.Spec.Versions[0].Schema.OpenAPIV3Schema, nil
}