|
| 1 | +/* |
| 2 | +Copyright 2024 Swisscom (Schweiz) AG. |
| 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 v1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +// VLANClaimSpec defines the desired state of VLANClaim |
| 24 | +type VLANClaimSpec struct { |
| 25 | + // The unique VLAN ID (VID) for the NetBox VLAN. If not provided, the operator will claim an available VID. |
| 26 | + //+optional |
| 27 | + //+kubebuilder:validation:Minimum=1 |
| 28 | + //+kubebuilder:validation:Maximum=4094 |
| 29 | + VlanId int `json:"vlanId,omitempty"` |
| 30 | + |
| 31 | + // The desired name for the VLAN in NetBox. If not provided, the operator will generate one. |
| 32 | + //+optional |
| 33 | + Name string `json:"name,omitempty"` |
| 34 | + |
| 35 | + // The NetBox Site where this VLAN should exist |
| 36 | + //+kubebuilder:validation:Required |
| 37 | + Site string `json:"site"` |
| 38 | + |
| 39 | + // The NetBox VLANGroup where this VLAN should be organized. Required if vlanId is not provided. |
| 40 | + //+optional |
| 41 | + VlanGroup string `json:"vlanGroup,omitempty"` |
| 42 | + |
| 43 | + // Description that should be added to the resource in NetBox |
| 44 | + //+optional |
| 45 | + Description string `json:"description,omitempty"` |
| 46 | + |
| 47 | + // Comment that should be added to the resource in NetBox |
| 48 | + //+optional |
| 49 | + Comments string `json:"comments,omitempty"` |
| 50 | + |
| 51 | + // The NetBox Custom Fields that should be added to the resource in NetBox |
| 52 | + //+optional |
| 53 | + CustomFields map[string]string `json:"customFields,omitempty"` |
| 54 | + |
| 55 | + // Defines whether the Resource should be preserved in NetBox when the |
| 56 | + // Kubernetes Resource is deleted. |
| 57 | + //+optional |
| 58 | + PreserveInNetbox bool `json:"preserveInNetbox,omitempty"` |
| 59 | +} |
| 60 | + |
| 61 | +// VLANClaimStatus defines the observed state of VLANClaim |
| 62 | +type VLANClaimStatus struct { |
| 63 | + // The assigned VLAN ID (VID) |
| 64 | + //+optional |
| 65 | + VlanId int `json:"vlanId,omitempty"` |
| 66 | + |
| 67 | + // The name of the Vlan CR created by the VLANClaim Controller |
| 68 | + //+optional |
| 69 | + VlanName string `json:"vlanName,omitempty"` |
| 70 | + |
| 71 | + // Conditions represent the latest available observations of an object's state |
| 72 | + //+optional |
| 73 | + Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` |
| 74 | +} |
| 75 | + |
| 76 | +//+kubebuilder:object:root=true |
| 77 | +//+kubebuilder:subresource:status |
| 78 | +//+kubebuilder:storageversion |
| 79 | +//+kubebuilder:printcolumn:name="VID",type=integer,JSONPath=`.status.vlanId` |
| 80 | +//+kubebuilder:printcolumn:name="Vlan Name",type=string,JSONPath=`.status.vlanName` |
| 81 | +//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status` |
| 82 | +//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` |
| 83 | +//+kubebuilder:resource:shortName=vlc |
| 84 | + |
| 85 | +// VLANClaim is the Schema for the vlanclaims API |
| 86 | +type VLANClaim struct { |
| 87 | + metav1.TypeMeta `json:",inline"` |
| 88 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 89 | + |
| 90 | + Spec VLANClaimSpec `json:"spec,omitempty"` |
| 91 | + Status VLANClaimStatus `json:"status,omitempty"` |
| 92 | +} |
| 93 | + |
| 94 | +func (v *VLANClaim) Conditions() *[]metav1.Condition { |
| 95 | + return &v.Status.Conditions |
| 96 | +} |
| 97 | + |
| 98 | +//+kubebuilder:object:root=true |
| 99 | + |
| 100 | +// VLANClaimList contains a list of VLANClaim |
| 101 | +type VLANClaimList struct { |
| 102 | + metav1.TypeMeta `json:",inline"` |
| 103 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 104 | + Items []VLANClaim `json:"items"` |
| 105 | +} |
| 106 | + |
| 107 | +func init() { |
| 108 | + SchemeBuilder.Register(&VLANClaim{}, &VLANClaimList{}) |
| 109 | +} |
| 110 | + |
| 111 | +var ConditionVlanClaimReadyTrue = metav1.Condition{ |
| 112 | + Type: "Ready", |
| 113 | + Status: "True", |
| 114 | + Reason: "VlanResourceReady", |
| 115 | + Message: "VLAN Resource is ready", |
| 116 | +} |
| 117 | + |
| 118 | +var ConditionVlanClaimReadyFalse = metav1.Condition{ |
| 119 | + Type: "Ready", |
| 120 | + Status: "False", |
| 121 | + Reason: "VlanResourceNotReady", |
| 122 | + Message: "VLAN Resource is not ready", |
| 123 | +} |
| 124 | + |
| 125 | +var ConditionVlanAssignedTrue = metav1.Condition{ |
| 126 | + Type: "VlanAssigned", |
| 127 | + Status: "True", |
| 128 | + Reason: "VlanCRCreated", |
| 129 | + Message: "VLAN VID assigned and Vlan CR created", |
| 130 | +} |
| 131 | + |
| 132 | +var ConditionVlanAssignedFalse = metav1.Condition{ |
| 133 | + Type: "VlanAssigned", |
| 134 | + Status: "False", |
| 135 | + Reason: "VlanCRNotCreated", |
| 136 | + Message: "Failed to assign VID or create Vlan CR", |
| 137 | +} |
0 commit comments