|
| 1 | +/* |
| 2 | +Copyright 2023 Akamai Technologies, Inc. |
| 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 v1beta1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +// LinodeMachineTemplateSpec defines the desired state of LinodeMachineTemplate |
| 24 | +type LinodeMachineTemplateSpec struct { |
| 25 | + // template defines the specification for a LinodeMachine. |
| 26 | + // +required |
| 27 | + Template LinodeMachineTemplateResource `json:"template,omitempty,omitzero"` |
| 28 | +} |
| 29 | + |
| 30 | +// LinodeMachineTemplateStatus defines the observed state of LinodeMachineTemplate |
| 31 | +// It is used to store the status of the LinodeMachineTemplate, such as tags. |
| 32 | +type LinodeMachineTemplateStatus struct { |
| 33 | + // conditions define the current service state of the LinodeMachineTemplate |
| 34 | + // +optional |
| 35 | + // +listType=map |
| 36 | + // +listMapKey=type |
| 37 | + // +patchStrategy=merge |
| 38 | + // +patchMergeKey=type |
| 39 | + Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` |
| 40 | + |
| 41 | + // tags that are currently applied to the LinodeMachineTemplate. |
| 42 | + // +optional |
| 43 | + // +listType=set |
| 44 | + Tags []string `json:"tags,omitempty"` |
| 45 | + |
| 46 | + // firewallID that is currently applied to the LinodeMachineTemplate. |
| 47 | + // +optional |
| 48 | + FirewallID int `json:"firewallID,omitempty"` |
| 49 | +} |
| 50 | + |
| 51 | +// LinodeMachineTemplateResource describes the data needed to create a LinodeMachine from a template. |
| 52 | +type LinodeMachineTemplateResource struct { |
| 53 | + // spec is the specification of the desired behavior of the machine. |
| 54 | + // +required |
| 55 | + Spec LinodeMachineSpec `json:"spec,omitempty,omitzero"` |
| 56 | +} |
| 57 | + |
| 58 | +// +kubebuilder:object:root=true |
| 59 | +// +kubebuilder:storageversion |
| 60 | +// +kubebuilder:resource:path=linodemachinetemplates,scope=Namespaced,categories=cluster-api,shortName=lmt |
| 61 | +// +kubebuilder:subresource:status |
| 62 | +// +kubebuilder:metadata:labels="clusterctl.cluster.x-k8s.io/move-hierarchy=true" |
| 63 | + |
| 64 | +// LinodeMachineTemplate is the Schema for the linodemachinetemplates API |
| 65 | +type LinodeMachineTemplate struct { |
| 66 | + metav1.TypeMeta `json:",inline"` |
| 67 | + // metadata is the standard object's metadata. |
| 68 | + // +optional |
| 69 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 70 | + |
| 71 | + // spec is the desired state of the LinodeMachineTemplate. |
| 72 | + // +optional |
| 73 | + Spec LinodeMachineTemplateSpec `json:"spec,omitzero,omitempty"` |
| 74 | + |
| 75 | + // status is the observed state of the LinodeMachineTemplate. |
| 76 | + // +optional |
| 77 | + Status LinodeMachineTemplateStatus `json:"status,omitempty"` |
| 78 | +} |
| 79 | + |
| 80 | +func (lmt *LinodeMachineTemplate) SetCondition(cond metav1.Condition) { |
| 81 | + if cond.LastTransitionTime.IsZero() { |
| 82 | + cond.LastTransitionTime = metav1.Now() |
| 83 | + } |
| 84 | + for i := range lmt.Status.Conditions { |
| 85 | + if lmt.Status.Conditions[i].Type == cond.Type { |
| 86 | + lmt.Status.Conditions[i] = cond |
| 87 | + |
| 88 | + return |
| 89 | + } |
| 90 | + } |
| 91 | + lmt.Status.Conditions = append(lmt.Status.Conditions, cond) |
| 92 | +} |
| 93 | + |
| 94 | +// +kubebuilder:object:root=true |
| 95 | + |
| 96 | +// LinodeMachineTemplateList contains a list of LinodeMachineTemplate |
| 97 | +type LinodeMachineTemplateList struct { |
| 98 | + metav1.TypeMeta `json:",inline"` |
| 99 | + |
| 100 | + // metadata is the standard object's metadata. |
| 101 | + // +optional |
| 102 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 103 | + |
| 104 | + // items is a list of LinodeMachineTemplate. |
| 105 | + // +optional |
| 106 | + Items []LinodeMachineTemplate `json:"items"` |
| 107 | +} |
| 108 | + |
| 109 | +func init() { |
| 110 | + SchemeBuilder.Register(&LinodeMachineTemplate{}, &LinodeMachineTemplateList{}) |
| 111 | +} |
0 commit comments