|
| 1 | +/* |
| 2 | +Copyright 2024 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 tree |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + "k8s.io/apimachinery/pkg/runtime" |
| 22 | + "k8s.io/apimachinery/pkg/types" |
| 23 | + |
| 24 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 25 | +) |
| 26 | + |
| 27 | +// NodeObject represent a node in the tree which doesn't correspond to Cluster, MachineDeployment, Machine etc. |
| 28 | +// An example of NodeObject are GroupNodes, which are used e.g. to represent a set of Machines. |
| 29 | +// Note: NodeObject implements condition getter and setter interfaces as well as the minimal set of methods |
| 30 | +// usually existing on Kubernetes objects. |
| 31 | +type NodeObject struct { |
| 32 | + metav1.TypeMeta |
| 33 | + metav1.ObjectMeta |
| 34 | + Status NodeStatus |
| 35 | +} |
| 36 | + |
| 37 | +// NodeStatus is the status of a node object. |
| 38 | +type NodeStatus struct { |
| 39 | + Conditions clusterv1.Conditions |
| 40 | + V1Beta2 *NodeObjectV1Beta2Status |
| 41 | +} |
| 42 | + |
| 43 | +// NodeObjectV1Beta2Status is the v1Beta2 status of a node object. |
| 44 | +type NodeObjectV1Beta2Status struct { |
| 45 | + Conditions []metav1.Condition |
| 46 | +} |
| 47 | + |
| 48 | +// GetConditions returns the set of conditions for this object. |
| 49 | +func (o *NodeObject) GetConditions() clusterv1.Conditions { |
| 50 | + return o.Status.Conditions |
| 51 | +} |
| 52 | + |
| 53 | +// SetConditions sets the conditions on this object. |
| 54 | +func (o *NodeObject) SetConditions(conditions clusterv1.Conditions) { |
| 55 | + o.Status.Conditions = conditions |
| 56 | +} |
| 57 | + |
| 58 | +// GetV1Beta2Conditions returns the set of conditions for this object. |
| 59 | +func (o *NodeObject) GetV1Beta2Conditions() []metav1.Condition { |
| 60 | + if o.Status.V1Beta2 == nil { |
| 61 | + return nil |
| 62 | + } |
| 63 | + return o.Status.V1Beta2.Conditions |
| 64 | +} |
| 65 | + |
| 66 | +// SetV1Beta2Conditions sets conditions for an API object. |
| 67 | +func (o *NodeObject) SetV1Beta2Conditions(conditions []metav1.Condition) { |
| 68 | + if o.Status.V1Beta2 == nil && conditions != nil { |
| 69 | + o.Status.V1Beta2 = &NodeObjectV1Beta2Status{} |
| 70 | + } |
| 71 | + o.Status.V1Beta2.Conditions = conditions |
| 72 | +} |
| 73 | + |
| 74 | +// GetUID returns object's UID. |
| 75 | +func (o *NodeObject) GetUID() types.UID { |
| 76 | + return o.UID |
| 77 | +} |
| 78 | + |
| 79 | +// SetUID sets object's UID. |
| 80 | +func (o *NodeObject) SetUID(uid types.UID) { |
| 81 | + o.UID = uid |
| 82 | +} |
| 83 | + |
| 84 | +// GetCreationTimestamp returns object's CreationTimestamp. |
| 85 | +func (o *NodeObject) GetCreationTimestamp() metav1.Time { |
| 86 | + return o.CreationTimestamp |
| 87 | +} |
| 88 | + |
| 89 | +// SetCreationTimestamp sets object's CreationTimestamp. |
| 90 | +func (o *NodeObject) SetCreationTimestamp(timestamp metav1.Time) { |
| 91 | + o.CreationTimestamp = timestamp |
| 92 | +} |
| 93 | + |
| 94 | +// GetDeletionTimestamp returns object's DeletionTimestamp. |
| 95 | +func (o *NodeObject) GetDeletionTimestamp() *metav1.Time { |
| 96 | + return o.DeletionTimestamp |
| 97 | +} |
| 98 | + |
| 99 | +// SetDeletionTimestamp sets object's DeletionTimestamp. |
| 100 | +func (o *NodeObject) SetDeletionTimestamp(timestamp *metav1.Time) { |
| 101 | + o.DeletionTimestamp = timestamp |
| 102 | +} |
| 103 | + |
| 104 | +// GetOwnerReferences returns object's OwnerReferences. |
| 105 | +func (o *NodeObject) GetOwnerReferences() []metav1.OwnerReference { |
| 106 | + return o.OwnerReferences |
| 107 | +} |
| 108 | + |
| 109 | +// SetOwnerReferences sets object's OwnerReferences. |
| 110 | +func (o *NodeObject) SetOwnerReferences(references []metav1.OwnerReference) { |
| 111 | + o.OwnerReferences = references |
| 112 | +} |
| 113 | + |
| 114 | +// GetManagedFields returns object's ManagedFields. |
| 115 | +func (o *NodeObject) GetManagedFields() []metav1.ManagedFieldsEntry { |
| 116 | + return o.ManagedFields |
| 117 | +} |
| 118 | + |
| 119 | +// SetManagedFields sets object's ManagedFields. |
| 120 | +func (o *NodeObject) SetManagedFields(managedFields []metav1.ManagedFieldsEntry) { |
| 121 | + o.ManagedFields = managedFields |
| 122 | +} |
| 123 | + |
| 124 | +// DeepCopyObject returns a deep copy of the object. |
| 125 | +func (o *NodeObject) DeepCopyObject() runtime.Object { |
| 126 | + panic("implement me") |
| 127 | +} |
0 commit comments