From 765901bad7117b87abff9779bcae3991a6600c71 Mon Sep 17 00:00:00 2001 From: wastill <2225144254@qq.com> Date: Fri, 22 Dec 2023 15:46:29 +0800 Subject: [PATCH 1/2] feat(api): Extraction of public structures 1. Extraction of public structures 1. ingress 2. service 3. status --- api/v1alpha1/sparkhistoryserver_types.go | 127 ++---------- api/v1alpha1/zz_generated.deepcopy.go | 157 +-------------- ...stack.zncdata.net_sparkhistoryservers.yaml | 189 +++++++++++++++++- go.mod | 43 ++-- go.sum | 89 +++++---- internal/controller/handler.go | 67 ++++--- .../sparkhistoryserver_controller.go | 34 +--- 7 files changed, 310 insertions(+), 396 deletions(-) diff --git a/api/v1alpha1/sparkhistoryserver_types.go b/api/v1alpha1/sparkhistoryserver_types.go index b49e239..06e6b1a 100644 --- a/api/v1alpha1/sparkhistoryserver_types.go +++ b/api/v1alpha1/sparkhistoryserver_types.go @@ -17,9 +17,12 @@ limitations under the License. package v1alpha1 import ( + "github.com/zncdata-labs/operator-go/pkg/image" + "github.com/zncdata-labs/operator-go/pkg/ingress" + "github.com/zncdata-labs/operator-go/pkg/persistence" + "github.com/zncdata-labs/operator-go/pkg/service" + "github.com/zncdata-labs/operator-go/pkg/status" corev1 "k8s.io/api/core/v1" - networkingv1 "k8s.io/api/networking/v1" - apimeta "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -29,7 +32,7 @@ import ( // SparkHistoryServerSpec defines the desired state of SparkHistoryServer type SparkHistoryServerSpec struct { // +kubebuilder:validation:Required - Image *ImageSpec `json:"image"` + Image *image.ImageSpec `json:"image"` // +kubebuilder:validation:Optional // +kubebuilder:validation:Minimum=1 @@ -44,13 +47,13 @@ type SparkHistoryServerSpec struct { SecurityContext *corev1.PodSecurityContext `json:"securityContext"` // +kubebuilder:validation:Required - Persistence *PersistenceSpec `json:"persistence"` + Persistence *persistence.PersistenceSpec `json:"persistence"` // +kubebuilder:validation:Required - Ingress *IngressSpec `json:"ingress"` + Ingress *ingress.IngressSpec `json:"ingress"` // +kubebuilder:validation:Required - Service *ServiceSpec `json:"service"` + Service *service.ServiceSpec `json:"service"` // +kubebuilder:validation:Optional Labels map[string]string `json:"labels"` @@ -69,47 +72,9 @@ type SparkHistoryServerSpec struct { } func (sparkHistory *SparkHistoryServer) GetNameWithSuffix(suffix string) string { - // return sparkHistory.GetName() + rand.String(5) + suffix return sparkHistory.GetName() + suffix } -type ImageSpec struct { - // +kubebuilder:validation:Optional - // +kubebuilder:default:="bitnami/spark" - Repository string `json:"repository,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default:="3.4.1" - Tag string `json:"tag,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default:=IfNotPresent - PullPolicy corev1.PullPolicy `json:"pullPolicy,omitempty"` -} - -type PersistenceSpec struct { - // +kubebuilder:validation:Optional - // +kubebuilder:default:=true - Enable bool `json:"enable,omitempty"` - // +kubebuilder:validation:Optional - ExistingClaim *string `json:"existingClaim,omitempty"` - // +kubebuilder:validation:Optional - Annotations map[string]string `json:"annotations,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default:="10Gi" - StorageSize string `json:"storageSize,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default:="ReadWriteOnce" - AccessMode string `json:"accessMode,omitempty"` - // +kubebuilder:validation:Optional - StorageClassName *string `json:"storageClassName,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default=Filesystem - VolumeMode *corev1.PersistentVolumeMode `json:"volumeMode,omitempty"` -} - -func (p *PersistenceSpec) Existing() bool { - return p.ExistingClaim != nil -} - func (sparkHistory *SparkHistoryServer) GetPvcName() string { if sparkHistory.Spec.Persistence != nil && sparkHistory.Spec.Persistence.Existing() { return *sparkHistory.Spec.Persistence.ExistingClaim @@ -118,82 +83,16 @@ func (sparkHistory *SparkHistoryServer) GetPvcName() string { return sparkHistory.GetNameWithSuffix("-pvc") } -type IngressSpec struct { - // +kubebuilder:validation:Optional - // +kubebuilder:default:=true - Enabled bool `json:"enabled,omitempty"` - // +kubebuilder:validation:Optional - TLS *networkingv1.IngressTLS `json:"tls,omitempty"` - // +kubebuilder:validation:Optional - Annotations map[string]string `json:"annotations,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default:="spark-history-server.example.com" - Host string `json:"host,omitempty"` -} - -type ServiceSpec struct { - // +kubebuilder:validation:Optional - Annotations map[string]string `json:"annotations,omitempty"` - // +kubebuilder:validation:enum=ClusterIP;NodePort;LoadBalancer;ExternalName - // +kubebuilder:default=ClusterIP - Type corev1.ServiceType `json:"type,omitempty"` - // +kubebuilder:validation:Minimum=1 - // +kubebuilder:validation:Maximum=65535 - // +kubebuilder:default=18080 - Port int32 `json:"port"` -} - // SetStatusCondition updates the status condition using the provided arguments. // If the condition already exists, it updates the condition; otherwise, it appends the condition. // If the condition status has changed, it updates the condition's LastTransitionTime. func (sparkHistory *SparkHistoryServer) SetStatusCondition(condition metav1.Condition) { - // if the condition already exists, update it - existingCondition := apimeta.FindStatusCondition(sparkHistory.Status.Conditions, condition.Type) - if existingCondition == nil { - condition.ObservedGeneration = sparkHistory.GetGeneration() - condition.LastTransitionTime = metav1.Now() - sparkHistory.Status.Conditions = append(sparkHistory.Status.Conditions, condition) - } else if existingCondition.Status != condition.Status || existingCondition.Reason != condition.Reason || existingCondition.Message != condition.Message { - existingCondition.Status = condition.Status - existingCondition.Reason = condition.Reason - existingCondition.Message = condition.Message - existingCondition.ObservedGeneration = sparkHistory.GetGeneration() - existingCondition.LastTransitionTime = metav1.Now() - } + sparkHistory.Status.SetStatusCondition(condition) } // InitStatusConditions initializes the status conditions to the provided conditions. func (sparkHistory *SparkHistoryServer) InitStatusConditions() { - sparkHistory.Status.Conditions = []metav1.Condition{} - sparkHistory.SetStatusCondition(metav1.Condition{ - Type: ConditionTypeProgressing, - Status: metav1.ConditionTrue, - Reason: ConditionReasonPreparing, - Message: "SparkHistoryServer is preparing", - ObservedGeneration: sparkHistory.GetGeneration(), - LastTransitionTime: metav1.Now(), - }) - sparkHistory.SetStatusCondition(metav1.Condition{ - Type: ConditionTypeAvailable, - Status: metav1.ConditionFalse, - Reason: ConditionReasonPreparing, - Message: "SparkHistoryServer is preparing", - ObservedGeneration: sparkHistory.GetGeneration(), - LastTransitionTime: metav1.Now(), - }) -} - -// SparkHistoryServerStatus defines the observed state of SparkHistoryServer -type SparkHistoryServerStatus struct { - // +kubebuilder:validation:Optional - Conditions []metav1.Condition `json:"condition,omitempty"` - // +kubebuilder:validation:Optional - URLs []StatusURL `json:"urls,omitempty"` -} - -type StatusURL struct { - Name string `json:"name"` - URL string `json:"url"` + sparkHistory.Status.InitStatusConditions() } //+kubebuilder:object:root=true @@ -204,8 +103,8 @@ type SparkHistoryServer struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec SparkHistoryServerSpec `json:"spec,omitempty"` - Status SparkHistoryServerStatus `json:"status,omitempty"` + Spec SparkHistoryServerSpec `json:"spec,omitempty"` + Status status.ZncdataStatus `json:"status,omitempty"` } //+kubebuilder:object:root=true diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 7fe3398..e751481 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -22,112 +22,9 @@ package v1alpha1 import ( "k8s.io/api/core/v1" - networkingv1 "k8s.io/api/networking/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ImageSpec) DeepCopyInto(out *ImageSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImageSpec. -func (in *ImageSpec) DeepCopy() *ImageSpec { - if in == nil { - return nil - } - out := new(ImageSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *IngressSpec) DeepCopyInto(out *IngressSpec) { - *out = *in - if in.TLS != nil { - in, out := &in.TLS, &out.TLS - *out = new(networkingv1.IngressTLS) - (*in).DeepCopyInto(*out) - } - if in.Annotations != nil { - in, out := &in.Annotations, &out.Annotations - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IngressSpec. -func (in *IngressSpec) DeepCopy() *IngressSpec { - if in == nil { - return nil - } - out := new(IngressSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PersistenceSpec) DeepCopyInto(out *PersistenceSpec) { - *out = *in - if in.ExistingClaim != nil { - in, out := &in.ExistingClaim, &out.ExistingClaim - *out = new(string) - **out = **in - } - if in.Annotations != nil { - in, out := &in.Annotations, &out.Annotations - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - if in.StorageClassName != nil { - in, out := &in.StorageClassName, &out.StorageClassName - *out = new(string) - **out = **in - } - if in.VolumeMode != nil { - in, out := &in.VolumeMode, &out.VolumeMode - *out = new(v1.PersistentVolumeMode) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PersistenceSpec. -func (in *PersistenceSpec) DeepCopy() *PersistenceSpec { - if in == nil { - return nil - } - out := new(PersistenceSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ServiceSpec) DeepCopyInto(out *ServiceSpec) { - *out = *in - if in.Annotations != nil { - in, out := &in.Annotations, &out.Annotations - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceSpec. -func (in *ServiceSpec) DeepCopy() *ServiceSpec { - if in == nil { - return nil - } - out := new(ServiceSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SparkHistoryServer) DeepCopyInto(out *SparkHistoryServer) { *out = *in @@ -192,8 +89,7 @@ func (in *SparkHistoryServerSpec) DeepCopyInto(out *SparkHistoryServerSpec) { *out = *in if in.Image != nil { in, out := &in.Image, &out.Image - *out = new(ImageSpec) - **out = **in + *out = (*in).DeepCopy() } if in.Resources != nil { in, out := &in.Resources, &out.Resources @@ -207,18 +103,15 @@ func (in *SparkHistoryServerSpec) DeepCopyInto(out *SparkHistoryServerSpec) { } if in.Persistence != nil { in, out := &in.Persistence, &out.Persistence - *out = new(PersistenceSpec) - (*in).DeepCopyInto(*out) + *out = (*in).DeepCopy() } if in.Ingress != nil { in, out := &in.Ingress, &out.Ingress - *out = new(IngressSpec) - (*in).DeepCopyInto(*out) + *out = (*in).DeepCopy() } if in.Service != nil { in, out := &in.Service, &out.Service - *out = new(ServiceSpec) - (*in).DeepCopyInto(*out) + *out = (*in).DeepCopy() } if in.Labels != nil { in, out := &in.Labels, &out.Labels @@ -262,45 +155,3 @@ func (in *SparkHistoryServerSpec) DeepCopy() *SparkHistoryServerSpec { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SparkHistoryServerStatus) DeepCopyInto(out *SparkHistoryServerStatus) { - *out = *in - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make([]metav1.Condition, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.URLs != nil { - in, out := &in.URLs, &out.URLs - *out = make([]StatusURL, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SparkHistoryServerStatus. -func (in *SparkHistoryServerStatus) DeepCopy() *SparkHistoryServerStatus { - if in == nil { - return nil - } - out := new(SparkHistoryServerStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *StatusURL) DeepCopyInto(out *StatusURL) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StatusURL. -func (in *StatusURL) DeepCopy() *StatusURL { - if in == nil { - return nil - } - out := new(StatusURL) - in.DeepCopyInto(out) - return out -} diff --git a/config/crd/bases/stack.zncdata.net_sparkhistoryservers.yaml b/config/crd/bases/stack.zncdata.net_sparkhistoryservers.yaml index 6f8edaf..7b3c76e 100644 --- a/config/crd/bases/stack.zncdata.net_sparkhistoryservers.yaml +++ b/config/crd/bases/stack.zncdata.net_sparkhistoryservers.yaml @@ -271,7 +271,8 @@ spec: properties: labelSelector: description: A label query over a set of resources, - in this case pods. + in this case pods. If it's null, this PodAffinityTerm + matches with no Pods. properties: matchExpressions: description: matchExpressions is a list of label @@ -321,6 +322,44 @@ spec: type: object type: object x-kubernetes-map-type: atomic + matchLabelKeys: + description: MatchLabelKeys is a set of pod label + keys to select which pods will be taken into consideration. + The keys are used to lookup values from the incoming + pod labels, those key-value labels are merged + with `LabelSelector` as `key in (value)` to select + the group of existing pods which pods will be + taken into consideration for the incoming pod's + pod (anti) affinity. Keys that don't exist in + the incoming pod labels will be ignored. The default + value is empty. The same key is forbidden to exist + in both MatchLabelKeys and LabelSelector. Also, + MatchLabelKeys cannot be set when LabelSelector + isn't set. This is an alpha field and requires + enabling MatchLabelKeysInPodAffinity feature gate. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: MismatchLabelKeys is a set of pod label + keys to select which pods will be taken into consideration. + The keys are used to lookup values from the incoming + pod labels, those key-value labels are merged + with `LabelSelector` as `key notin (value)` to + select the group of existing pods which pods will + be taken into consideration for the incoming pod's + pod (anti) affinity. Keys that don't exist in + the incoming pod labels will be ignored. The default + value is empty. The same key is forbidden to exist + in both MismatchLabelKeys and LabelSelector. Also, + MismatchLabelKeys cannot be set when LabelSelector + isn't set. This is an alpha field and requires + enabling MatchLabelKeysInPodAffinity feature gate. + items: + type: string + type: array + x-kubernetes-list-type: atomic namespaceSelector: description: A label query over the set of namespaces that the term applies to. The term is applied @@ -431,7 +470,8 @@ spec: properties: labelSelector: description: A label query over a set of resources, - in this case pods. + in this case pods. If it's null, this PodAffinityTerm + matches with no Pods. properties: matchExpressions: description: matchExpressions is a list of label @@ -477,6 +517,43 @@ spec: type: object type: object x-kubernetes-map-type: atomic + matchLabelKeys: + description: MatchLabelKeys is a set of pod label keys + to select which pods will be taken into consideration. + The keys are used to lookup values from the incoming + pod labels, those key-value labels are merged with + `LabelSelector` as `key in (value)` to select the + group of existing pods which pods will be taken into + consideration for the incoming pod's pod (anti) affinity. + Keys that don't exist in the incoming pod labels will + be ignored. The default value is empty. The same key + is forbidden to exist in both MatchLabelKeys and LabelSelector. + Also, MatchLabelKeys cannot be set when LabelSelector + isn't set. This is an alpha field and requires enabling + MatchLabelKeysInPodAffinity feature gate. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: MismatchLabelKeys is a set of pod label + keys to select which pods will be taken into consideration. + The keys are used to lookup values from the incoming + pod labels, those key-value labels are merged with + `LabelSelector` as `key notin (value)` to select the + group of existing pods which pods will be taken into + consideration for the incoming pod's pod (anti) affinity. + Keys that don't exist in the incoming pod labels will + be ignored. The default value is empty. The same key + is forbidden to exist in both MismatchLabelKeys and + LabelSelector. Also, MismatchLabelKeys cannot be set + when LabelSelector isn't set. This is an alpha field + and requires enabling MatchLabelKeysInPodAffinity + feature gate. + items: + type: string + type: array + x-kubernetes-list-type: atomic namespaceSelector: description: A label query over the set of namespaces that the term applies to. The term is applied to the @@ -580,7 +657,8 @@ spec: properties: labelSelector: description: A label query over a set of resources, - in this case pods. + in this case pods. If it's null, this PodAffinityTerm + matches with no Pods. properties: matchExpressions: description: matchExpressions is a list of label @@ -630,6 +708,44 @@ spec: type: object type: object x-kubernetes-map-type: atomic + matchLabelKeys: + description: MatchLabelKeys is a set of pod label + keys to select which pods will be taken into consideration. + The keys are used to lookup values from the incoming + pod labels, those key-value labels are merged + with `LabelSelector` as `key in (value)` to select + the group of existing pods which pods will be + taken into consideration for the incoming pod's + pod (anti) affinity. Keys that don't exist in + the incoming pod labels will be ignored. The default + value is empty. The same key is forbidden to exist + in both MatchLabelKeys and LabelSelector. Also, + MatchLabelKeys cannot be set when LabelSelector + isn't set. This is an alpha field and requires + enabling MatchLabelKeysInPodAffinity feature gate. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: MismatchLabelKeys is a set of pod label + keys to select which pods will be taken into consideration. + The keys are used to lookup values from the incoming + pod labels, those key-value labels are merged + with `LabelSelector` as `key notin (value)` to + select the group of existing pods which pods will + be taken into consideration for the incoming pod's + pod (anti) affinity. Keys that don't exist in + the incoming pod labels will be ignored. The default + value is empty. The same key is forbidden to exist + in both MismatchLabelKeys and LabelSelector. Also, + MismatchLabelKeys cannot be set when LabelSelector + isn't set. This is an alpha field and requires + enabling MatchLabelKeysInPodAffinity feature gate. + items: + type: string + type: array + x-kubernetes-list-type: atomic namespaceSelector: description: A label query over the set of namespaces that the term applies to. The term is applied @@ -740,7 +856,8 @@ spec: properties: labelSelector: description: A label query over a set of resources, - in this case pods. + in this case pods. If it's null, this PodAffinityTerm + matches with no Pods. properties: matchExpressions: description: matchExpressions is a list of label @@ -786,6 +903,43 @@ spec: type: object type: object x-kubernetes-map-type: atomic + matchLabelKeys: + description: MatchLabelKeys is a set of pod label keys + to select which pods will be taken into consideration. + The keys are used to lookup values from the incoming + pod labels, those key-value labels are merged with + `LabelSelector` as `key in (value)` to select the + group of existing pods which pods will be taken into + consideration for the incoming pod's pod (anti) affinity. + Keys that don't exist in the incoming pod labels will + be ignored. The default value is empty. The same key + is forbidden to exist in both MatchLabelKeys and LabelSelector. + Also, MatchLabelKeys cannot be set when LabelSelector + isn't set. This is an alpha field and requires enabling + MatchLabelKeysInPodAffinity feature gate. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: MismatchLabelKeys is a set of pod label + keys to select which pods will be taken into consideration. + The keys are used to lookup values from the incoming + pod labels, those key-value labels are merged with + `LabelSelector` as `key notin (value)` to select the + group of existing pods which pods will be taken into + consideration for the incoming pod's pod (anti) affinity. + Keys that don't exist in the incoming pod labels will + be ignored. The default value is empty. The same key + is forbidden to exist in both MismatchLabelKeys and + LabelSelector. Also, MismatchLabelKeys cannot be set + when LabelSelector isn't set. This is an alpha field + and requires enabling MatchLabelKeysInPodAffinity + feature gate. + items: + type: string + type: array + x-kubernetes-list-type: atomic namespaceSelector: description: A label query over the set of namespaces that the term applies to. The term is applied to the @@ -930,6 +1084,12 @@ spec: accessMode: default: ReadWriteOnce type: string + accessModes: + default: + - ReadWriteOnce + items: + type: string + type: array annotations: additionalProperties: type: string @@ -939,6 +1099,15 @@ spec: type: boolean existingClaim: type: string + labels: + additionalProperties: + type: string + type: object + size: + default: 10Gi + type: string + storageClass: + type: string storageClassName: type: string storageSize: @@ -1239,9 +1408,9 @@ spec: - service type: object status: - description: SparkHistoryServerStatus defines the observed state of SparkHistoryServer + description: ZncdataStatus defines the common state of Zncdata properties: - condition: + conditions: items: description: "Condition contains details for one aspect of the current state of this API Resource. --- This struct is intended for direct @@ -1309,8 +1478,16 @@ spec: - type type: object type: array + generation: + format: int64 + type: integer + name: + type: string + type: + type: string urls: items: + description: URL is a URL with a name properties: name: type: string diff --git a/go.mod b/go.mod index b2baba5..d75fe71 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,15 @@ module github.com/zncdata-labs/spark-k8s-operator -go 1.19 +go 1.21 require ( - github.com/onsi/ginkgo/v2 v2.12.1 - github.com/onsi/gomega v1.27.10 - k8s.io/api v0.28.2 - k8s.io/apimachinery v0.28.2 - k8s.io/client-go v0.28.2 - sigs.k8s.io/controller-runtime v0.16.2 + github.com/onsi/ginkgo/v2 v2.13.0 + github.com/onsi/gomega v1.29.0 + github.com/zncdata-labs/operator-go v0.0.0-20231222061826-114414d7e684 + k8s.io/api v0.29.0 + k8s.io/apimachinery v0.29.0 + k8s.io/client-go v0.29.0 + sigs.k8s.io/controller-runtime v0.16.3 ) require ( @@ -28,17 +29,17 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cisco-open/k8s-objectmatcher v1.9.0 github.com/davecgh/go-spew v1.1.1 // indirect - github.com/emicklei/go-restful/v3 v3.9.0 // indirect + github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch/v5 v5.6.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.3.0 github.com/go-logr/zapr v1.2.4 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.3 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/google/go-cmp v0.5.9 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/uuid v1.3.0 // indirect github.com/imdario/mergo v0.3.6 // indirect @@ -57,24 +58,24 @@ require ( github.com/spf13/pflag v1.0.5 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.25.0 // indirect - golang.org/x/net v0.14.0 // indirect - golang.org/x/oauth2 v0.8.0 // indirect - golang.org/x/sys v0.12.0 // indirect - golang.org/x/term v0.12.0 // indirect - golang.org/x/text v0.12.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/oauth2 v0.10.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/term v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/appengine v1.6.7 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/apiextensions-apiserver v0.28.2 // indirect - k8s.io/component-base v0.28.2 // indirect - k8s.io/klog/v2 v2.100.1 // indirect - k8s.io/kube-openapi v0.0.0-20230918164632-68afd615200d // indirect - k8s.io/kubectl v0.28.2 + k8s.io/apiextensions-apiserver v0.28.3 // indirect + k8s.io/component-base v0.29.0 // indirect + k8s.io/klog/v2 v2.110.1 // indirect + k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect + k8s.io/kubectl v0.29.0 k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 5539c83..74b4112 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,7 @@ emperror.dev/errors v0.8.1 h1:UavXZ5cSX/4u9iyvH6aDcuGkVjeexUGJ7Ij7G4VfQT0= emperror.dev/errors v0.8.1/go.mod h1:YcRvLPh626Ubn2xqtoprejnA5nFha+TJ+2vew48kWuE= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= +github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= @@ -15,17 +16,17 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE= -github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= +github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww= github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= -github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/zapr v1.2.4 h1:QHVo+6stLbfJmYGkQ7uGHUCu5hnAFAj6mDe6Ea0SeOo= github.com/go-logr/zapr v1.2.4/go.mod h1:FyHWQIzQORZ0QVE1BtVHv3cKtNLuXsbNLtpuhNapBOA= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= @@ -48,8 +49,9 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -70,6 +72,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -85,10 +88,10 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/onsi/ginkgo/v2 v2.12.1 h1:uHNEO1RP2SpuZApSkel9nEh1/Mu+hmQe7Q+Pepg5OYA= -github.com/onsi/ginkgo/v2 v2.12.1/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= -github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= -github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= +github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= +github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= +github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -103,6 +106,7 @@ github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -114,13 +118,17 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/zncdata-labs/operator-go v0.0.0-20231222061826-114414d7e684 h1:ZOb5wpkxbvdwfj8Sh4bu7MEAOpP7NlzouoRDRxwQMV0= +github.com/zncdata-labs/operator-go v0.0.0-20231222061826-114414d7e684/go.mod h1:y5EDDKn3tt5X9RiO+xsVAw26Xk65bdO1j3R0w1MA5d4= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= +go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= @@ -137,6 +145,7 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= @@ -144,10 +153,10 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= -golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= -golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8= -golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/oauth2 v0.10.0 h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8= +golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -161,16 +170,16 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= -golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -205,29 +214,29 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.28.2 h1:9mpl5mOb6vXZvqbQmankOfPIGiudghwCoLl1EYfUZbw= -k8s.io/api v0.28.2/go.mod h1:RVnJBsjU8tcMq7C3iaRSGMeaKt2TWEUXcpIt/90fjEg= -k8s.io/apiextensions-apiserver v0.28.2 h1:J6/QRWIKV2/HwBhHRVITMLYoypCoPY1ftigDM0Kn+QU= -k8s.io/apiextensions-apiserver v0.28.2/go.mod h1:5tnkxLGa9nefefYzWuAlWZ7RZYuN/765Au8cWLA6SRg= -k8s.io/apimachinery v0.28.2 h1:KCOJLrc6gu+wV1BYgwik4AF4vXOlVJPdiqn0yAWWwXQ= -k8s.io/apimachinery v0.28.2/go.mod h1:RdzF87y/ngqk9H4z3EL2Rppv5jj95vGS/HaFXrLDApU= -k8s.io/client-go v0.28.2 h1:DNoYI1vGq0slMBN/SWKMZMw0Rq+0EQW6/AK4v9+3VeY= -k8s.io/client-go v0.28.2/go.mod h1:sMkApowspLuc7omj1FOSUxSoqjr+d5Q0Yc0LOFnYFJY= -k8s.io/component-base v0.28.2 h1:Yc1yU+6AQSlpJZyvehm/NkJBII72rzlEsd6MkBQ+G0E= -k8s.io/component-base v0.28.2/go.mod h1:4IuQPQviQCg3du4si8GpMrhAIegxpsgPngPRR/zWpzc= -k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= -k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= -k8s.io/kube-openapi v0.0.0-20230918164632-68afd615200d h1:/CFeJBjBrZvHX09rObS2+2iEEDevMWYc1v3aIYAjIYI= -k8s.io/kube-openapi v0.0.0-20230918164632-68afd615200d/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= -k8s.io/kubectl v0.28.2 h1:fOWOtU6S0smdNjG1PB9WFbqEIMlkzU5ahyHkc7ESHgM= -k8s.io/kubectl v0.28.2/go.mod h1:6EQWTPySF1fn7yKoQZHYf9TPwIl2AygHEcJoxFekr64= +k8s.io/api v0.29.0 h1:NiCdQMY1QOp1H8lfRyeEf8eOwV6+0xA6XEE44ohDX2A= +k8s.io/api v0.29.0/go.mod h1:sdVmXoz2Bo/cb77Pxi71IPTSErEW32xa4aXwKH7gfBA= +k8s.io/apiextensions-apiserver v0.28.3 h1:Od7DEnhXHnHPZG+W9I97/fSQkVpVPQx2diy+2EtmY08= +k8s.io/apiextensions-apiserver v0.28.3/go.mod h1:NE1XJZ4On0hS11aWWJUTNkmVB03j9LM7gJSisbRt8Lc= +k8s.io/apimachinery v0.29.0 h1:+ACVktwyicPz0oc6MTMLwa2Pw3ouLAfAon1wPLtG48o= +k8s.io/apimachinery v0.29.0/go.mod h1:eVBxQ/cwiJxH58eK/jd/vAk4mrxmVlnpBH5J2GbMeis= +k8s.io/client-go v0.29.0 h1:KmlDtFcrdUzOYrBhXHgKw5ycWzc3ryPX5mQe0SkG3y8= +k8s.io/client-go v0.29.0/go.mod h1:yLkXH4HKMAywcrD82KMSmfYg2DlE8mepPR4JGSo5n38= +k8s.io/component-base v0.29.0 h1:T7rjd5wvLnPBV1vC4zWd/iWRbV8Mdxs+nGaoaFzGw3s= +k8s.io/component-base v0.29.0/go.mod h1:sADonFTQ9Zc9yFLghpDpmNXEdHyQmFIGbiuZbqAXQ1M= +k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0= +k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo= +k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780= +k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= +k8s.io/kubectl v0.29.0 h1:Oqi48gXjikDhrBF67AYuZRTcJV4lg2l42GmvsP7FmYI= +k8s.io/kubectl v0.29.0/go.mod h1:0jMjGWIcMIQzmUaMgAzhSELv5WtHo2a8pq67DtviAJs= k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/controller-runtime v0.16.2 h1:mwXAVuEk3EQf478PQwQ48zGOXvW27UJc8NHktQVuIPU= -sigs.k8s.io/controller-runtime v0.16.2/go.mod h1:vpMu3LpI5sYWtujJOa2uPK61nB5rbwlN7BAB8aSLvGU= +sigs.k8s.io/controller-runtime v0.16.3 h1:2TuvuokmfXvDUamSx1SuAOO3eTyye+47mJCigwG62c4= +sigs.k8s.io/controller-runtime v0.16.3/go.mod h1:j7bialYoSn142nv9sCOJmQgDXQXxnroFU4VnX/brVJ0= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= -sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE= -sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E= +sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= +sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/internal/controller/handler.go b/internal/controller/handler.go index c7bdb82..820e7d4 100644 --- a/internal/controller/handler.go +++ b/internal/controller/handler.go @@ -3,6 +3,9 @@ package controller import ( "context" "fmt" + zncdataerr "github.com/zncdata-labs/operator-go/pkg/errors" + "github.com/zncdata-labs/operator-go/pkg/status" + "github.com/zncdata-labs/operator-go/pkg/utils" stackv1alpha1 "github.com/zncdata-labs/spark-k8s-operator/api/v1alpha1" appsv1 "k8s.io/api/apps/v1" @@ -16,7 +19,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" ) -func (r *SparkHistoryServerReconciler) makePVC(instance *stackv1alpha1.SparkHistoryServer, schema *runtime.Scheme) *corev1.PersistentVolumeClaim { +func (r *SparkHistoryServerReconciler) makePVC(instance *stackv1alpha1.SparkHistoryServer, schema *runtime.Scheme) (*corev1.PersistentVolumeClaim, error) { labels := instance.GetLabels() pvc := &corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ @@ -27,7 +30,7 @@ func (r *SparkHistoryServerReconciler) makePVC(instance *stackv1alpha1.SparkHist Spec: corev1.PersistentVolumeClaimSpec{ StorageClassName: instance.Spec.Persistence.StorageClassName, AccessModes: []corev1.PersistentVolumeAccessMode{corev1.PersistentVolumeAccessMode(instance.Spec.Persistence.AccessMode)}, - Resources: corev1.ResourceRequirements{ + Resources: corev1.VolumeResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceStorage: resource.MustParse(instance.Spec.Persistence.StorageSize), }, @@ -38,9 +41,9 @@ func (r *SparkHistoryServerReconciler) makePVC(instance *stackv1alpha1.SparkHist err := ctrl.SetControllerReference(instance, pvc, schema) if err != nil { r.Log.Error(err, "Failed to set controller reference for pvc") - return nil + return nil, zncdataerr.Wrap(err, "Failed to set controller reference for pvc") } - return pvc + return pvc, nil } func (r *SparkHistoryServerReconciler) reconcilePVC(ctx context.Context, instance *stackv1alpha1.SparkHistoryServer) error { @@ -51,9 +54,12 @@ func (r *SparkHistoryServerReconciler) reconcilePVC(ctx context.Context, instanc pvc := &corev1.PersistentVolumeClaim{} err := r.Client.Get(ctx, types.NamespacedName{Namespace: instance.Namespace, Name: instance.GetPvcName()}, pvc) if err != nil && errors.IsNotFound(err) { - pvc := r.makePVC(instance, r.Scheme) + pvc, err := r.makePVC(instance, r.Scheme) + if err != nil { + return err + } r.Log.Info("Creating a new PVC", "PVC.Namespace", pvc.Namespace, "PVC.Name", pvc.Name) - err := r.Client.Create(ctx, pvc) + err = r.Client.Create(ctx, pvc) if err != nil { return err } @@ -64,11 +70,9 @@ func (r *SparkHistoryServerReconciler) reconcilePVC(ctx context.Context, instanc return nil } -func (r *SparkHistoryServerReconciler) makeIngress(instance *stackv1alpha1.SparkHistoryServer, schema *runtime.Scheme) *v1.Ingress { +func (r *SparkHistoryServerReconciler) makeIngress(instance *stackv1alpha1.SparkHistoryServer, schema *runtime.Scheme) (*v1.Ingress, error) { labels := instance.GetLabels() - pt := v1.PathTypeImplementationSpecific - ing := &v1.Ingress{ ObjectMeta: metav1.ObjectMeta{ Name: instance.Name, @@ -103,16 +107,15 @@ func (r *SparkHistoryServerReconciler) makeIngress(instance *stackv1alpha1.Spark } err := ctrl.SetControllerReference(instance, ing, schema) if err != nil { - r.Log.Error(err, "Failed to set controller reference for ingress") - return nil + return nil, zncdataerr.Wrap(err, "Failed to set controller reference for ingress") } - return ing + return ing, nil } func (r *SparkHistoryServerReconciler) reconcileIngress(ctx context.Context, instance *stackv1alpha1.SparkHistoryServer) error { - obj := r.makeIngress(instance, r.Scheme) - if obj == nil { - return nil + obj, err := r.makeIngress(instance, r.Scheme) + if err != nil { + return err } if err := CreateOrUpdate(ctx, r.Client, obj); err != nil { @@ -123,19 +126,19 @@ func (r *SparkHistoryServerReconciler) reconcileIngress(ctx context.Context, ins if instance.Spec.Ingress.Enabled { url := fmt.Sprintf("http://%s", instance.Spec.Ingress.Host) if instance.Status.URLs == nil { - instance.Status.URLs = []stackv1alpha1.StatusURL{ + instance.Status.URLs = []status.URL{ { Name: "webui", URL: url, }, } - if err := r.UpdateStatus(ctx, instance); err != nil { + if err := utils.UpdateStatus(ctx, r.Client, instance); err != nil { return err } } else if instance.Spec.Ingress.Host != instance.Status.URLs[0].Name { instance.Status.URLs[0].URL = url - if err := r.UpdateStatus(ctx, instance); err != nil { + if err := utils.UpdateStatus(ctx, r.Client, instance); err != nil { return err } @@ -145,7 +148,7 @@ func (r *SparkHistoryServerReconciler) reconcileIngress(ctx context.Context, ins return nil } -func (r *SparkHistoryServerReconciler) makeService(instance *stackv1alpha1.SparkHistoryServer, schema *runtime.Scheme) *corev1.Service { +func (r *SparkHistoryServerReconciler) makeService(instance *stackv1alpha1.SparkHistoryServer, schema *runtime.Scheme) (*corev1.Service, error) { labels := instance.GetLabels() svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -168,16 +171,15 @@ func (r *SparkHistoryServerReconciler) makeService(instance *stackv1alpha1.Spark } err := ctrl.SetControllerReference(instance, svc, schema) if err != nil { - r.Log.Error(err, "Failed to set controller reference for service") - return nil + return nil, zncdataerr.Wrap(err, "Failed to set controller reference for service") } - return svc + return svc, nil } func (r *SparkHistoryServerReconciler) reconcileService(ctx context.Context, instance *stackv1alpha1.SparkHistoryServer) error { - obj := r.makeService(instance, r.Scheme) - if obj == nil { - return nil + obj, err := r.makeService(instance, r.Scheme) + if err != nil { + return err } if err := CreateOrUpdate(ctx, r.Client, obj); err != nil { @@ -187,7 +189,7 @@ func (r *SparkHistoryServerReconciler) reconcileService(ctx context.Context, ins return nil } -func (r *SparkHistoryServerReconciler) makeDeployment(instance *stackv1alpha1.SparkHistoryServer, schema *runtime.Scheme) *appsv1.Deployment { +func (r *SparkHistoryServerReconciler) makeDeployment(instance *stackv1alpha1.SparkHistoryServer, schema *runtime.Scheme) (*appsv1.Deployment, error) { labels := instance.GetLabels() dep := &appsv1.Deployment{ @@ -258,10 +260,9 @@ func (r *SparkHistoryServerReconciler) makeDeployment(instance *stackv1alpha1.Sp err := ctrl.SetControllerReference(instance, dep, schema) if err != nil { - r.Log.Error(err, "Failed to set controller reference for deployment") - return nil + return nil, zncdataerr.Wrap(err, "Failed to set controller reference for deployment") } - return dep + return dep, nil } func (r *SparkHistoryServerReconciler) updateStatusConditionWithDeployment(ctx context.Context, instance *stackv1alpha1.SparkHistoryServer, status metav1.ConditionStatus, message string) error { @@ -274,16 +275,16 @@ func (r *SparkHistoryServerReconciler) updateStatusConditionWithDeployment(ctx c LastTransitionTime: metav1.Now(), }) - if err := r.UpdateStatus(ctx, instance); err != nil { + if err := utils.UpdateStatus(ctx, r.Client, instance); err != nil { return err } return nil } func (r *SparkHistoryServerReconciler) reconcileDeployment(ctx context.Context, instance *stackv1alpha1.SparkHistoryServer) error { - obj := r.makeDeployment(instance, r.Scheme) - if obj == nil { - return nil + obj, err := r.makeDeployment(instance, r.Scheme) + if err != nil { + return err } if err := CreateOrUpdate(ctx, r.Client, obj); err != nil { logger.Error(err, "Failed to create or update deployment") diff --git a/internal/controller/sparkhistoryserver_controller.go b/internal/controller/sparkhistoryserver_controller.go index 1ff5c57..2b81aa5 100644 --- a/internal/controller/sparkhistoryserver_controller.go +++ b/internal/controller/sparkhistoryserver_controller.go @@ -19,11 +19,11 @@ package controller import ( "context" "github.com/go-logr/logr" + "github.com/zncdata-labs/operator-go/pkg/utils" stackv1alpha1 "github.com/zncdata-labs/spark-k8s-operator/api/v1alpha1" apimeta "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/util/retry" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -75,7 +75,8 @@ func (r *SparkHistoryServerReconciler) Reconcile(ctx context.Context, req ctrl.R if readCondition == nil || readCondition.ObservedGeneration != sparkHistory.GetGeneration() { sparkHistory.InitStatusConditions() - if err := r.UpdateStatus(ctx, sparkHistory); err != nil { + if err := utils.UpdateStatus(ctx, r.Client, sparkHistory); err != nil { + r.Log.Error(err, "unable to update SparkHistoryServer status") return ctrl.Result{}, err } } @@ -110,7 +111,8 @@ func (r *SparkHistoryServerReconciler) Reconcile(ctx context.Context, req ctrl.R ObservedGeneration: sparkHistory.GetGeneration(), }) - if err := r.UpdateStatus(ctx, sparkHistory); err != nil { + if err := utils.UpdateStatus(ctx, r.Client, sparkHistory); err != nil { + r.Log.Error(err, "unable to update SparkHistoryServer status") return ctrl.Result{}, err } @@ -118,32 +120,6 @@ func (r *SparkHistoryServerReconciler) Reconcile(ctx context.Context, req ctrl.R return ctrl.Result{}, nil } -// UpdateStatus updates the status of the SparkHistoryServer resource -// https://stackoverflow.com/questions/76388004/k8s-controller-update-status-and-condition -func (r *SparkHistoryServerReconciler) UpdateStatus(ctx context.Context, instance *stackv1alpha1.SparkHistoryServer) error { - retryErr := retry.RetryOnConflict(retry.DefaultRetry, func() error { - return r.Status().Update(ctx, instance) - //return r.Status().Patch(ctx, instance, client.MergeFrom(instance)) - }) - - if retryErr != nil { - r.Log.Error(retryErr, "Failed to update vfm status after retries") - return retryErr - } - - //if err := r.Get(ctx, key, latest); err != nil { - // r.Log.Error(err, "Failed to get latest object") - // return err - //} - // - //if err := r.Status().Patch(ctx, instance, client.MergeFrom(instance)); err != nil { - // r.Log.Error(err, "Failed to patch object status") - // return err - //} - r.Log.V(1).Info("Successfully patched object status") - return nil -} - // SetupWithManager sets up the controller with the Manager. func (r *SparkHistoryServerReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). From 29f9b03da9f27422b93bcd4dc4b5015bea723d21 Mon Sep 17 00:00:00 2001 From: wastill <2225144254@qq.com> Date: Tue, 26 Dec 2023 10:04:28 +0800 Subject: [PATCH 2/2] feat(api): Extraction of public structures 1. Extraction of public structures 1. ingress 2. service 3. status --- api/v1alpha1/sparkhistoryserver_types.go | 1 + go.mod | 2 +- go.sum | 4 +- internal/controller/handler.go | 1 - .../sparkhistoryserver_controller.go | 74 ++++++++++++++++--- 5 files changed, 68 insertions(+), 14 deletions(-) diff --git a/api/v1alpha1/sparkhistoryserver_types.go b/api/v1alpha1/sparkhistoryserver_types.go index 06e6b1a..9fbcdd9 100644 --- a/api/v1alpha1/sparkhistoryserver_types.go +++ b/api/v1alpha1/sparkhistoryserver_types.go @@ -92,6 +92,7 @@ func (sparkHistory *SparkHistoryServer) SetStatusCondition(condition metav1.Cond // InitStatusConditions initializes the status conditions to the provided conditions. func (sparkHistory *SparkHistoryServer) InitStatusConditions() { + sparkHistory.Status.InitStatus(sparkHistory) sparkHistory.Status.InitStatusConditions() } diff --git a/go.mod b/go.mod index d75fe71..d9f6f7b 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/onsi/ginkgo/v2 v2.13.0 github.com/onsi/gomega v1.29.0 - github.com/zncdata-labs/operator-go v0.0.0-20231222061826-114414d7e684 + github.com/zncdata-labs/operator-go v0.0.0-20231225134925-0f88208e24da k8s.io/api v0.29.0 k8s.io/apimachinery v0.29.0 k8s.io/client-go v0.29.0 diff --git a/go.sum b/go.sum index 74b4112..64afc58 100644 --- a/go.sum +++ b/go.sum @@ -123,8 +123,8 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/zncdata-labs/operator-go v0.0.0-20231222061826-114414d7e684 h1:ZOb5wpkxbvdwfj8Sh4bu7MEAOpP7NlzouoRDRxwQMV0= -github.com/zncdata-labs/operator-go v0.0.0-20231222061826-114414d7e684/go.mod h1:y5EDDKn3tt5X9RiO+xsVAw26Xk65bdO1j3R0w1MA5d4= +github.com/zncdata-labs/operator-go v0.0.0-20231225134925-0f88208e24da h1:xWJEMqTlkTbhJ5WJ4xwO5/uRBry6okxjejAZqOTjIrs= +github.com/zncdata-labs/operator-go v0.0.0-20231225134925-0f88208e24da/go.mod h1:y5EDDKn3tt5X9RiO+xsVAw26Xk65bdO1j3R0w1MA5d4= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= diff --git a/internal/controller/handler.go b/internal/controller/handler.go index 820e7d4..95635a5 100644 --- a/internal/controller/handler.go +++ b/internal/controller/handler.go @@ -6,7 +6,6 @@ import ( zncdataerr "github.com/zncdata-labs/operator-go/pkg/errors" "github.com/zncdata-labs/operator-go/pkg/status" "github.com/zncdata-labs/operator-go/pkg/utils" - stackv1alpha1 "github.com/zncdata-labs/spark-k8s-operator/api/v1alpha1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" diff --git a/internal/controller/sparkhistoryserver_controller.go b/internal/controller/sparkhistoryserver_controller.go index 2b81aa5..9aa8196 100644 --- a/internal/controller/sparkhistoryserver_controller.go +++ b/internal/controller/sparkhistoryserver_controller.go @@ -19,6 +19,7 @@ package controller import ( "context" "github.com/go-logr/logr" + "github.com/zncdata-labs/operator-go/pkg/status" "github.com/zncdata-labs/operator-go/pkg/utils" stackv1alpha1 "github.com/zncdata-labs/spark-k8s-operator/api/v1alpha1" apimeta "k8s.io/apimachinery/pkg/api/meta" @@ -71,7 +72,7 @@ func (r *SparkHistoryServerReconciler) Reconcile(ctx context.Context, req ctrl.R // Get the status condition, if it exists and its generation is not the //same as the SparkHistoryServer's generation, reset the status conditions - readCondition := apimeta.FindStatusCondition(sparkHistory.Status.Conditions, stackv1alpha1.ConditionTypeProgressing) + readCondition := apimeta.FindStatusCondition(sparkHistory.Status.Conditions, status.ConditionTypeProgressing) if readCondition == nil || readCondition.ObservedGeneration != sparkHistory.GetGeneration() { sparkHistory.InitStatusConditions() @@ -87,33 +88,86 @@ func (r *SparkHistoryServerReconciler) Reconcile(ctx context.Context, req ctrl.R r.Log.Error(err, "unable to reconcile PVC") return ctrl.Result{}, err } + if updated := sparkHistory.Status.SetStatusCondition(metav1.Condition{ + Type: status.ConditionTypeReconcilePVC, + Status: metav1.ConditionTrue, + Reason: status.ConditionReasonRunning, + Message: "SparkHistoryServer's PVC is running", + ObservedGeneration: sparkHistory.GetGeneration(), + }); updated { + if err := utils.UpdateStatus(ctx, r.Client, sparkHistory); err != nil { + r.Log.Error(err, "unable to update status for PVC") + return ctrl.Result{}, err + } + } if err := r.reconcileDeployment(ctx, sparkHistory); err != nil { r.Log.Error(err, "unable to reconcile Deployment") return ctrl.Result{}, err } + if updated := sparkHistory.Status.SetStatusCondition(metav1.Condition{ + Type: status.ConditionTypeReconcileDeployment, + Status: metav1.ConditionTrue, + Reason: status.ConditionReasonRunning, + Message: "SparkHistoryServer's deployment is running", + ObservedGeneration: sparkHistory.GetGeneration(), + }); updated { + if err := utils.UpdateStatus(ctx, r.Client, sparkHistory); err != nil { + r.Log.Error(err, "unable to update status for Deployment") + return ctrl.Result{}, err + } + } + if err := r.reconcileService(ctx, sparkHistory); err != nil { r.Log.Error(err, "unable to reconcile Service") return ctrl.Result{}, err } + if updated := sparkHistory.Status.SetStatusCondition(metav1.Condition{ + Type: status.ConditionTypeReconcileService, + Status: metav1.ConditionTrue, + Reason: status.ConditionReasonRunning, + Message: "SparkHistoryServer's service is running", + ObservedGeneration: sparkHistory.GetGeneration(), + }); updated { + err := utils.UpdateStatus(ctx, r.Client, sparkHistory) + if err != nil { + r.Log.Error(err, "unable to update status for Service") + return ctrl.Result{}, err + } + } if err := r.reconcileIngress(ctx, sparkHistory); err != nil { r.Log.Error(err, "unable to reconcile Ingress") return ctrl.Result{}, err } - - sparkHistory.SetStatusCondition(metav1.Condition{ - Type: stackv1alpha1.ConditionTypeAvailable, + if updated := sparkHistory.Status.SetStatusCondition(metav1.Condition{ + Type: status.ConditionTypeReconcileIngress, Status: metav1.ConditionTrue, - Reason: stackv1alpha1.ConditionReasonRunning, - Message: "SparkHistoryServer is running", + Reason: status.ConditionReasonRunning, + Message: "SparkHistoryServer's ingress is running", ObservedGeneration: sparkHistory.GetGeneration(), - }) + }); updated { + err := utils.UpdateStatus(ctx, r.Client, sparkHistory) + if err != nil { + r.Log.Error(err, "unable to update status for Ingress") + return ctrl.Result{}, err + } + } - if err := utils.UpdateStatus(ctx, r.Client, sparkHistory); err != nil { - r.Log.Error(err, "unable to update SparkHistoryServer status") - return ctrl.Result{}, err + if !sparkHistory.Status.IsAvailable() { + sparkHistory.SetStatusCondition(metav1.Condition{ + Type: status.ConditionTypeAvailable, + Status: metav1.ConditionTrue, + Reason: status.ConditionReasonRunning, + Message: "SparkHistoryServer is running", + ObservedGeneration: sparkHistory.GetGeneration(), + }) + + if err := utils.UpdateStatus(ctx, r.Client, sparkHistory); err != nil { + r.Log.Error(err, "unable to update SparkHistoryServer status") + return ctrl.Result{}, err + } } r.Log.Info("Successfully reconciled SparkHistoryServer")