Skip to content

Commit 02a7d79

Browse files
committed
CRD versioning - types change
1 parent 9eb0c35 commit 02a7d79

File tree

2 files changed

+66
-1
lines changed
  • staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions

2 files changed

+66
-1
lines changed

staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ type CustomResourceDefinitionSpec struct {
2525
// Group is the group this resource belongs in
2626
Group string
2727
// Version is the version this resource belongs in
28+
// Should be always first item in Versions field if provided.
29+
// Optional, but at least one of Version or Versions must be set.
30+
// Deprecated: Please use `Versions`.
2831
Version string
2932
// Names are the names used to describe this custom resource
3033
Names CustomResourceDefinitionNames
@@ -34,6 +37,27 @@ type CustomResourceDefinitionSpec struct {
3437
Validation *CustomResourceValidation
3538
// Subresources describes the subresources for CustomResources
3639
Subresources *CustomResourceSubresources
40+
// Versions is the list of all supported versions for this resource.
41+
// If Version field is provided, this field is optional.
42+
// Validation: All versions must use the same validation schema for now. i.e., top
43+
// level Validation field is applied to all of these versions.
44+
// Order: The version name will be used to compute the order.
45+
// If the version string is "kube-like", it will sort above non "kube-like" version strings, which are ordered
46+
// lexicographically. "Kube-like" versions start with a "v", then are followed by a number (the major version),
47+
// then optionally the string "alpha" or "beta" and another number (the minor version). These are sorted first
48+
// by GA > beta > alpha, and then by comparing major version, then minor version. An example sorted list of
49+
// versions: v10, v2, v1, v11beta2, v10beta3, v3beta1, v12alpha1, v11alpha2, foo1, foo10.
50+
Versions []CustomResourceDefinitionVersion
51+
}
52+
53+
type CustomResourceDefinitionVersion struct {
54+
// Name is the version name, e.g. “v1”, “v2beta1”, etc.
55+
Name string
56+
// Served is a flag enabling/disabling this version from being served via REST APIs
57+
Served bool
58+
// Storage flags the version as storage version. There must be exactly one flagged
59+
// as storage version.
60+
Storage bool
3761
}
3862

3963
// CustomResourceDefinitionNames indicates the names to serve this CustomResourceDefinition
@@ -115,6 +139,14 @@ type CustomResourceDefinitionStatus struct {
115139
// AcceptedNames are the names that are actually being used to serve discovery
116140
// They may be different than the names in spec.
117141
AcceptedNames CustomResourceDefinitionNames
142+
143+
// StoredVersions are all versions of CustomResources that were ever persisted. Tracking these
144+
// versions allows a migration path for stored versions in etcd. The field is mutable
145+
// so the migration controller can first finish a migration to another version (i.e.
146+
// that no old objects are left in the storage), and then remove the rest of the
147+
// versions from this list.
148+
// None of the versions in this list can be removed from the spec.Versions field.
149+
StoredVersions []string
118150
}
119151

120152
// CustomResourceCleanupFinalizer is the name of the finalizer which will delete instances of

staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/types.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ type CustomResourceDefinitionSpec struct {
2525
// Group is the group this resource belongs in
2626
Group string `json:"group" protobuf:"bytes,1,opt,name=group"`
2727
// Version is the version this resource belongs in
28-
Version string `json:"version" protobuf:"bytes,2,opt,name=version"`
28+
// Should be always first item in Versions field if provided.
29+
// Optional, but at least one of Version or Versions must be set.
30+
// Deprecated: Please use `Versions`.
31+
// +optional
32+
Version string `json:"version,omitempty" protobuf:"bytes,2,opt,name=version"`
2933
// Names are the names used to describe this custom resource
3034
Names CustomResourceDefinitionNames `json:"names" protobuf:"bytes,3,opt,name=names"`
3135
// Scope indicates whether this resource is cluster or namespace scoped. Default is namespaced
@@ -36,6 +40,27 @@ type CustomResourceDefinitionSpec struct {
3640
// Subresources describes the subresources for CustomResources
3741
// +optional
3842
Subresources *CustomResourceSubresources `json:"subresources,omitempty" protobuf:"bytes,6,opt,name=subresources"`
43+
// Versions is the list of all supported versions for this resource.
44+
// If Version field is provided, this field is optional.
45+
// Validation: All versions must use the same validation schema for now. i.e., top
46+
// level Validation field is applied to all of these versions.
47+
// Order: The version name will be used to compute the order.
48+
// If the version string is "kube-like", it will sort above non "kube-like" version strings, which are ordered
49+
// lexicographically. "Kube-like" versions start with a "v", then are followed by a number (the major version),
50+
// then optionally the string "alpha" or "beta" and another number (the minor version). These are sorted first
51+
// by GA > beta > alpha, and then by comparing major version, then minor version. An example sorted list of
52+
// versions: v10, v2, v1, v11beta2, v10beta3, v3beta1, v12alpha1, v11alpha2, foo1, foo10.
53+
Versions []CustomResourceDefinitionVersion `json:"versions,omitempty" protobuf:"bytes,7,rep,name=versions"`
54+
}
55+
56+
type CustomResourceDefinitionVersion struct {
57+
// Name is the version name, e.g. “v1”, “v2beta1”, etc.
58+
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
59+
// Served is a flag enabling/disabling this version from being served via REST APIs
60+
Served bool `json:"served" protobuf:"varint,2,opt,name=served"`
61+
// Storage flags the version as storage version. There must be exactly one
62+
// flagged as storage version.
63+
Storage bool `json:"storage" protobuf:"varint,3,opt,name=storage"`
3964
}
4065

4166
// CustomResourceDefinitionNames indicates the names to serve this CustomResourceDefinition
@@ -117,6 +142,14 @@ type CustomResourceDefinitionStatus struct {
117142
// AcceptedNames are the names that are actually being used to serve discovery
118143
// They may be different than the names in spec.
119144
AcceptedNames CustomResourceDefinitionNames `json:"acceptedNames" protobuf:"bytes,2,opt,name=acceptedNames"`
145+
146+
// StoredVersions are all versions of CustomResources that were ever persisted. Tracking these
147+
// versions allows a migration path for stored versions in etcd. The field is mutable
148+
// so the migration controller can first finish a migration to another version (i.e.
149+
// that no old objects are left in the storage), and then remove the rest of the
150+
// versions from this list.
151+
// None of the versions in this list can be removed from the spec.Versions field.
152+
StoredVersions []string `protobuf:"bytes,3,rep,name=storedVersions"`
120153
}
121154

122155
// CustomResourceCleanupFinalizer is the name of the finalizer which will delete instances of

0 commit comments

Comments
 (0)