Skip to content

Commit

Permalink
Address Matt' comments on server side
Browse files Browse the repository at this point in the history
  • Loading branch information
chinhtranvan committed Feb 16, 2024
1 parent ee51d7a commit 816800c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/verticarestorepointsquery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type VerticaRestorePointsQueryStatus struct {
// +operator-sdk:csv:customresourcedefinitions:type=status
// This contains the result of the restore points query. Check the QueryComplete
// status condition to know when this has been populated by the operator.
RestorePoints []vclusterops.RestorePoint `json:"restorePoints,omitempty"`
RestorePoints []vclusterops.RestorePoint `json:"restorePoints"`
}

const (
Expand Down
5 changes: 3 additions & 2 deletions pkg/controllers/vrpq/query_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/go-logr/logr"
ops "github.com/vertica/vcluster/vclusterops"
vapi "github.com/vertica/vertica-kubernetes/api/v1"
v1beta1 "github.com/vertica/vertica-kubernetes/api/v1beta1"
"github.com/vertica/vertica-kubernetes/pkg/controllers"
Expand Down Expand Up @@ -146,7 +147,7 @@ func (q *QueryReconciler) runShowRestorePoints(ctx context.Context, dispatcher v
opts []showrestorepoints.Option) (err error) {
// set Querying status condition ,state and restore points prior to calling vclusterops API
err = vrpqstatus.Update(ctx, q.VRec.Client, q.VRec.Log, q.Vrpq,
[]*metav1.Condition{vapi.MakeCondition(v1beta1.Querying, metav1.ConditionTrue, "Started")}, stateQuerying, nil)
[]*metav1.Condition{vapi.MakeCondition(v1beta1.Querying, metav1.ConditionTrue, "Started")}, stateQuerying, []ops.RestorePoint{})
if err != nil {
return err
}
Expand All @@ -159,7 +160,7 @@ func (q *QueryReconciler) runShowRestorePoints(ctx context.Context, dispatcher v
if errRun != nil {
q.VRec.Event(q.Vrpq, corev1.EventTypeWarning, events.ShowRestorePointsFailed, "Failed when calling show restore points")
err = vrpqstatus.Update(ctx, q.VRec.Client, q.VRec.Log, q.Vrpq,
[]*metav1.Condition{vapi.MakeCondition(v1beta1.Querying, metav1.ConditionFalse, "Failed")}, stateFailedQuery, nil)
[]*metav1.Condition{vapi.MakeCondition(v1beta1.Querying, metav1.ConditionFalse, "Failed")}, stateFailedQuery, []ops.RestorePoint{})
if err != nil {
errRun = errors.Join(errRun, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/vrpq/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (*MockVClusterOps) VReviveDatabase(_ *vclusterops.VReviveDatabaseOptions) (
return "", nil, nil
}
func (*MockVClusterOps) VShowRestorePoints(_ *vclusterops.VShowRestorePointsOptions) ([]vclusterops.RestorePoint, error) {
return nil, nil
return []vclusterops.RestorePoint{}, nil
}
func (*MockVClusterOps) VStartDatabase(_ *vclusterops.VStartDatabaseOptions) error {
return nil
Expand Down
8 changes: 5 additions & 3 deletions pkg/controllers/vrpq/vdbverify_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"

"github.com/go-logr/logr"
ops "github.com/vertica/vcluster/vclusterops"
vapi "github.com/vertica/vertica-kubernetes/api/v1"
v1beta1 "github.com/vertica/vertica-kubernetes/api/v1beta1"
"github.com/vertica/vertica-kubernetes/pkg/controllers"
Expand Down Expand Up @@ -61,6 +62,7 @@ func (q *VDBVerifyReconciler) Reconcile(ctx context.Context, _ *ctrl.Request) (c
}

vdb := &vapi.VerticaDB{}
restorePoints := []ops.RestorePoint{}
nm := names.GenNamespacedName(q.Vrpq, q.Vrpq.Spec.VerticaDBName)
if res, err := vk8s.FetchVDB(ctx, q.VRec, q.Vrpq, nm, vdb); verrors.IsReconcileAborted(res, err) {
return res, err
Expand All @@ -75,7 +77,7 @@ func (q *VDBVerifyReconciler) Reconcile(ctx context.Context, _ *ctrl.Request) (c
q.VRec.Eventf(q.Vrpq, corev1.EventTypeWarning, events.RestoreNotSupported,
"The Vertica version '%s' doesn't support in-database restore points", vinf.VdbVer)
err = vrpqstatus.Update(ctx, q.VRec.Client, q.VRec.Log, q.Vrpq,
[]*metav1.Condition{vapi.MakeCondition(v1beta1.QueryReady, metav1.ConditionFalse, "IncompatibleDB")}, stateIncompatibleDB, nil)
[]*metav1.Condition{vapi.MakeCondition(v1beta1.QueryReady, metav1.ConditionFalse, "IncompatibleDB")}, stateIncompatibleDB, restorePoints)
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -87,12 +89,12 @@ func (q *VDBVerifyReconciler) Reconcile(ctx context.Context, _ *ctrl.Request) (c
q.VRec.Event(q.Vrpq, corev1.EventTypeWarning, events.AdmintoolsNotSupported,
"ShowRestorePoints is not supported for admintools deployments")
err = vrpqstatus.Update(ctx, q.VRec.Client, q.VRec.Log, q.Vrpq,
[]*metav1.Condition{vapi.MakeCondition(v1beta1.QueryReady, metav1.ConditionFalse, "AdmintoolsNotSupported")}, stateIncompatibleDB, nil)
[]*metav1.Condition{vapi.MakeCondition(v1beta1.QueryReady, metav1.ConditionFalse, "AdmintoolsNotSupported")}, stateIncompatibleDB, restorePoints)
if err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}
return ctrl.Result{}, vrpqstatus.Update(ctx, q.VRec.Client, q.VRec.Log, q.Vrpq,
[]*metav1.Condition{vapi.MakeCondition(v1beta1.QueryReady, metav1.ConditionTrue, "Completed")}, stateQuerying, nil)
[]*metav1.Condition{vapi.MakeCondition(v1beta1.QueryReady, metav1.ConditionTrue, "Completed")}, stateQuerying, restorePoints)
}
14 changes: 7 additions & 7 deletions pkg/vrpqstatus/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var _ = Describe("status", func() {
cond := []metav1.Condition{
{Type: vapi.Querying, Status: metav1.ConditionTrue, Reason: v1.UnknownReason},
}
Expect(Update(ctx, k8sClient, logger, vrpq, []*metav1.Condition{&cond[0]}, "", nil)).Should(Succeed())
Expect(Update(ctx, k8sClient, logger, vrpq, []*metav1.Condition{&cond[0]}, "", []vclusterops.RestorePoint{})).Should(Succeed())
fetchVdb := &vapi.VerticaRestorePointsQuery{}
nm := types.NamespacedName{Namespace: vrpq.Namespace, Name: vrpq.Name}
Expect(k8sClient.Get(ctx, nm, fetchVdb)).Should(Succeed())
Expand All @@ -107,7 +107,7 @@ var _ = Describe("status", func() {
{Type: vapi.Querying, Status: metav1.ConditionFalse, Reason: v1.UnknownReason},
}
for i := range conds {
Expect(Update(ctx, k8sClient, logger, vrpq, []*metav1.Condition{&conds[i]}, "", nil)).Should(Succeed())
Expect(Update(ctx, k8sClient, logger, vrpq, []*metav1.Condition{&conds[i]}, "", []vclusterops.RestorePoint{})).Should(Succeed())
fetchVdb := &vapi.VerticaRestorePointsQuery{}
nm := types.NamespacedName{Namespace: vrpq.Namespace, Name: vrpq.Name}
Expect(k8sClient.Get(ctx, nm, fetchVdb)).Should(Succeed())
Expand All @@ -130,7 +130,7 @@ var _ = Describe("status", func() {
}

for i := range conds {
Expect(Update(ctx, k8sClient, logger, vrpq, []*metav1.Condition{&conds[i]}, "", nil)).Should(Succeed())
Expect(Update(ctx, k8sClient, logger, vrpq, []*metav1.Condition{&conds[i]}, "", []vclusterops.RestorePoint{})).Should(Succeed())
}

fetchVdb := &vapi.VerticaRestorePointsQuery{}
Expand All @@ -150,10 +150,10 @@ var _ = Describe("status", func() {
origTime := metav1.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC)
Expect(Update(ctx, k8sClient, logger, vrpq,
[]*metav1.Condition{{Type: vapi.Querying, Status: metav1.ConditionFalse, LastTransitionTime: origTime,
Reason: v1.UnknownReason}}, "", nil)).Should(Succeed())
Reason: v1.UnknownReason}}, "", []vclusterops.RestorePoint{})).Should(Succeed())
Expect(Update(ctx, k8sClient, logger, vrpq,
[]*metav1.Condition{{Type: vapi.Querying, Status: metav1.ConditionTrue, LastTransitionTime: origTime,
Reason: v1.UnknownReason}}, "", nil)).Should(Succeed())
Reason: v1.UnknownReason}}, "", []vclusterops.RestorePoint{})).Should(Succeed())
Expect(vrpq.Status.Conditions[0].LastTransitionTime).ShouldNot(Equal(origTime))
})

Expand All @@ -166,14 +166,14 @@ var _ = Describe("status", func() {
cond := v1.MakeCondition(vapi.Querying, metav1.ConditionTrue, "")

Expect(Update(ctx, k8sClient, logger, vrpq,
[]*metav1.Condition{cond}, msg, nil)).Should(Succeed())
[]*metav1.Condition{cond}, msg, []vclusterops.RestorePoint{})).Should(Succeed())

nm := types.NamespacedName{Namespace: vrpq.Namespace, Name: vrpq.Name}
Expect(k8sClient.Get(ctx, nm, vrpq)).Should(Succeed())
Expect(vrpq.Status.State).Should(Equal(msg))

Expect(Update(ctx, k8sClient, logger, vrpq,
[]*metav1.Condition{cond}, msg1, nil)).Should(Succeed())
[]*metav1.Condition{cond}, msg1, []vclusterops.RestorePoint{})).Should(Succeed())
Expect(k8sClient.Get(ctx, nm, vrpq)).Should(Succeed())
Expect(vrpq.Status.State).Should(Equal(msg1))
})
Expand Down

0 comments on commit 816800c

Please sign in to comment.