From f4269ce61826d7ad9e439dc81fab11cb0d18f200 Mon Sep 17 00:00:00 2001 From: yike21 Date: Fri, 22 Jul 2022 18:47:37 +0800 Subject: [PATCH] add RolloutHistory api Signed-off-by: yike21 --- api/v1alpha1/rollouthistory_types.go | 166 +++++++++++ api/v1alpha1/zz_generated.deepcopy.go | 275 +++++++++++++++++- .../rollouts.kruise.io_rollouthistories.yaml | 188 ++++++++++++ 3 files changed, 628 insertions(+), 1 deletion(-) create mode 100644 api/v1alpha1/rollouthistory_types.go create mode 100644 config/crd/bases/rollouts.kruise.io_rollouthistories.yaml diff --git a/api/v1alpha1/rollouthistory_types.go b/api/v1alpha1/rollouthistory_types.go new file mode 100644 index 0000000..04d831c --- /dev/null +++ b/api/v1alpha1/rollouthistory_types.go @@ -0,0 +1,166 @@ +/* +Copyright 2022 The Kruise 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 ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// RolloutHistorySpec defines the desired state of RolloutHistory +type RolloutHistorySpec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Rollout indicates information of the rollout related with rollouthistory + Rollout RolloutInfo `json:"rollout,omitempty"` + // Workload indicates information of the workload, such as cloneset, deployment, advanced statefulset + Workload WorkloadInfo `json:"workload,omitempty"` + // Service indicates information of the service related with workload + Service ServiceInfo `json:"service,omitempty"` + // TrafficRouting indicates information of traffic route related with workload + TrafficRouting TrafficRoutingInfo `json:"trafficRouting,omitempty"` +} + +type NameAndSpecData struct { + // Name indicates the name of object ref, such as rollout name, workload name, ingress name, etc. + Name string `json:"name"` + // Data indecates the spec of object ref + // +kubebuilder:pruning:PreserveUnknownFields + // +kubebuilder:validation:Schemaless + Data runtime.RawExtension `json:"data,omitempty"` +} + +// RolloutInfo indicates information of the rollout related +type RolloutInfo struct { + // RolloutID indicates the new rollout + // if there is no new RolloutID this time, ignore it and not execute RolloutHistory + RolloutID string `json:"rolloutID"` + NameAndSpecData `json:",inline"` +} + +// ServiceInfo indicates information of the service related +type ServiceInfo struct { + NameAndSpecData `json:",inline"` +} + +// TrafficRoutingInfo indicates information of Gateway API or Ingress +type TrafficRoutingInfo struct { + // IngressRef indicates information of ingress + // +optional + Ingress *IngressInfo `json:"ingress,omitempty"` + // HTTPRouteRef indacates information of Gateway API + // +optional + HTTPRoute *HTTPRouteInfo `json:"httpRoute,omitempty"` +} + +// IngressInfo indicates information of the ingress related +type IngressInfo struct { + NameAndSpecData `json:",inline"` +} + +// HTTPRouteInfo indicates information of gateway API +type HTTPRouteInfo struct { + NameAndSpecData `json:",inline"` +} + +// WorkloadInfo indicates information of the workload, such as cloneset, deployment, advanced statefulset +type WorkloadInfo struct { + metav1.TypeMeta `json:",inline"` + NameAndSpecData `json:",inline"` +} + +// RolloutHistoryStatus defines the observed state of RolloutHistory +type RolloutHistoryStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Phase indicates phase of RolloutHistory, such as "pending", "updated", "completed" + Phase string `json:"phase,omitempty"` + // RolloutState indicates the rollouts status + RolloutState RolloutState `json:"rolloutState,omitempty"` + // CanarySteps indicates the pods released each step + CanarySteps []CanaryStepInfo `json:"canarySteps,omitempty"` +} + +// RolloutState indicates the rollouts status +type RolloutState struct { + // RolloutPhase is the rollout phase. + RolloutPhase RolloutPhase `json:"phase,omitempty"` + // Message provides details on why the rollout is in its current phase + Message string `json:"message,omitempty"` +} + +// CanaryStepInfo indicates the pods for a revision +type CanaryStepInfo struct { + // CanaryStepIndex indicates step this revision + CanaryStepIndex int32 `json:"canaryStepIndex,omitempty"` + // Pods indicates the pods information + Pods []Pod `json:"pods,omitempty"` +} + +// Pod indicates the information of a pod, including name, ip, node_name. +type Pod struct { + // Name indicates the node name + Name string `json:"name,omitempty"` + // IP indicates the pod ip + IP string `json:"ip,omitempty"` + // NodeName indicates the node which pod is located at + NodeName string `json:"nodeName,omitempty"` + // todo + // State indicates whether the pod is ready or not + // State string `json:"state, omitempty"` +} + +// Phase indicates rollouthistory status/phase +const ( + PhasePending string = "pending" + PhaseUpdated string = "updated" + PhaseCompleted string = "completed" +) + +// MaxRolloutHistoryNum indicates how many rollouthistories there can be at most +const MaxRolloutHistoryNum int = 10 + +// +genclient +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status + +// RolloutHistory is the Schema for the rollouthistories API +type RolloutHistory struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec RolloutHistorySpec `json:"spec,omitempty"` + Status RolloutHistoryStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// RolloutHistoryList contains a list of RolloutHistory +type RolloutHistoryList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []RolloutHistory `json:"items"` +} + +func init() { + SchemeBuilder.Register(&RolloutHistory{}, &RolloutHistoryList{}) +} diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 39eb6a6..72b5a23 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -22,7 +22,7 @@ limitations under the License. package v1alpha1 import ( - runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -199,6 +199,26 @@ func (in *CanaryStep) DeepCopy() *CanaryStep { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CanaryStepInfo) DeepCopyInto(out *CanaryStepInfo) { + *out = *in + if in.Pods != nil { + in, out := &in.Pods, &out.Pods + *out = make([]Pod, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CanaryStepInfo. +func (in *CanaryStepInfo) DeepCopy() *CanaryStepInfo { + if in == nil { + return nil + } + out := new(CanaryStepInfo) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CanaryStrategy) DeepCopyInto(out *CanaryStrategy) { *out = *in @@ -252,6 +272,38 @@ func (in *GatewayTrafficRouting) DeepCopy() *GatewayTrafficRouting { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *HTTPRouteInfo) DeepCopyInto(out *HTTPRouteInfo) { + *out = *in + in.NameAndSpecData.DeepCopyInto(&out.NameAndSpecData) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPRouteInfo. +func (in *HTTPRouteInfo) DeepCopy() *HTTPRouteInfo { + if in == nil { + return nil + } + out := new(HTTPRouteInfo) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IngressInfo) DeepCopyInto(out *IngressInfo) { + *out = *in + in.NameAndSpecData.DeepCopyInto(&out.NameAndSpecData) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IngressInfo. +func (in *IngressInfo) DeepCopy() *IngressInfo { + if in == nil { + return nil + } + out := new(IngressInfo) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *IngressTrafficRouting) DeepCopyInto(out *IngressTrafficRouting) { *out = *in @@ -267,6 +319,22 @@ func (in *IngressTrafficRouting) DeepCopy() *IngressTrafficRouting { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NameAndSpecData) DeepCopyInto(out *NameAndSpecData) { + *out = *in + in.Data.DeepCopyInto(&out.Data) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NameAndSpecData. +func (in *NameAndSpecData) DeepCopy() *NameAndSpecData { + if in == nil { + return nil + } + out := new(NameAndSpecData) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ObjectRef) DeepCopyInto(out *ObjectRef) { *out = *in @@ -287,6 +355,21 @@ func (in *ObjectRef) DeepCopy() *ObjectRef { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Pod) DeepCopyInto(out *Pod) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Pod. +func (in *Pod) DeepCopy() *Pod { + if in == nil { + return nil + } + out := new(Pod) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ReleaseBatch) DeepCopyInto(out *ReleaseBatch) { *out = *in @@ -372,6 +455,123 @@ func (in *RolloutCondition) DeepCopy() *RolloutCondition { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutHistory) DeepCopyInto(out *RolloutHistory) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutHistory. +func (in *RolloutHistory) DeepCopy() *RolloutHistory { + if in == nil { + return nil + } + out := new(RolloutHistory) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RolloutHistory) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutHistoryList) DeepCopyInto(out *RolloutHistoryList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]RolloutHistory, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutHistoryList. +func (in *RolloutHistoryList) DeepCopy() *RolloutHistoryList { + if in == nil { + return nil + } + out := new(RolloutHistoryList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RolloutHistoryList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutHistorySpec) DeepCopyInto(out *RolloutHistorySpec) { + *out = *in + in.Rollout.DeepCopyInto(&out.Rollout) + in.Workload.DeepCopyInto(&out.Workload) + in.Service.DeepCopyInto(&out.Service) + in.TrafficRouting.DeepCopyInto(&out.TrafficRouting) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutHistorySpec. +func (in *RolloutHistorySpec) DeepCopy() *RolloutHistorySpec { + if in == nil { + return nil + } + out := new(RolloutHistorySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutHistoryStatus) DeepCopyInto(out *RolloutHistoryStatus) { + *out = *in + out.RolloutState = in.RolloutState + if in.CanarySteps != nil { + in, out := &in.CanarySteps, &out.CanarySteps + *out = make([]CanaryStepInfo, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutHistoryStatus. +func (in *RolloutHistoryStatus) DeepCopy() *RolloutHistoryStatus { + if in == nil { + return nil + } + out := new(RolloutHistoryStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutInfo) DeepCopyInto(out *RolloutInfo) { + *out = *in + in.NameAndSpecData.DeepCopyInto(&out.NameAndSpecData) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutInfo. +func (in *RolloutInfo) DeepCopy() *RolloutInfo { + if in == nil { + return nil + } + out := new(RolloutInfo) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RolloutList) DeepCopyInto(out *RolloutList) { *out = *in @@ -441,6 +641,21 @@ func (in *RolloutSpec) DeepCopy() *RolloutSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutState) DeepCopyInto(out *RolloutState) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutState. +func (in *RolloutState) DeepCopy() *RolloutState { + if in == nil { + return nil + } + out := new(RolloutState) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RolloutStatus) DeepCopyInto(out *RolloutStatus) { *out = *in @@ -488,6 +703,22 @@ func (in *RolloutStrategy) DeepCopy() *RolloutStrategy { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServiceInfo) DeepCopyInto(out *ServiceInfo) { + *out = *in + in.NameAndSpecData.DeepCopyInto(&out.NameAndSpecData) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceInfo. +func (in *ServiceInfo) DeepCopy() *ServiceInfo { + if in == nil { + return nil + } + out := new(ServiceInfo) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TrafficRouting) DeepCopyInto(out *TrafficRouting) { *out = *in @@ -513,6 +744,48 @@ func (in *TrafficRouting) DeepCopy() *TrafficRouting { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TrafficRoutingInfo) DeepCopyInto(out *TrafficRoutingInfo) { + *out = *in + if in.Ingress != nil { + in, out := &in.Ingress, &out.Ingress + *out = new(IngressInfo) + (*in).DeepCopyInto(*out) + } + if in.HTTPRoute != nil { + in, out := &in.HTTPRoute, &out.HTTPRoute + *out = new(HTTPRouteInfo) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrafficRoutingInfo. +func (in *TrafficRoutingInfo) DeepCopy() *TrafficRoutingInfo { + if in == nil { + return nil + } + out := new(TrafficRoutingInfo) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *WorkloadInfo) DeepCopyInto(out *WorkloadInfo) { + *out = *in + out.TypeMeta = in.TypeMeta + in.NameAndSpecData.DeepCopyInto(&out.NameAndSpecData) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkloadInfo. +func (in *WorkloadInfo) DeepCopy() *WorkloadInfo { + if in == nil { + return nil + } + out := new(WorkloadInfo) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WorkloadRef) DeepCopyInto(out *WorkloadRef) { *out = *in diff --git a/config/crd/bases/rollouts.kruise.io_rollouthistories.yaml b/config/crd/bases/rollouts.kruise.io_rollouthistories.yaml new file mode 100644 index 0000000..76750e6 --- /dev/null +++ b/config/crd/bases/rollouts.kruise.io_rollouthistories.yaml @@ -0,0 +1,188 @@ + +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.7.0 + creationTimestamp: null + name: rollouthistories.rollouts.kruise.io +spec: + group: rollouts.kruise.io + names: + kind: RolloutHistory + listKind: RolloutHistoryList + plural: rollouthistories + singular: rollouthistory + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: RolloutHistory is the Schema for the rollouthistories API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: RolloutHistorySpec defines the desired state of RolloutHistory + properties: + rollout: + description: Rollout indicates information of the rollout related + with rollouthistory + properties: + data: + description: Data indecates the spec of object ref + x-kubernetes-preserve-unknown-fields: true + name: + description: Name indicates the name of object ref, such as rollout + name, workload name, ingress name, etc. + type: string + rolloutID: + description: RolloutID indicates the new rollout if there is no + new RolloutID this time, ignore it and not execute RolloutHistory + type: string + required: + - name + - rolloutID + type: object + service: + description: Service indicates information of the service related + with workload + properties: + data: + description: Data indecates the spec of object ref + x-kubernetes-preserve-unknown-fields: true + name: + description: Name indicates the name of object ref, such as rollout + name, workload name, ingress name, etc. + type: string + required: + - name + type: object + trafficRouting: + description: TrafficRouting indicates information of traffic route + related with workload + properties: + httpRoute: + description: HTTPRouteRef indacates information of Gateway API + properties: + data: + description: Data indecates the spec of object ref + x-kubernetes-preserve-unknown-fields: true + name: + description: Name indicates the name of object ref, such as + rollout name, workload name, ingress name, etc. + type: string + required: + - name + type: object + ingress: + description: IngressRef indicates information of ingress + properties: + data: + description: Data indecates the spec of object ref + x-kubernetes-preserve-unknown-fields: true + name: + description: Name indicates the name of object ref, such as + rollout name, workload name, ingress name, etc. + type: string + required: + - name + type: object + type: object + workload: + description: Workload indicates information of the workload, such + as cloneset, deployment, advanced statefulset + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this + representation of an object. Servers should convert recognized + schemas to the latest internal value, and may reject unrecognized + values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + data: + description: Data indecates the spec of object ref + x-kubernetes-preserve-unknown-fields: true + kind: + description: 'Kind is a string value representing the REST resource + this object represents. Servers may infer this from the endpoint + the client submits requests to. Cannot be updated. In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: Name indicates the name of object ref, such as rollout + name, workload name, ingress name, etc. + type: string + required: + - name + type: object + type: object + status: + description: RolloutHistoryStatus defines the observed state of RolloutHistory + properties: + canarySteps: + description: CanarySteps indicates the pods released each step + items: + description: CanaryStepInfo indicates the pods for a revision + properties: + canaryStepIndex: + description: CanaryStepIndex indicates step this revision + format: int32 + type: integer + pods: + description: Pods indicates the pods information + items: + description: Pod indicates the information of a pod, including + name, ip, node_name. + properties: + ip: + description: IP indicates the pod ip + type: string + name: + description: Name indicates the node name + type: string + nodeName: + description: NodeName indicates the node which pod is + located at + type: string + type: object + type: array + type: object + type: array + phase: + description: Phase indicates phase of RolloutHistory, such as "pending", + "updated", "completed" + type: string + rolloutState: + description: RolloutState indicates the rollouts status + properties: + message: + description: Message provides details on why the rollout is in + its current phase + type: string + phase: + description: RolloutPhase is the rollout phase. + type: string + type: object + type: object + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: []