|
| 1 | +/* |
| 2 | +Copyright 2025. |
| 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 v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + corev1 "k8s.io/api/core/v1" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | +) |
| 23 | + |
| 24 | +const ConnectorInstanceConditionReady = "Ready" |
| 25 | + |
| 26 | +// ConnectorInstanceSpec is an immutable snapshot of one Connector replica |
| 27 | +// incarnation. ConnectorInstance is an implementation resource owned by a |
| 28 | +// Connector, not a user-facing identity resource. |
| 29 | +// |
| 30 | +// +kubebuilder:validation:XValidation:rule="has(self.managedTailnetID) != has(self.authKeySecretRef)",message="exactly one of managedTailnetID or authKeySecretRef must be specified" |
| 31 | +type ConnectorInstanceSpec struct { |
| 32 | + // ConnectorRef identifies the owning logical Connector. |
| 33 | + // +required |
| 34 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="connectorRef is immutable" |
| 35 | + ConnectorRef corev1.LocalObjectReference `json:"connectorRef"` |
| 36 | + |
| 37 | + // Slot is the logical replica position served by this incarnation. |
| 38 | + // +kubebuilder:validation:Minimum=0 |
| 39 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="slot is immutable" |
| 40 | + Slot int32 `json:"slot"` |
| 41 | + |
| 42 | + // Revision changes whenever the resolved Connector configuration changes. |
| 43 | + // +required |
| 44 | + // +kubebuilder:validation:MinLength=8 |
| 45 | + // +kubebuilder:validation:MaxLength=64 |
| 46 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="revision is immutable" |
| 47 | + Revision string `json:"revision"` |
| 48 | + |
| 49 | + // ManagedTailnetID selects a Kodiak-managed Ionscale Tailnet. Empty means |
| 50 | + // the control plane is externally managed. |
| 51 | + // +optional |
| 52 | + // +kubebuilder:validation:Pattern=`^[0-9]+$` |
| 53 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="managedTailnetID is immutable" |
| 54 | + ManagedTailnetID string `json:"managedTailnetID,omitempty"` |
| 55 | + |
| 56 | + // LoginURL is the Tailscale protocol endpoint. |
| 57 | + // +optional |
| 58 | + // +kubebuilder:validation:Pattern=`^https://[^[:space:]]+$` |
| 59 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="loginURL is immutable" |
| 60 | + LoginURL string `json:"loginURL,omitempty"` |
| 61 | + |
| 62 | + // AuthKeySecretRef selects an externally managed bootstrap key. |
| 63 | + // It is mutually exclusive with managedTailnetID. |
| 64 | + // +optional |
| 65 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="authKeySecretRef is immutable" |
| 66 | + AuthKeySecretRef *corev1.SecretKeySelector `json:"authKeySecretRef,omitempty"` |
| 67 | + |
| 68 | + // Tags are the policy identity requested for the external device. |
| 69 | + // +optional |
| 70 | + // +listType=set |
| 71 | + Tags []string `json:"tags,omitempty"` |
| 72 | + |
| 73 | + // AdvertiseRoutes are the exact prefixes served by this instance. |
| 74 | + // +required |
| 75 | + // +listType=set |
| 76 | + AdvertiseRoutes []string `json:"advertiseRoutes"` |
| 77 | + |
| 78 | + // Image is the stock Tailscale container image. |
| 79 | + // +required |
| 80 | + Image string `json:"image"` |
| 81 | + |
| 82 | + // Workload is the resolved Pod configuration. |
| 83 | + // +optional |
| 84 | + Workload ConnectorWorkloadSpec `json:"workload,omitempty"` |
| 85 | +} |
| 86 | + |
| 87 | +// ConnectorInstanceStatus records the external child currently associated |
| 88 | +// with one Pod incarnation. It never contains tailscaled private state. |
| 89 | +type ConnectorInstanceStatus struct { |
| 90 | + // ObservedGeneration is the latest reconciled generation. |
| 91 | + // +optional |
| 92 | + ObservedGeneration int64 `json:"observedGeneration,omitempty"` |
| 93 | + |
| 94 | + // PodName is the controller-owned Pod for this incarnation. |
| 95 | + // +optional |
| 96 | + PodName string `json:"podName,omitempty"` |
| 97 | + |
| 98 | + // PodUID disambiguates a recreated Pod with the same name. |
| 99 | + // +optional |
| 100 | + PodUID string `json:"podUID,omitempty"` |
| 101 | + |
| 102 | + // RequestedHostname is the unique correlation key presented to the |
| 103 | + // control plane during registration. |
| 104 | + // +optional |
| 105 | + RequestedHostname string `json:"requestedHostname,omitempty"` |
| 106 | + |
| 107 | + // Device is the last external control-plane observation. |
| 108 | + // +optional |
| 109 | + Device ConnectorDeviceStatus `json:"device,omitempty"` |
| 110 | + |
| 111 | + // Conditions reports provisioning and route readiness. |
| 112 | + // +optional |
| 113 | + // +listType=map |
| 114 | + // +listMapKey=type |
| 115 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 116 | +} |
| 117 | + |
| 118 | +// +kubebuilder:object:root=true |
| 119 | +// +kubebuilder:subresource:status |
| 120 | +// +kubebuilder:resource:shortName={"kconnectorinstance"} |
| 121 | +// +kubebuilder:printcolumn:name="CONNECTOR",type="string",JSONPath=".spec.connectorRef.name" |
| 122 | +// +kubebuilder:printcolumn:name="SLOT",type="integer",JSONPath=".spec.slot" |
| 123 | +// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" |
| 124 | +// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" |
| 125 | + |
| 126 | +// ConnectorInstance is an internal lifecycle record for one replaceable |
| 127 | +// Connector device and its Pod. |
| 128 | +type ConnectorInstance struct { |
| 129 | + metav1.TypeMeta `json:",inline"` |
| 130 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 131 | + |
| 132 | + Spec ConnectorInstanceSpec `json:"spec"` |
| 133 | + Status ConnectorInstanceStatus `json:"status,omitempty"` |
| 134 | +} |
| 135 | + |
| 136 | +// +kubebuilder:object:root=true |
| 137 | + |
| 138 | +// ConnectorInstanceList contains a list of ConnectorInstance. |
| 139 | +type ConnectorInstanceList struct { |
| 140 | + metav1.TypeMeta `json:",inline"` |
| 141 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 142 | + Items []ConnectorInstance `json:"items"` |
| 143 | +} |
| 144 | + |
| 145 | +func init() { |
| 146 | + SchemeBuilder.Register(&ConnectorInstance{}, &ConnectorInstanceList{}) |
| 147 | +} |
0 commit comments