1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1alpha1 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 ) 22 23 // +genclient 24 // +genclient:nonNamespaced 25 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 26 27 // Storage version of a specific resource. 28 type StorageVersion struct { 29 metav1.TypeMeta `json:",inline"` 30 // The name is <group>.<resource>. 31 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 32 33 // Spec is an empty spec. It is here to comply with Kubernetes API style. 34 Spec StorageVersionSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"` 35 36 // API server instances report the version they can decode and the version they 37 // encode objects to when persisting objects in the backend. 38 Status StorageVersionStatus `json:"status" protobuf:"bytes,3,opt,name=status"` 39 } 40 41 // StorageVersionSpec is an empty spec. 42 type StorageVersionSpec struct{} 43 44 // API server instances report the versions they can decode and the version they 45 // encode objects to when persisting objects in the backend. 46 type StorageVersionStatus struct { 47 // The reported versions per API server instance. 48 // +optional 49 // +listType=map 50 // +listMapKey=apiServerID 51 StorageVersions []ServerStorageVersion `json:"storageVersions,omitempty" protobuf:"bytes,1,opt,name=storageVersions"` 52 // If all API server instances agree on the same encoding storage version, 53 // then this field is set to that version. Otherwise this field is left empty. 54 // API servers should finish updating its storageVersionStatus entry before 55 // serving write operations, so that this field will be in sync with the reality. 56 // +optional 57 CommonEncodingVersion *string `json:"commonEncodingVersion,omitempty" protobuf:"bytes,2,opt,name=commonEncodingVersion"` 58 59 // The latest available observations of the storageVersion's state. 60 // +optional 61 // +listType=map 62 // +listMapKey=type 63 Conditions []StorageVersionCondition `json:"conditions,omitempty" protobuf:"bytes,3,opt,name=conditions"` 64 } 65 66 // An API server instance reports the version it can decode and the version it 67 // encodes objects to when persisting objects in the backend. 68 type ServerStorageVersion struct { 69 // The ID of the reporting API server. 70 APIServerID string `json:"apiServerID,omitempty" protobuf:"bytes,1,opt,name=apiServerID"` 71 72 // The API server encodes the object to this version when persisting it in 73 // the backend (e.g., etcd). 74 EncodingVersion string `json:"encodingVersion,omitempty" protobuf:"bytes,2,opt,name=encodingVersion"` 75 76 // The API server can decode objects encoded in these versions. 77 // The encodingVersion must be included in the decodableVersions. 78 // +listType=set 79 DecodableVersions []string `json:"decodableVersions,omitempty" protobuf:"bytes,3,opt,name=decodableVersions"` 80 81 // The API server can serve these versions. 82 // DecodableVersions must include all ServedVersions. 83 // +listType=set 84 ServedVersions []string `json:"servedVersions,omitempty" protobuf:"bytes,4,opt,name=servedVersions"` 85 } 86 87 type StorageVersionConditionType string 88 89 const ( 90 // Indicates that encoding storage versions reported by all servers are equal. 91 AllEncodingVersionsEqual StorageVersionConditionType = "AllEncodingVersionsEqual" 92 ) 93 94 type ConditionStatus string 95 96 const ( 97 ConditionTrue ConditionStatus = "True" 98 ConditionFalse ConditionStatus = "False" 99 ConditionUnknown ConditionStatus = "Unknown" 100 ) 101 102 // Describes the state of the storageVersion at a certain point. 103 type StorageVersionCondition struct { 104 // Type of the condition. 105 // +required 106 Type StorageVersionConditionType `json:"type" protobuf:"bytes,1,opt,name=type"` 107 // Status of the condition, one of True, False, Unknown. 108 // +required 109 Status ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status"` 110 // If set, this represents the .metadata.generation that the condition was set based upon. 111 // +optional 112 ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,3,opt,name=observedGeneration"` 113 // Last time the condition transitioned from one status to another. 114 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"` 115 // The reason for the condition's last transition. 116 // +required 117 Reason string `json:"reason" protobuf:"bytes,5,opt,name=reason"` 118 // A human readable message indicating details about the transition. 119 // +required 120 Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"` 121 } 122 123 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 124 125 // A list of StorageVersions. 126 type StorageVersionList struct { 127 metav1.TypeMeta `json:",inline"` 128 // Standard list metadata. 129 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 130 // +optional 131 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 132 // Items holds a list of StorageVersion 133 Items []StorageVersion `json:"items" protobuf:"bytes,2,rep,name=items"` 134 } 135