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

Add Support for OpenAPIEnum in OpenAPI v2 #105057

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
315 changes: 272 additions & 43 deletions api/openapi-spec/swagger.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
utilfeature "k8s.io/apiserver/pkg/util/feature"
utilflowcontrol "k8s.io/apiserver/pkg/util/flowcontrol"
"k8s.io/apiserver/pkg/util/notfoundhandler"
"k8s.io/apiserver/pkg/util/openapi"
"k8s.io/apiserver/pkg/util/webhook"
clientgoinformers "k8s.io/client-go/informers"
clientgoclientset "k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -396,8 +397,9 @@ func buildGenericConfig(
return
}
}

genericConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(generatedopenapi.GetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(legacyscheme.Scheme, extensionsapiserver.Scheme, aggregatorscheme.Scheme))
// wrap the definitions to revert any changes from disabled features
getOpenAPIDefinitions := openapi.GetOpenAPIDefinitionsWithoutDisabledFeatures(generatedopenapi.GetOpenAPIDefinitions)
genericConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(getOpenAPIDefinitions, openapinamer.NewDefinitionNamer(legacyscheme.Scheme, extensionsapiserver.Scheme, aggregatorscheme.Scheme))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean CRD enums are stripped too, or just the ones of native APIs? What about aggregation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only affect built-in, CRD schemas were untouched.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enums are removed from generated openapi defs of only built-ins. Because it is eliminated at the source, aggregation won't have enums for built-ins either.

