Skip to content

Commit

Permalink
fix(status): remove unnecessary default
Browse files Browse the repository at this point in the history
1. remove unnecessary default
  • Loading branch information
wastill committed Jan 3, 2024
1 parent a73f8d2 commit 7e82b86
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 28 deletions.
1 change: 0 additions & 1 deletion pkg/image/image_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import corev1 "k8s.io/api/core/v1"

type ImageSpec struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default:="bitnami/spark"
Repository string `json:"repository,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:default:="3.4.1"
Expand Down
1 change: 0 additions & 1 deletion pkg/ingress/ingress_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type IngressSpec struct {
// +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"`
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1alphav1 //nolint:typecheck
package v1alpha1 //nolint:typecheck
import (
"github.com/zncdata-labs/operator-go/pkg/status"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -29,8 +29,8 @@ type Database struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DatabaseSpec `json:"spec,omitempty"`
Status status.ZncdataStatus `json:"status,omitempty"`
Spec DatabaseSpec `json:"spec,omitempty"`
Status status.Status `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1alphav1
package v1alpha1

import (
"github.com/zncdata-labs/operator-go/pkg/status"
Expand Down Expand Up @@ -26,7 +26,7 @@ type DatabaseConnection struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DatabaseConnectionSpec `json:"spec,omitempty"`
Status status.ZncdataStatus `json:"status,omitempty"`
Status status.Status `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1alphav1
package v1alpha1

// DatabaseProvider defines all types database provider of DatabaseConnection
type DatabaseProvider struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1alphav1
package v1alpha1

import (
"github.com/zncdata-labs/operator-go/pkg/status"
Expand Down Expand Up @@ -37,8 +37,8 @@ type S3Bucket struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec S3BucketSpec `json:"spec,omitempty"`
Status status.ZncdataStatus `json:"status,omitempty"`
Spec S3BucketSpec `json:"spec,omitempty"`
Status status.Status `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1alphav1
package v1alpha1

import (
"github.com/zncdata-labs/operator-go/pkg/status"
Expand Down Expand Up @@ -35,8 +35,8 @@ type S3Connection struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec S3ConnectionSpec `json:"spec,omitempty"`
Status status.ZncdataStatus `json:"status,omitempty"`
Spec S3ConnectionSpec `json:"spec,omitempty"`
Status status.Status `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/service/service_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type ServiceSpec struct {
Type corev1.ServiceType `json:"type,omitempty"`
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
// +kubebuilder:default=18080
Port int32 `json:"port"`
}

Expand Down
22 changes: 11 additions & 11 deletions pkg/status/zncdata_status.go → pkg/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// ZncdataStatus defines the common state of Zncdata
type ZncdataStatus struct {
// Status defines the common status
type Status struct {
// +kubebuilder:validation:Optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
// +kubebuilder:validation:Optional
Expand All @@ -19,12 +19,12 @@ type ZncdataStatus struct {
}

// IsAvailable returns true if the status is available.
func (status *ZncdataStatus) IsAvailable() bool {
func (status *Status) IsAvailable() bool {
return apimeta.IsStatusConditionTrue(status.Conditions, ConditionTypeAvailable)
}

// SetStatusCondition sets the status condition.
func (status *ZncdataStatus) SetStatusCondition(condition metav1.Condition) (updated bool) {
func (status *Status) SetStatusCondition(condition metav1.Condition) (updated bool) {
// if the condition already exists, update it
existingCondition := apimeta.FindStatusCondition(status.Conditions, condition.Type)
if existingCondition == nil {
Expand All @@ -45,7 +45,7 @@ func (status *ZncdataStatus) SetStatusCondition(condition metav1.Condition) (upd
}

// InitStatusConditions initializes the status conditions to the provided conditions.
func (status *ZncdataStatus) InitStatusConditions() {
func (status *Status) InitStatusConditions() {
status.Conditions = []metav1.Condition{}
status.SetStatusCondition(metav1.Condition{
Type: ConditionTypeProgressing,
Expand All @@ -66,7 +66,7 @@ func (status *ZncdataStatus) InitStatusConditions() {
}

// InitStatus initializes the status.
func (status *ZncdataStatus) InitStatus(object client.Object) {
func (status *Status) InitStatus(object client.Object) {
generation := object.GetGeneration()
name := object.GetName()
kind := object.GetObjectKind().GroupVersionKind().Kind
Expand All @@ -76,7 +76,7 @@ func (status *ZncdataStatus) InitStatus(object client.Object) {
}

// GetGeneration returns the status's generation.
func (status *ZncdataStatus) GetGeneration() int64 {
func (status *Status) GetGeneration() int64 {
return status.Generation
}

Expand All @@ -87,7 +87,7 @@ type URL struct {
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ZncdataStatus) DeepCopyInto(out *ZncdataStatus) {
func (in *Status) DeepCopyInto(out *Status) {
*out = *in
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
Expand All @@ -103,12 +103,12 @@ func (in *ZncdataStatus) DeepCopyInto(out *ZncdataStatus) {
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ZncdataStatus.
func (in *ZncdataStatus) DeepCopy() *ZncdataStatus {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Status.
func (in *Status) DeepCopy() *Status {
if in == nil {
return nil
}
out := new(ZncdataStatus)
out := new(Status)
in.DeepCopyInto(out)
return out
}
2 changes: 1 addition & 1 deletion pkg/utils/reconcilier_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func CreateOrUpdate(ctx context.Context, c client.Client, obj client.Object) err
return err
}

// UpdateStatus updates the status of the SparkHistoryServer resource
// UpdateStatus updates the status of the Server resource
// https://stackoverflow.com/questions/76388004/k8s-controller-update-status-and-condition
func UpdateStatus(ctx context.Context, reconcilier client.Client, instance client.Object) error {
retryErr := retry.RetryOnConflict(retry.DefaultRetry, func() error {
Expand Down

0 comments on commit 7e82b86

Please sign in to comment.