README
¶
Sampling New OpenAPI Data
This document describes how to fetch OpenAPI data from a live kubernetes API server, e.g. an instance of kind.
Delete all currently built-in schema
make nuke
Add a new built-in schema
In this directory, fetch the openapi schema and generate the corresponding swagger.go for the kubernetes api:
make kubernetesapi/swagger.go
To fetch the schema without generating the swagger.go, you can run:
make nuke
make kubernetesapi/swagger.json
Note that generating the swagger.go will re-fetch the schema.
You can specify a specific version with the "API_VERSION" parameter. The default version is v1.19.1. Here is an example for generating swagger.go for v1.14.1.
make kubernetesapi/swagger.go API_VERSION=v1.14.1
This will update the OpenAPI schema. The above command will create a directory kubernetesapi/v1141 and store the resulting swagger.json and swagger.go files there.
Make the schema available for use
While the above commands generate the swagger.go files, they
do not make them available for use nor do they update the
info field reported by kustomize openapi info
. To make the
newly fetched schema and swagger.go available:
make kubernetesapi/openapiinfo.go
Run all tests
At the top of the repository, run the tests.
make prow-presubmit-check >& /tmp/k.txt; echo $?
# The exit code should be zero; if not examine /tmp/k.txt
Documentation
¶
Overview ¶
Example ¶
Output: Number of desired pods. This is a pointer to distinguish between expli... [integer]
Example (ArrayElement) ¶
Output: Number of port to expose on the pod's IP address. This must be a valid... [integer]
Example (ArrayMerge) ¶
Output: List of containers belonging to the pod. Containers cannot currently b... [array] merge name
Example (ArrayReplace) ¶
Output: Arguments to the entrypoint. The docker image's CMD is used if this is... [array]
Example (Map) ¶
Output: Map of string keys and values that can be used to organize and categor... [object]
Index ¶
- Constants
- func AddDefinitions(definitions spec.Definitions)
- func AddSchema(s []byte) error
- func DefinitionRefs(openAPIPath string) ([]string, error)
- func GetSchemaVersion() string
- func IsNamespaceScoped(typeMeta yaml.TypeMeta) (bool, bool)
- func ResetOpenAPI()
- func Resolve(ref *spec.Ref, schema *spec.Schema) (*spec.Schema, error)
- func Schema() *spec.Schema
- func SchemaFromFile(path string) (*spec.Schema, error)
- func SetSchema(openAPIField map[string]string, schema []byte, reset bool) error
- func SuppressBuiltInSchemaUse()
- type ResourceSchema
- func (rs *ResourceSchema) Elements() *ResourceSchema
- func (rs *ResourceSchema) Field(field string) *ResourceSchema
- func (rs *ResourceSchema) IsMissingOrNull() bool
- func (rs *ResourceSchema) Lookup(path ...string) *ResourceSchema
- func (rs *ResourceSchema) PatchStrategyAndKey() (string, string)
- func (rs *ResourceSchema) PatchStrategyAndKeyList() (string, []string)
Examples ¶
Constants ¶
const Definitions = "definitions"
const Elements = "[]"
const SupplementaryOpenAPIFieldName = "openAPI"
SupplementaryOpenAPIFieldName is the conventional field name (JSON/YAML) containing supplementary OpenAPI definitions.
Variables ¶
This section is empty.
Functions ¶
func AddDefinitions ¶ added in v0.0.11
func AddDefinitions(definitions spec.Definitions)
AddDefinitions adds the definitions to the global schema.
func AddSchema ¶ added in v0.0.11
AddSchema parses s, and adds definitions from s to the global schema.
func DefinitionRefs ¶ added in v0.9.0
DefinitionRefs returns the list of openAPI definition references present in the input openAPIPath
func GetSchemaVersion ¶ added in v0.10.7
func GetSchemaVersion() string
GetSchemaVersion returns what kubernetes OpenAPI version is being used
func IsNamespaceScoped ¶ added in v0.8.0
IsNamespaceScoped determines whether a resource is namespace or cluster-scoped by looking at the information in the openapi schema. The second return value tells whether the provided type could be found in the openapi schema. If the value is false here, the scope of the resource is not known. If the type if found, the first return value will be true if the resource is namespace-scoped, and false if the type is cluster-scoped.
func ResetOpenAPI ¶ added in v0.0.12
func ResetOpenAPI()
ResetOpenAPI resets the openapi data to empty
func SchemaFromFile ¶ added in v0.10.0
AddSchemaFromFile reads the file at path and parses the OpenAPI definitions from the field "openAPI", also returns a function to clean the added definitions The returned clean function is a no-op on error, or else it's a function that the caller should use to remove the added openAPI definitions from global schema
func SuppressBuiltInSchemaUse ¶ added in v0.0.11
func SuppressBuiltInSchemaUse()
SuppressBuiltInSchemaUse can be called to prevent using the built-in Kubernetes schema as part of the global schema. Must be called before the schema is used.
Types ¶
type ResourceSchema ¶
type ResourceSchema struct { // Schema is the OpenAPI schema for a Resource or field Schema *spec.Schema }
ResourceSchema wraps the OpenAPI Schema.
func GetSchema ¶ added in v0.0.11
func GetSchema(s string, schema *spec.Schema) (*ResourceSchema, error)
GetSchema parses s into a ResourceSchema, resolving References within the global schema.
func SchemaForResourceType ¶
func SchemaForResourceType(t yaml.TypeMeta) *ResourceSchema
SchemaForResourceType returns the Schema for the given Resource TODO(pwittrock): create a version of this function that will return a schema which can be used for duck-typed Resources -- e.g. contains common fields such as metadata, replicas and spec.template.spec
func (*ResourceSchema) Elements ¶
func (rs *ResourceSchema) Elements() *ResourceSchema
Elements returns the Schema for the elements of an array.
func (*ResourceSchema) Field ¶
func (rs *ResourceSchema) Field(field string) *ResourceSchema
Field returns the Schema for a field.
func (*ResourceSchema) IsMissingOrNull ¶ added in v0.6.0
func (rs *ResourceSchema) IsMissingOrNull() bool
IsEmpty returns true if the ResourceSchema is empty
func (*ResourceSchema) Lookup ¶
func (rs *ResourceSchema) Lookup(path ...string) *ResourceSchema
Lookup calls either Field or Elements for each item in the path. If the path item is "[]", then Elements is called, otherwise Field is called. If any Field or Elements call returns nil, then Lookup returns nil immediately.
func (*ResourceSchema) PatchStrategyAndKey ¶
func (rs *ResourceSchema) PatchStrategyAndKey() (string, string)
PatchStrategyAndKey returns the patch strategy and merge key extensions
func (*ResourceSchema) PatchStrategyAndKeyList ¶ added in v0.9.4
func (rs *ResourceSchema) PatchStrategyAndKeyList() (string, []string)
PatchStrategyAndKeyList returns the patch strategy and complete merge key list