From 01942dddb96dee0046ae4e9bccbcded36f69d77a Mon Sep 17 00:00:00 2001 From: Francesco Cheinasso Date: Tue, 10 Oct 2023 16:19:19 +0200 Subject: [PATCH] External Network: Connection API --- apis/networking/v1alpha1/connection_types.go | 91 +++++++---------- .../v1alpha1/zz_generated.deepcopy.go | 42 ++------ .../crds/networking.liqo.io_connections.yaml | 99 ++++++------------- 3 files changed, 76 insertions(+), 156 deletions(-) diff --git a/apis/networking/v1alpha1/connection_types.go b/apis/networking/v1alpha1/connection_types.go index 3b9d5cdbc1..c46c47cc8c 100644 --- a/apis/networking/v1alpha1/connection_types.go +++ b/apis/networking/v1alpha1/connection_types.go @@ -38,21 +38,33 @@ var ConnectionGroupVersionResource = GroupVersion.WithResource(ConnectionResourc // ConnectionType represents the type of a connection. type ConnectionType string +// ConnectionStatusValue represents the status of a connection. +type ConnectionStatusValue string + +// ConnectionStatusMessage represents the message of a connection. +type ConnectionStatusMessage string + const ( // ConnectionTypeServer represents a server connection. ConnectionTypeServer ConnectionType = "Server" // ConnectionTypeClient represents a client connection. ConnectionTypeClient ConnectionType = "Client" -) -// PingSpec defines the desired state of Ping. -type PingSpec struct { - // Enabled specifies whether the ping is enabled or not. - // +kubebuilder:default=true - Enabled *bool `json:"enabled,omitempty"` - // Endpoint specifies the endpoint to ping. - Endpoint EndpointStatus `json:"endpoint,omitempty"` -} + // Connected used when the connection is up and running. + Connected ConnectionStatusValue = "Connected" + // ConnectedMessage human-readable info when the vpn connection is in "connected" state. + ConnectedMessage ConnectionStatusMessage = "VPN connection established" + + // Connecting used as temporary status while waiting for the vpn tunnel to come up. + Connecting ConnectionStatusValue = "Connecting" + // ConnectingMessage human-readable info when the vpn is in "connecting" state. + ConnectingMessage ConnectionStatusMessage = "Waiting VPN connection to be established" + + // ConnectionError used to se the status in case of errors. + ConnectionError ConnectionStatusValue = "Error" + // ConnectionErrorMessage is the message sent when a connection error occurs. + ConnectionErrorMessage ConnectionStatusMessage = "No network connectivity towards remote cluster" +) // ConnectionSpec defines the desired state of Connection. type ConnectionSpec struct { @@ -61,62 +73,33 @@ type ConnectionSpec struct { Type ConnectionType `json:"type"` // GatewayRef specifies the reference to the gateway. GatewayRef corev1.ObjectReference `json:"gatewayRef"` - // Ping specifies the ping configuration. - Ping PingSpec `json:"ping,omitempty"` } -// ConnectionConditionType represents different conditions that a connection could assume. -type ConnectionConditionType string - -const ( - // ConnectionConditionEstablished represents a connection that is established. - ConnectionConditionEstablished ConnectionConditionType = "Established" - // ConnectionConditionPending represents a connection that is pending. - ConnectionConditionPending ConnectionConditionType = "Pending" - // ConnectionConditionDenied represents a connection that is denied. - ConnectionConditionDenied ConnectionConditionType = "Denied" - // ConnectionConditionError represents a connection that is in error. - ConnectionConditionError ConnectionConditionType = "Error" -) - -// ConnectionConditionStatusType represents the status of a connection condition. -type ConnectionConditionStatusType string - -const ( - // ConnectionConditionStatusTrue represents a connection condition that is true. - ConnectionConditionStatusTrue ConnectionConditionStatusType = "True" - // ConnectionConditionStatusFalse represents a connection condition that is false. - ConnectionConditionStatusFalse ConnectionConditionStatusType = "False" - // ConnectionConditionStatusUnknown represents a connection condition that is unknown. - ConnectionConditionStatusUnknown ConnectionConditionStatusType = "Unknown" -) - -// ConnectionCondition contains details about state of the connection. -type ConnectionCondition struct { - // Type of the connection condition. - // +kubebuilder:validation:Enum="Established" - Type ConnectionConditionType `json:"type"` - // Status of the condition. - // +kubebuilder:validation:Enum="True";"False";"Unknown" - // +kubebuilder:default="Unknown" - Status ConnectionConditionStatusType `json:"status"` - // LastTransitionTime -> timestamp for when the condition last transitioned from one status to another. - LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` - // Reason -> Machine-readable, UpperCamelCase text indicating the reason for the condition's last transition. - Reason string `json:"reason,omitempty"` - // Message -> Human-readable message indicating details about the last status transition. - Message string `json:"message,omitempty"` +// ConnectionLatency represents the latency between two clusters. +type ConnectionLatency struct { + // Value of the latency. + Value string `json:"value,omitempty"` + // Timestamp of the latency. + Timestamp metav1.Time `json:"timestamp,omitempty"` } // ConnectionStatus defines the observed state of Connection. type ConnectionStatus struct { - // Conditions contains the conditions of the connection. - Conditions []ConnectionCondition `json:"conditions,omitempty"` + // Value of the connection. + Value ConnectionStatusValue `json:"value,omitempty"` + // Message of the connection. + Message string `json:"message,omitempty"` + // Latency of the connection. + Latency ConnectionLatency `json:"latency,omitempty"` } // +kubebuilder:object:root=true // +kubebuilder:resource:categories=liqo // +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.spec.type` +// +kubebuilder:printcolumn:name="Latency",type=string,JSONPath=`.status.latency.value`,priority=1 +// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.value` +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` // Connection contains the status of a connection between two clusters (a client and a server). type Connection struct { diff --git a/apis/networking/v1alpha1/zz_generated.deepcopy.go b/apis/networking/v1alpha1/zz_generated.deepcopy.go index 09f8849405..e298fd3eea 100644 --- a/apis/networking/v1alpha1/zz_generated.deepcopy.go +++ b/apis/networking/v1alpha1/zz_generated.deepcopy.go @@ -180,7 +180,7 @@ func (in *Connection) DeepCopyInto(out *Connection) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) + out.Spec = in.Spec in.Status.DeepCopyInto(&out.Status) } @@ -203,17 +203,17 @@ func (in *Connection) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ConnectionCondition) DeepCopyInto(out *ConnectionCondition) { +func (in *ConnectionLatency) DeepCopyInto(out *ConnectionLatency) { *out = *in - in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) + in.Timestamp.DeepCopyInto(&out.Timestamp) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConnectionCondition. -func (in *ConnectionCondition) DeepCopy() *ConnectionCondition { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConnectionLatency. +func (in *ConnectionLatency) DeepCopy() *ConnectionLatency { if in == nil { return nil } - out := new(ConnectionCondition) + out := new(ConnectionLatency) in.DeepCopyInto(out) return out } @@ -254,7 +254,6 @@ func (in *ConnectionList) DeepCopyObject() runtime.Object { func (in *ConnectionSpec) DeepCopyInto(out *ConnectionSpec) { *out = *in out.GatewayRef = in.GatewayRef - in.Ping.DeepCopyInto(&out.Ping) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConnectionSpec. @@ -270,13 +269,7 @@ func (in *ConnectionSpec) DeepCopy() *ConnectionSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ConnectionStatus) DeepCopyInto(out *ConnectionStatus) { *out = *in - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make([]ConnectionCondition, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } + in.Latency.DeepCopyInto(&out.Latency) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConnectionStatus. @@ -648,27 +641,6 @@ func (in *GatewayServerStatus) DeepCopy() *GatewayServerStatus { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PingSpec) DeepCopyInto(out *PingSpec) { - *out = *in - if in.Enabled != nil { - in, out := &in.Enabled, &out.Enabled - *out = new(bool) - **out = **in - } - in.Endpoint.DeepCopyInto(&out.Endpoint) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PingSpec. -func (in *PingSpec) DeepCopy() *PingSpec { - if in == nil { - return nil - } - out := new(PingSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PublicKey) DeepCopyInto(out *PublicKey) { *out = *in diff --git a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_connections.yaml b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_connections.yaml index 48c7509a63..f0f9b5e0fc 100644 --- a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_connections.yaml +++ b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_connections.yaml @@ -16,7 +16,21 @@ spec: singular: connection scope: Namespaced versions: - - name: v1alpha1 + - additionalPrinterColumns: + - jsonPath: .spec.type + name: Type + type: string + - jsonPath: .status.latency.value + name: Latency + priority: 1 + type: string + - jsonPath: .status.value + name: Status + type: string + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1alpha1 schema: openAPIV3Schema: description: Connection contains the status of a connection between two clusters @@ -74,35 +88,6 @@ spec: type: string type: object x-kubernetes-map-type: atomic - ping: - description: Ping specifies the ping configuration. - properties: - enabled: - default: true - description: Enabled specifies whether the ping is enabled or - not. - type: boolean - endpoint: - description: Endpoint specifies the endpoint to ping. - properties: - addresses: - description: Addresses specifies the addresses of the endpoint. - items: - type: string - type: array - port: - description: Port specifies the port of the endpoint. - format: int32 - type: integer - protocol: - default: TCP - description: Protocol specifies the protocol of the endpoint. - enum: - - TCP - - UDP - type: string - type: object - type: object type: description: Type of the connection. enum: @@ -116,43 +101,23 @@ spec: status: description: ConnectionStatus defines the observed state of Connection. properties: - conditions: - description: Conditions contains the conditions of the connection. - items: - description: ConnectionCondition contains details about state of - the connection. - properties: - lastTransitionTime: - description: LastTransitionTime -> timestamp for when the condition - last transitioned from one status to another. - format: date-time - type: string - message: - description: Message -> Human-readable message indicating details - about the last status transition. - type: string - reason: - description: Reason -> Machine-readable, UpperCamelCase text - indicating the reason for the condition's last transition. - type: string - status: - default: Unknown - description: Status of the condition. - enum: - - "True" - - "False" - - Unknown - type: string - type: - description: Type of the connection condition. - enum: - - Established - type: string - required: - - status - - type - type: object - type: array + latency: + description: Latency of the connection. + properties: + timestamp: + description: Timestamp of the latency. + format: date-time + type: string + value: + description: Value of the latency. + type: string + type: object + message: + description: Message of the connection. + type: string + value: + description: Value of the connection. + type: string type: object type: object served: true