genericConfig.OpenAPIConfig.Info.Title = "Kubernetes"
genericConfig.LongRunningFunc = filters.BasicLongRunningRequestCheck(
sets.NewString("watch", "proxy"),
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ require (
k8s.io/klog/v2 v2.30.0
k8s.io/kube-aggregator v0.0.0
k8s.io/kube-controller-manager v0.0.0
k8s.io/kube-openapi v0.0.0-20211105084753-ee342a809c29
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65
k8s.io/kube-proxy v0.0.0
k8s.io/kube-scheduler v0.0.0
k8s.io/kubectl v0.0.0
Expand Down Expand Up @@ -243,6 +243,7 @@ replace (
github.com/frankban/quicktest => github.com/frankban/quicktest v1.11.3
github.com/fsnotify/fsnotify => github.com/fsnotify/fsnotify v1.4.9
github.com/fvbommel/sortorder => github.com/fvbommel/sortorder v1.0.1
github.com/getkin/kin-openapi => github.com/getkin/kin-openapi v0.76.0
github.com/getsentry/raven-go => github.com/getsentry/raven-go v0.2.0
github.com/ghodss/yaml => github.com/ghodss/yaml v1.0.0
github.com/go-errors/errors => github.com/go-errors/errors v1.0.1
Expand Down Expand Up @@ -504,7 +505,7 @@ replace (
k8s.io/klog/v2 => k8s.io/klog/v2 v2.30.0
k8s.io/kube-aggregator => ./staging/src/k8s.io/kube-aggregator
k8s.io/kube-controller-manager => ./staging/src/k8s.io/kube-controller-manager
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20211105084753-ee342a809c29
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65
k8s.io/kube-proxy => ./staging/src/k8s.io/kube-proxy
k8s.io/kube-scheduler => ./staging/src/k8s.io/kube-scheduler
k8s.io/kubectl => ./staging/src/k8s.io/kubectl
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fvbommel/sortorder v1.0.1 h1:dSnXLt4mJYH25uDDGa3biZNQsozaUWDSWeKJ0qqFfzE=
github.com/fvbommel/sortorder v1.0.1/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs=
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down Expand Up @@ -590,8 +591,8 @@ k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c h1:GohjlNKauSai7gN4wsJkeZ3WAJx4S
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog/v2 v2.30.0 h1:bUO6drIvCIsvZ/XFgfxoGFQU/a4Qkh0iAlvUR7vlHJw=
k8s.io/klog/v2 v2.30.0/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20211105084753-ee342a809c29 h1:SgxutK76kGA2O/LIjRjoJ2ABggpGJlaJOiLyOdCjEsU=
k8s.io/kube-openapi v0.0.0-20211105084753-ee342a809c29/go.mod h1:X90lRFlqk35/w9FG4WIvZqMPfG3WrZGzdlSaL6uh7rc=
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 h1:E3J9oCLlaobFUqsjG9DfKbP2BmgwBL2p7pn0A3dG9W4=
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65/go.mod h1:sX9MT8g7NVZM5lVL/j8QyCCJe8YSMW30QvGZWaCIDIk=
k8s.io/system-validators v1.6.0 h1:21qaPNdZ+mQrm4qc5shU0T5Eh49t/miFqZsn4sW8Hr0=
k8s.io/system-validators v1.6.0/go.mod h1:bPldcLgkIUK22ALflnsXk8pvkTEndYdNuaHH6gRrl0Q=
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b h1:wxEMGetGMur3J1xuGLQY7GEQYg9bZxKn3tKo5k/eYcs=
Expand Down
6 changes: 6 additions & 0 deletions staging/src/k8s.io/api/admissionregistration/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Rule struct {
}

// ScopeType specifies a scope for a Rule.
// +enum
apelisse marked this conversation as resolved.
Show resolved Hide resolved
type ScopeType string

const (
Expand All @@ -77,6 +78,7 @@ const (
)

// FailurePolicyType specifies a failure policy that defines how unrecognized errors from the admission endpoint are handled.
// +enum
type FailurePolicyType string

const (
Expand All @@ -87,6 +89,7 @@ const (
)

// MatchPolicyType specifies the type of match policy.
// +enum
type MatchPolicyType string

const (
Expand All @@ -97,6 +100,7 @@ const (
)

// SideEffectClass specifies the types of side effects a webhook may have.
// +enum
type SideEffectClass string

const (
Expand Down Expand Up @@ -450,6 +454,7 @@ type MutatingWebhook struct {
}

// ReinvocationPolicyType specifies what type of policy the admission hook uses.
// +enum
type ReinvocationPolicyType string

const (
Expand All @@ -476,6 +481,7 @@ type RuleWithOperations struct {
}

// OperationType specifies an operation for a request.
// +enum
type OperationType string

// The constants should be kept in sync with those defined in k8s.io/kubernetes/pkg/admission/interface.go.
Expand Down
4 changes: 4 additions & 0 deletions staging/src/k8s.io/api/apps/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type StatefulSet struct {
}

// PodManagementPolicyType defines the policy for creating pods under a stateful set.
// +enum
type PodManagementPolicyType string

const (
Expand Down Expand Up @@ -90,6 +91,7 @@ type StatefulSetUpdateStrategy struct {

// StatefulSetUpdateStrategyType is a string enumeration type that enumerates
// all possible update strategies for the StatefulSet controller.
// +enum
type StatefulSetUpdateStrategyType string

const (
Expand Down Expand Up @@ -352,6 +354,7 @@ type DeploymentStrategy struct {
RollingUpdate *RollingUpdateDeployment `json:"rollingUpdate,omitempty" protobuf:"bytes,2,opt,name=rollingUpdate"`
}

// +enum
type DeploymentStrategyType string

const (
Expand Down Expand Up @@ -493,6 +496,7 @@ type DaemonSetUpdateStrategy struct {
RollingUpdate *RollingUpdateDaemonSet `json:"rollingUpdate,omitempty" protobuf:"bytes,2,opt,name=rollingUpdate"`
}

// +enum
type DaemonSetUpdateStrategyType string

const (
Expand Down
1 change: 1 addition & 0 deletions staging/src/k8s.io/api/autoscaling/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ type ScaleStatus struct {
// the types below are used in the alpha metrics annotation

// MetricSourceType indicates the type of metric.
// +enum
type MetricSourceType string

const (
Expand Down
3 changes: 3 additions & 0 deletions staging/src/k8s.io/api/batch/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type JobList struct {
}

// CompletionMode specifies how Pod completions of a Job are tracked.
// +enum
type CompletionMode string

const (
Expand Down Expand Up @@ -288,6 +289,7 @@ type UncountedTerminatedPods struct {
Failed []types.UID `json:"failed,omitempty" protobuf:"bytes,2,rep,name=failed,casttype=k8s.io/apimachinery/pkg/types.UID"`
}

// +enum
type JobConditionType string

// These are valid conditions of a job.
Expand Down Expand Up @@ -412,6 +414,7 @@ type CronJobSpec struct {
// Only one of the following concurrent policies may be specified.
// If none of the following policies is specified, the default one
// is AllowConcurrent.
// +enum
type ConcurrencyPolicy string

const (
Expand Down
2 changes: 2 additions & 0 deletions staging/src/k8s.io/api/certificates/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ type CertificateSigningRequestStatus struct {
}

// RequestConditionType is the type of a CertificateSigningRequestCondition
// +enum
type RequestConditionType string

// Well-known condition types for certificate requests.
Expand Down Expand Up @@ -278,6 +279,7 @@ type CertificateSigningRequestList struct {
// KeyUsage specifies valid usage contexts for keys.
// See: https://tools.ietf.org/html/rfc5280#section-4.2.1.3
// https://tools.ietf.org/html/rfc5280#section-4.2.1.12
// +enum
type KeyUsage string

// Valid key usages
Expand Down