-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement API and CRD for ztunnel component #481
Changes from 5 commits
f531329
b52392e
501c77a
e82a4bc
051eb59
12039f8
c1f014a
c106779
1ea0231
623acbd
d65fac9
f4bd18d
839e7a5
96f2aee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,198 @@ | ||||||
// Copyright Istio Authors | ||||||
// | ||||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
// you may not use this file except in compliance with the License. | ||||||
// You may obtain a copy of the License at | ||||||
// | ||||||
// http://www.apache.org/licenses/LICENSE-2.0 | ||||||
// | ||||||
// Unless required by applicable law or agreed to in writing, software | ||||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
// See the License for the specific language governing permissions and | ||||||
// limitations under the License. | ||||||
|
||||||
package v1alpha1 | ||||||
|
||||||
import ( | ||||||
"time" | ||||||
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
) | ||||||
|
||||||
|
||||||
const ( | ||||||
ZTunnelKind = "ZTunnel" | ||||||
) | ||||||
|
||||||
// ZTunnelSpec defines the desired state of ZTunnel | ||||||
type ZTunnelSpec struct { | ||||||
// +sail:version | ||||||
// Defines the version of Istio to install. | ||||||
// Must be one of: v1.24.0 or latest. | ||||||
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=1,displayName="Istio Version",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:fieldGroup:General", "urn:alm:descriptor:com.tectonic.ui:select:v1.24.0", "urn:alm:descriptor:com.tectonic.ui:select:latest"} | ||||||
// +kubebuilder:validation:Enum=v1.24.0;latest | ||||||
// +kubebuilder:default=v1.24.0 | ||||||
Version string `json:"version"` | ||||||
|
||||||
// +sail:profile | ||||||
// The built-in installation configuration profile to use. | ||||||
// The 'default' profile is always applied. On OpenShift, the 'openshift' profile is also applied on top of 'default'. | ||||||
yxun marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// Must be one of: ambient, default, demo, empty, external, openshift-ambient, openshift, preview, remote, stable. | ||||||
// +++PROFILES-DROPDOWN-HIDDEN-UNTIL-WE-FULLY-IMPLEMENT-THEM+++operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Profile",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:fieldGroup:General", "urn:alm:descriptor:com.tectonic.ui:select:ambient", "urn:alm:descriptor:com.tectonic.ui:select:default", "urn:alm:descriptor:com.tectonic.ui:select:demo", "urn:alm:descriptor:com.tectonic.ui:select:empty", "urn:alm:descriptor:com.tectonic.ui:select:external", "urn:alm:descriptor:com.tectonic.ui:select:minimal", "urn:alm:descriptor:com.tectonic.ui:select:preview", "urn:alm:descriptor:com.tectonic.ui:select:remote"} | ||||||
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:hidden"} | ||||||
// +kubebuilder:validation:Enum=ambient;default;demo;empty;external;openshift-ambient;openshift;preview;remote;stable | ||||||
Profile string `json:"profile,omitempty"` | ||||||
yxun marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
// Namespace to which the Istio ztunnel component should be installed. | ||||||
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:io.kubernetes:Namespace"} | ||||||
// +kubebuilder:default=kube-system | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct? Do we want to deploy ztunnel to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In upstream, its installed by default in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we change the namespace to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, I tried an installation of upstream ambient on OpenShift. By default, it does not work in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's the best idea to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yxun when you tried installing ztunnel in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@luksa, I see that when using istioctl with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated this default namespace value in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed during the call yesterday, we will be installing the ztunnel CR in the |
||||||
Namespace string `json:"namespace"` | ||||||
|
||||||
// Defines the values to be passed to the Helm charts when installing Istio ztunnel. | ||||||
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Helm Values" | ||||||
Values *ZTunnelValues `json:"values,omitempty"` | ||||||
} | ||||||
|
||||||
// ZTunnelStatus defines the observed state of ZTunnel | ||||||
type ZTunnelStatus struct { | ||||||
// ObservedGeneration is the most recent generation observed for this | ||||||
// ZTunnel object. It corresponds to the object's generation, which is | ||||||
// updated on mutation by the API Server. The information in the status | ||||||
// pertains to this particular generation of the object. | ||||||
ObservedGeneration int64 `json:"observedGeneration,omitempty"` | ||||||
|
||||||
// Represents the latest available observations of the object's current state. | ||||||
Conditions []ZTunnelCondition `json:"conditions,omitempty"` | ||||||
|
||||||
// Reports the current state of the object. | ||||||
State ZTunnelConditionReason `json:"state,omitempty"` | ||||||
} | ||||||
|
||||||
// GetCondition returns the condition of the specified type | ||||||
func (s *ZTunnelStatus) GetCondition(conditionType ZTunnelConditionType) ZTunnelCondition { | ||||||
if s != nil { | ||||||
for i := range s.Conditions { | ||||||
if s.Conditions[i].Type == conditionType { | ||||||
return s.Conditions[i] | ||||||
} | ||||||
} | ||||||
} | ||||||
return ZTunnelCondition{Type: conditionType, Status: metav1.ConditionUnknown} | ||||||
} | ||||||
|
||||||
// SetCondition sets a specific condition in the list of conditions | ||||||
func (s *ZTunnelStatus) SetCondition(condition ZTunnelCondition) { | ||||||
var now time.Time | ||||||
if testTime == nil { | ||||||
now = time.Now() | ||||||
} else { | ||||||
now = *testTime | ||||||
} | ||||||
|
||||||
// The lastTransitionTime only gets serialized out to the second. This can | ||||||
// break update skipping, as the time in the resource returned from the client | ||||||
// may not match the time in our cached status during a reconcile. We truncate | ||||||
// here to save any problems down the line. | ||||||
lastTransitionTime := metav1.NewTime(now.Truncate(time.Second)) | ||||||
|
||||||
for i, prevCondition := range s.Conditions { | ||||||
if prevCondition.Type == condition.Type { | ||||||
if prevCondition.Status != condition.Status { | ||||||
condition.LastTransitionTime = lastTransitionTime | ||||||
} else { | ||||||
condition.LastTransitionTime = prevCondition.LastTransitionTime | ||||||
} | ||||||
s.Conditions[i] = condition | ||||||
return | ||||||
} | ||||||
} | ||||||
|
||||||
// If the condition does not exist, initialize the lastTransitionTime | ||||||
condition.LastTransitionTime = lastTransitionTime | ||||||
s.Conditions = append(s.Conditions, condition) | ||||||
} | ||||||
|
||||||
// ZTunnelCondition represents a specific observation of the ZTunnel object's state. | ||||||
type ZTunnelCondition struct { | ||||||
// The type of this condition. | ||||||
Type ZTunnelConditionType `json:"type,omitempty"` | ||||||
|
||||||
// The status of this condition. Can be True, False or Unknown. | ||||||
Status metav1.ConditionStatus `json:"status,omitempty"` | ||||||
|
||||||
// Unique, single-word, CamelCase reason for the condition's last transition. | ||||||
Reason ZTunnelConditionReason `json:"reason,omitempty"` | ||||||
|
||||||
// Human-readable message indicating details about the last transition. | ||||||
Message string `json:"message,omitempty"` | ||||||
|
||||||
// Last time the condition transitioned from one status to another. | ||||||
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` | ||||||
} | ||||||
|
||||||
// ZTunnelConditionType represents the type of the condition. Condition stages are: | ||||||
// Installed, Reconciled, Ready | ||||||
type ZTunnelConditionType string | ||||||
|
||||||
// ZTunnelConditionReason represents a short message indicating how the condition came | ||||||
// to be in its present state. | ||||||
type ZTunnelConditionReason string | ||||||
|
||||||
const ( | ||||||
// ZTunnelConditionReconciled signifies whether the controller has | ||||||
// successfully reconciled the resources defined through the CR. | ||||||
ZTunnelConditionReconciled ZTunnelConditionType = "Reconciled" | ||||||
|
||||||
// ZTunnelReasonReconcileError indicates that the reconciliation of the resource has failed, but will be retried. | ||||||
ZTunnelReasonReconcileError ZTunnelConditionReason = "ReconcileError" | ||||||
) | ||||||
|
||||||
const ( | ||||||
// ZTunnelConditionReady signifies whether the ztunnel DaemonSet is ready. | ||||||
ZTunnelConditionReady ZTunnelConditionType = "Ready" | ||||||
|
||||||
// ZTunnelDaemonSetNotReady indicates that the ztunnel DaemonSet is not ready. | ||||||
ZTunnelDaemonSetNotReady ZTunnelConditionReason = "DaemonSetNotReady" | ||||||
|
||||||
// ZTunnelReasonReadinessCheckFailed indicates that the DaemonSet readiness status could not be ascertained. | ||||||
ZTunnelReasonReadinessCheckFailed ZTunnelConditionReason = "ReadinessCheckFailed" | ||||||
) | ||||||
|
||||||
const ( | ||||||
// ZTunnelReasonHealthy indicates that the control plane is fully reconciled and that all components are ready. | ||||||
ZTunnelReasonHealthy ZTunnelConditionReason = "Healthy" | ||||||
) | ||||||
|
||||||
// +kubebuilder:object:root=true | ||||||
// +kubebuilder:resource:scope=Cluster,categories=istio-io | ||||||
// +kubebuilder:subresource:status | ||||||
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description="Whether the Istio ztunnel installation is ready to handle requests." | ||||||
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.state",description="The current state of this object." | ||||||
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version",description="The version of the Istio ztunnel installation." | ||||||
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="The age of the object" | ||||||
// +kubebuilder:validation:XValidation:rule="self.metadata.name == 'default'",message="metadata.name must be 'default'" | ||||||
|
||||||
// ZTunnel represents a deployment of the Istio ztunnel component. | ||||||
type ZTunnel struct { | ||||||
metav1.TypeMeta `json:",inline"` | ||||||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||||||
|
||||||
// +kubebuilder:default={version: "v1.24.0", namespace: "kube-system"} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Spec ZTunnelSpec `json:"spec,omitempty"` | ||||||
|
||||||
Status ZTunnelStatus `json:"status,omitempty"` | ||||||
} | ||||||
|
||||||
// +kubebuilder:object:root=true | ||||||
|
||||||
// ZTunnelList contains a list of ZTunnel | ||||||
type ZTunnelList struct { | ||||||
metav1.TypeMeta `json:",inline"` | ||||||
metav1.ListMeta `json:"metadata,omitempty"` | ||||||
Items []ZTunnel `json:"items"` | ||||||
} | ||||||
|
||||||
func init() { | ||||||
SchemeBuilder.Register(&ZTunnel{}, &ZTunnelList{}) | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.