1/*
2Copyright 2017 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package v1
18
19import (
20	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21)
22
23type (
24	ConditionStatus   string
25	CarpConditionType string
26	CarpPhase         string
27	RestartPolicy     string
28)
29
30// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
31
32// Carp is a collection of containers, used as either input (create, update) or as output (list, get).
33type Carp struct {
34	metav1.TypeMeta `json:",inline"`
35	// Standard object's metadata.
36	// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
37	// +optional
38	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
39
40	// Specification of the desired behavior of the carp.
41	// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
42	// +optional
43	Spec CarpSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
44
45	// Most recently observed status of the carp.
46	// This data may not be up to date.
47	// Populated by the system.
48	// Read-only.
49	// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
50	// +optional
51	Status CarpStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
52}
53
54// CarpStatus represents information about the status of a carp. Status may trail the actual
55// state of a system.
56type CarpStatus struct {
57	// Current condition of the carp.
58	// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-phase
59	// +optional
60	Phase CarpPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase,casttype=CarpPhase"`
61	// Current service state of carp.
62	// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-conditions
63	// +optional
64	Conditions []CarpCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,2,rep,name=conditions"`
65	// A human readable message indicating details about why the carp is in this condition.
66	// +optional
67	Message string `json:"message,omitempty" protobuf:"bytes,3,opt,name=message"`
68	// A brief CamelCase message indicating details about why the carp is in this state.
69	// e.g. 'DiskPressure'
70	// +optional
71	Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
72
73	// IP address of the host to which the carp is assigned. Empty if not yet scheduled.
74	// +optional
75	HostIP string `json:"hostIP,omitempty" protobuf:"bytes,5,opt,name=hostIP"`
76	// IP address allocated to the carp. Routable at least within the cluster.
77	// Empty if not yet allocated.
78	// +optional
79	CarpIP string `json:"carpIP,omitempty" protobuf:"bytes,6,opt,name=carpIP"`
80
81	// RFC 3339 date and time at which the object was acknowledged by the Kubelet.
82	// This is before the Kubelet pulled the container image(s) for the carp.
83	// +optional
84	StartTime *metav1.Time `json:"startTime,omitempty" protobuf:"bytes,7,opt,name=startTime"`
85}
86
87type CarpCondition struct {
88	// Type is the type of the condition.
89	// Currently only Ready.
90	// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-conditions
91	Type CarpConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=CarpConditionType"`
92	// Status is the status of the condition.
93	// Can be True, False, Unknown.
94	// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-conditions
95	Status ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=ConditionStatus"`
96	// Last time we probed the condition.
97	// +optional
98	LastProbeTime metav1.Time `json:"lastProbeTime,omitempty" protobuf:"bytes,3,opt,name=lastProbeTime"`
99	// Last time the condition transitioned from one status to another.
100	// +optional
101	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"`
102	// Unique, one-word, CamelCase reason for the condition's last transition.
103	// +optional
104	Reason string `json:"reason,omitempty" protobuf:"bytes,5,opt,name=reason"`
105	// Human-readable message indicating details about last transition.
106	// +optional
107	Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
108}
109
110// CarpSpec is a description of a carp
111type CarpSpec struct {
112	// Restart policy for all containers within the carp.
113	// One of Always, OnFailure, Never.
114	// Default to Always.
115	// More info: http://kubernetes.io/docs/user-guide/carp-states#restartpolicy
116	// +optional
117	RestartPolicy RestartPolicy `json:"restartPolicy,omitempty" protobuf:"bytes,3,opt,name=restartPolicy,casttype=RestartPolicy"`
118	// Optional duration in seconds the carp needs to terminate gracefully. May be decreased in delete request.
119	// Value must be non-negative integer. The value zero indicates delete immediately.
120	// If this value is nil, the default grace period will be used instead.
121	// The grace period is the duration in seconds after the processes running in the carp are sent
122	// a termination signal and the time when the processes are forcibly halted with a kill signal.
123	// Set this value longer than the expected cleanup time for your process.
124	// Defaults to 30 seconds.
125	// +optional
126	TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
127	// Optional duration in seconds the carp may be active on the node relative to
128	// StartTime before the system will actively try to mark it failed and kill associated containers.
129	// Value must be a positive integer.
130	// +optional
131	ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds,omitempty" protobuf:"varint,5,opt,name=activeDeadlineSeconds"`
132	// NodeSelector is a selector which must be true for the carp to fit on a node.
133	// Selector which must match a node's labels for the carp to be scheduled on that node.
134	// More info: http://kubernetes.io/docs/user-guide/node-selection/README
135	// +optional
136	NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"bytes,7,rep,name=nodeSelector"`
137
138	// ServiceAccountName is the name of the ServiceAccount to use to run this carp.
139	// More info: https://git.k8s.io/community/contributors/design-proposals/auth/service_accounts.md
140	// +optional
141	ServiceAccountName string `json:"serviceAccountName,omitempty" protobuf:"bytes,8,opt,name=serviceAccountName"`
142	// DeprecatedServiceAccount is a depreciated alias for ServiceAccountName.
143	// Deprecated: Use serviceAccountName instead.
144	// +k8s:conversion-gen=false
145	// +optional
146	DeprecatedServiceAccount string `json:"serviceAccount,omitempty" protobuf:"bytes,9,opt,name=serviceAccount"`
147
148	// NodeName is a request to schedule this carp onto a specific node. If it is non-empty,
149	// the scheduler simply schedules this carp onto that node, assuming that it fits resource
150	// requirements.
151	// +optional
152	NodeName string `json:"nodeName,omitempty" protobuf:"bytes,10,opt,name=nodeName"`
153	// Host networking requested for this carp. Use the host's network namespace.
154	// If this option is set, the ports that will be used must be specified.
155	// Default to false.
156	// +k8s:conversion-gen=false
157	// +optional
158	HostNetwork bool `json:"hostNetwork,omitempty" protobuf:"varint,11,opt,name=hostNetwork"`
159	// Use the host's pid namespace.
160	// Optional: Default to false.
161	// +k8s:conversion-gen=false
162	// +optional
163	HostPID bool `json:"hostPID,omitempty" protobuf:"varint,12,opt,name=hostPID"`
164	// Use the host's ipc namespace.
165	// Optional: Default to false.
166	// +k8s:conversion-gen=false
167	// +optional
168	HostIPC bool `json:"hostIPC,omitempty" protobuf:"varint,13,opt,name=hostIPC"`
169	// Specifies the hostname of the Carp
170	// If not specified, the carp's hostname will be set to a system-defined value.
171	// +optional
172	Hostname string `json:"hostname,omitempty" protobuf:"bytes,16,opt,name=hostname"`
173	// If specified, the fully qualified Carp hostname will be "<hostname>.<subdomain>.<carp namespace>.svc.<cluster domain>".
174	// If not specified, the carp will not have a domainname at all.
175	// +optional
176	Subdomain string `json:"subdomain,omitempty" protobuf:"bytes,17,opt,name=subdomain"`
177	// If specified, the carp will be dispatched by specified scheduler.
178	// If not specified, the carp will be dispatched by default scheduler.
179	// +optional
180	SchedulerName string `json:"schedulername,omitempty" protobuf:"bytes,19,opt,name=schedulername"`
181}
182
183// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
184
185// CarpList is a list of Carps.
186type CarpList struct {
187	metav1.TypeMeta `json:",inline"`
188	// Standard list metadata.
189	// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
190	// +optional
191	metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
192
193	// List of carps.
194	// More info: http://kubernetes.io/docs/user-guide/carps
195	Items []Carp `json:"items" protobuf:"bytes,2,rep,name=items"`
196}
197