Skip to content

Commit 663ba86

Browse files
authored
Merge pull request #2203 from shiftstack/resource-generator
🌱 ORC: Generate common parts of resource API
2 parents 8fc78f1 + e4e85c3 commit 663ba86

File tree

13 files changed

+558
-182
lines changed

13 files changed

+558
-182
lines changed

orc/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ modules:
5353
cd hack/codegen; go work sync; go mod tidy
5454

5555
.PHONY: generate
56-
generate: modules manifests generate-controller-gen generate-codegen generate-go
56+
generate: generate-resources generate-controller-gen generate-codegen generate-go modules manifests
57+
58+
.PHONY: generate-resources
59+
generate-resources:
60+
go run ./cmd/resource-generator
5761

5862
.PHONY: generate-controller-gen
5963
generate-controller-gen: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.

orc/api/v1alpha1/image_types.go

Lines changed: 1 addition & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ limitations under the License.
1616

1717
package v1alpha1
1818

19-
import (
20-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21-
)
22-
2319
// GlanceTag is the name of the go field tag in properties structs used to specify the Glance property name.
2420
const GlanceTag = "glance"
2521

@@ -318,65 +314,6 @@ type ImageFilter struct {
318314
Name *string `json:"name,omitempty"`
319315
}
320316

321-
// ImageImport specifies an existing image which will be imported instead of
322-
// creating a new image
323-
// +kubebuilder:validation:MinProperties:=1
324-
// +kubebuilder:validation:MaxProperties:=1
325-
type ImageImport struct {
326-
// ID contains the unique identifier of an existing Glance image. Note that
327-
// when specifying an image import by ID, the image MUST already exist. The
328-
// Image will enter an error state if the image does not exist.
329-
// +optional
330-
// +kubebuilder:validation:Format:=uuid
331-
ID *string `json:"id,omitempty"`
332-
333-
// Filter contains an image query which is expected to return a single
334-
// result. The controller will continue to retry if filter returns no
335-
// results. If filter returns multiple results the controller will set an
336-
// error state and will not continue to retry.
337-
// +optional
338-
Filter *ImageFilter `json:"filter,omitempty"`
339-
}
340-
341-
// ImageSpec defines the desired state of an Image.
342-
// +kubebuilder:validation:XValidation:rule="self.managementPolicy == 'managed' ? has(self.resource) : true",message="resource must be specified when policy is managed"
343-
// +kubebuilder:validation:XValidation:rule="self.managementPolicy == 'managed' ? !has(self.__import__) : true",message="import may not be specified when policy is managed"
344-
// +kubebuilder:validation:XValidation:rule="self.managementPolicy == 'unmanaged' ? !has(self.resource) : true",message="resource may not be specified when policy is unmanaged"
345-
// +kubebuilder:validation:XValidation:rule="self.managementPolicy == 'unmanaged' ? has(self.__import__) : true",message="import must be specified when policy is unmanaged"
346-
// +kubebuilder:validation:XValidation:rule="has(self.managedOptions) ? self.managementPolicy == 'managed' : true",message="managedOptions may only be provided when policy is managed"
347-
// +kubebuilder:validation:XValidation:rule="!has(self.__import__) ? has(self.resource.content) : true",message="resource content must be specified when not importing"
348-
type ImageSpec struct {
349-
// Import refers to an existing image which will be imported instead of
350-
// creating a new image.
351-
// +optional
352-
Import *ImageImport `json:"import,omitempty"`
353-
354-
// Resource specifies the desired state of the Glance image.
355-
//
356-
// Resource may not be specified if the management policy is `unmanaged`.
357-
//
358-
// Resource must be specified when the management policy is `managed`.
359-
// +optional
360-
Resource *ImageResourceSpec `json:"resource,omitempty"`
361-
362-
// ManagementPolicy defines how ORC will treat the object. Valid values are
363-
// `managed`: ORC will create, update, and delete the resource; `unmanaged`:
364-
// ORC will import an existing image, and will not apply updates to it or
365-
// delete it.
366-
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="managementPolicy is immutable"
367-
// +kubebuilder:default:=managed
368-
// +optional
369-
ManagementPolicy ManagementPolicy `json:"managementPolicy,omitempty"`
370-
371-
// ManagedOptions specifies options which may be applied to managed objects.
372-
// +optional
373-
ManagedOptions *ManagedOptions `json:"managedOptions,omitempty"`
374-
375-
// CloudCredentialsRef points to a secret containing OpenStack credentials
376-
// +kubebuilder:validation:Required
377-
CloudCredentialsRef CloudCredentialsReference `json:"cloudCredentialsRef"`
378-
}
379-
380317
// ImageResourceStatus represents the observed state of a Glance image
381318
type ImageResourceStatus struct {
382319
// Status is the image status as reported by Glance
@@ -400,82 +337,8 @@ type ImageResourceStatus struct {
400337
VirtualSizeB *int64 `json:"virtualSizeB,omitempty"`
401338
}
402339

403-
// ImageStatus defines the observed state of an Image.
404-
type ImageStatus struct {
405-
// Conditions represents the observed status of the object.
406-
// Known .status.conditions.type are: "Available", "Progressing"
407-
//
408-
// Available represents the availability of the Glance image. If it is
409-
// true then the image is ready for use in Glance, and its hash has been
410-
// verified.
411-
//
412-
// Progressing indicates the state of the Glance image does not currently
413-
// reflect the desired state, but that reconciliation is progressing.
414-
// Progressing will be False either because the desired state has been
415-
// achieved, or some terminal error prevents it from being achieved and the
416-
// controller is no longer attempting to reconcile.
417-
//
418-
// +patchMergeKey=type
419-
// +patchStrategy=merge
420-
// +listType=map
421-
// +listMapKey=type
422-
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
423-
424-
// ID is the unique identifier of the Glance image
425-
// +optional
426-
ID *string `json:"id,omitempty"`
427-
428-
// Resource contains the observed state of the Glance image
429-
// +optional
430-
Resource *ImageResourceStatus `json:"resource,omitempty"`
431-
340+
type ImageStatusExtra struct {
432341
// DownloadAttempts is the number of times the controller has attempted to download the image contents
433342
// +optional
434343
DownloadAttempts *int `json:"downloadAttempts,omitempty"`
435344
}
436-
437-
var _ ObjectWithConditions = &Image{}
438-
439-
func (i *Image) GetConditions() []metav1.Condition {
440-
return i.Status.Conditions
441-
}
442-
443-
// +genclient
444-
// +kubebuilder:object:root=true
445-
// +kubebuilder:subresource:status
446-
// +kubebuilder:printcolumn:name="ID",type="string",JSONPath=".status.id",description="Glance image ID"
447-
// +kubebuilder:printcolumn:name="Available",type="string",JSONPath=".status.conditions[?(@.type=='Available')].status",description="Availability status of image"
448-
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[?(@.type=='Available')].message",description="Message describing current availability status"
449-
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation"
450-
451-
// Image is the Schema for the ORC images API.
452-
type Image struct {
453-
metav1.TypeMeta `json:",inline"`
454-
metav1.ObjectMeta `json:"metadata,omitempty"`
455-
456-
Spec ImageSpec `json:"spec,omitempty"`
457-
Status ImageStatus `json:"status,omitempty"`
458-
}
459-
460-
// +kubebuilder:object:root=true
461-
462-
// ImageList contains a list of Image.
463-
type ImageList struct {
464-
metav1.TypeMeta `json:",inline"`
465-
metav1.ListMeta `json:"metadata,omitempty"`
466-
Items []Image `json:"items"`
467-
}
468-
469-
func init() {
470-
SchemeBuilder.Register(&Image{}, &ImageList{})
471-
}
472-
473-
func (i *Image) GetCloudCredentialsRef() (*string, *CloudCredentialsReference) {
474-
if i == nil {
475-
return nil, nil
476-
}
477-
478-
return &i.Namespace, &i.Spec.CloudCredentialsRef
479-
}
480-
481-
var _ CloudCredentialsRefProvider = &Image{}

orc/api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 19 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

orc/api/v1alpha1/zz_generated.image-resource.go

Lines changed: 160 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

0 commit comments

Comments
 (0)