forked from k-orc/openstack-resource-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.template
More file actions
186 lines (154 loc) · 7.21 KB
/
Copy pathapi.template
File metadata and controls
186 lines (154 loc) · 7.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
Copyright {{ .Year }} The ORC Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package {{ .APIVersion }}
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// {{ .Name }}Import specifies an existing resource which will be imported instead of
// creating a new one
// +kubebuilder:validation:MinProperties:=1
// +kubebuilder:validation:MaxProperties:=1
type {{ .Name }}Import struct {
// id contains the unique identifier of an existing OpenStack resource. Note
// that when specifying an import by ID, the resource MUST already exist.
// The ORC object will enter an error state if the resource does not exist.
// +optional
// +kubebuilder:validation:Format:=uuid
ID *string `json:"id,omitempty"`
// filter contains a resource query which is expected to return a single
// result. The controller will continue to retry if filter returns no
// results. If filter returns multiple results the controller will set an
// error state and will not continue to retry.
// +optional
Filter *{{ .Name }}Filter `json:"filter,omitempty"`
}
// {{ .Name }}Spec defines the desired state of an ORC object.
// +kubebuilder:validation:XValidation:rule="self.managementPolicy == 'managed' ? has(self.resource) : true",message="resource must be specified when policy is managed"
// +kubebuilder:validation:XValidation:rule="self.managementPolicy == 'managed' ? !has(self.__import__) : true",message="import may not be specified when policy is managed"
// +kubebuilder:validation:XValidation:rule="self.managementPolicy == 'unmanaged' ? !has(self.resource) : true",message="resource may not be specified when policy is unmanaged"
// +kubebuilder:validation:XValidation:rule="self.managementPolicy == 'unmanaged' ? has(self.__import__) : true",message="import must be specified when policy is unmanaged"
// +kubebuilder:validation:XValidation:rule="has(self.managedOptions) ? self.managementPolicy == 'managed' : true",message="managedOptions may only be provided when policy is managed"
{{ range .SpecExtraValidations -}}
// +kubebuilder:validation:XValidation:rule="{{ .Rule }}",message="{{ .Message }}"
{{ end -}}
type {{ .Name }}Spec struct {
{{- if .SpecExtraType }}
{{ .SpecExtraType }} `json:",inline"`
{{ end }}
// import refers to an existing OpenStack resource which will be imported instead of
// creating a new one.
// +optional
Import *{{ .Name }}Import `json:"import,omitempty"`
// resource specifies the desired state of the resource.
//
// resource may not be specified if the management policy is `unmanaged`.
//
// resource must be specified if the management policy is `managed`.
// +optional
Resource *{{ .Name }}ResourceSpec `json:"resource,omitempty"`
// managementPolicy defines how ORC will treat the object. Valid values are
// `managed`: ORC will create, update, and delete the resource; `unmanaged`:
// ORC will import an existing resource, and will not apply updates to it or
// delete it.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="managementPolicy is immutable"
// +kubebuilder:default:=managed
// +optional
ManagementPolicy ManagementPolicy `json:"managementPolicy,omitempty"`
// managedOptions specifies options which may be applied to managed objects.
// +optional
ManagedOptions *ManagedOptions `json:"managedOptions,omitempty"`
// cloudCredentialsRef points to a secret containing OpenStack credentials
// +required
CloudCredentialsRef CloudCredentialsReference `json:"cloudCredentialsRef"`
}
// {{ .Name }}Status defines the observed state of an ORC resource.
type {{ .Name }}Status struct {
// conditions represents the observed status of the object.
// Known .status.conditions.type are: "Available", "Progressing"
//
// Available represents the availability of the OpenStack resource. If it is
// true then the resource is ready for use.
//
// Progressing indicates whether the controller is still attempting to
// reconcile the current state of the OpenStack resource to the desired
// state. Progressing will be False either because the desired state has
// been achieved, or because some terminal error prevents it from ever being
// achieved and the controller is no longer attempting to reconcile. If
// Progressing is True, an observer waiting on the resource should continue
// to wait.
//
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
// id is the unique identifier of the OpenStack resource.
// +optional
ID *string `json:"id,omitempty"`
// resource contains the observed state of the OpenStack resource.
// +optional
Resource *{{ .Name }}ResourceStatus `json:"resource,omitempty"`
{{- if .StatusExtraType }}
{{ .StatusExtraType }} `json:",inline"`
{{- end }}
}
var _ ObjectWithConditions = &{{ .Name }}{}
func (i *{{ .Name }}) GetConditions() []metav1.Condition {
return i.Status.Conditions
}
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:resource:categories=openstack
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="ID",type="string",JSONPath=".status.id",description="Resource ID"
// +kubebuilder:printcolumn:name="Available",type="string",JSONPath=".status.conditions[?(@.type=='Available')].status",description="Availability status of resource"
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[?(@.type=='Available')].message",description="Message describing current availability status"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation"
// {{ .Name }} is the Schema for an ORC resource.
type {{ .Name }} struct {
metav1.TypeMeta `json:",inline"`
// metadata contains the object metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// spec specifies the desired state of the resource.
// +optional
Spec {{ .Name }}Spec `json:"spec,omitempty"`
// status defines the observed state of the resource.
// +optional
Status {{ .Name }}Status `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// {{ .Name }}List contains a list of {{ .Name }}.
type {{ .Name }}List struct {
metav1.TypeMeta `json:",inline"`
// metadata contains the list metadata
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
// items contains a list of {{ .Name }}.
// +required
Items []{{ .Name }} `json:"items"`
}
func (l *{{ .Name }}List) GetItems() []{{ .Name }} {
return l.Items
}
func init() {
SchemeBuilder.Register(&{{ .Name }}{}, &{{ .Name }}List{})
}
func (i *{{ .Name }}) GetCloudCredentialsRef() (*string, *CloudCredentialsReference) {
if i == nil {
return nil, nil
}
return &i.Namespace, &i.Spec.CloudCredentialsRef
}
var _ CloudCredentialsRefProvider = &{{ .Name }}{}