Skip to content

Commit

Permalink
Make lastSyncedTime a pointer to all nil value (#466)
Browse files Browse the repository at this point in the history
- Reconciling last synced time fails when the sync fails as it tries to
  set time to a null value. By updating the type of LastSyncedTime to a
pointer, it gets assined nil on failure, which can reconcile
successfully.
  • Loading branch information
Ashwin Venkatesh authored Mar 25, 2021
1 parent 06f75dd commit 3c5e456
Show file tree
Hide file tree
Showing 21 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion api/common/configentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ConfigEntryResource interface {
// SetSyncedCondition updates the synced condition.
SetSyncedCondition(status corev1.ConditionStatus, reason, message string)
// SetLastSyncedTime updates the last synced time.
SetLastSyncedTime(time metav1.Time)
SetLastSyncedTime(time *metav1.Time)
// SyncedCondition gets the synced condition.
SyncedCondition() (status corev1.ConditionStatus, reason, message string)
// SyncedConditionStatus returns the status of the synced condition.
Expand Down
2 changes: 1 addition & 1 deletion api/common/configentry_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (in *mockConfigEntry) ConsulName() string {

func (in *mockConfigEntry) SetSyncedCondition(_ corev1.ConditionStatus, _ string, _ string) {}

func (in *mockConfigEntry) SetLastSyncedTime(_ metav1.Time) {}
func (in *mockConfigEntry) SetLastSyncedTime(_ *metav1.Time) {}

func (in *mockConfigEntry) SyncedCondition() (status corev1.ConditionStatus, reason string, message string) {
return corev1.ConditionTrue, "", ""
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/ingressgateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (in *IngressGateway) SetSyncedCondition(status corev1.ConditionStatus, reas
}
}

func (in *IngressGateway) SetLastSyncedTime(time metav1.Time) {
func (in *IngressGateway) SetLastSyncedTime(time *metav1.Time) {
in.Status.LastSyncedTime = time
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/ingressgateway_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,9 @@ func TestIngressGateway_SetSyncedCondition(t *testing.T) {
func TestIngressGateway_SetLastSyncedTime(t *testing.T) {
ingressGateway := &IngressGateway{}
syncedTime := metav1.NewTime(time.Now())
ingressGateway.SetLastSyncedTime(syncedTime)
ingressGateway.SetLastSyncedTime(&syncedTime)

require.Equal(t, syncedTime, ingressGateway.Status.LastSyncedTime)
require.Equal(t, &syncedTime, ingressGateway.Status.LastSyncedTime)
}

func TestIngressGateway_GetSyncedConditionStatus(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/proxydefaults_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (in *ProxyDefaults) SetSyncedCondition(status corev1.ConditionStatus, reaso
}
}

func (in *ProxyDefaults) SetLastSyncedTime(time metav1.Time) {
func (in *ProxyDefaults) SetLastSyncedTime(time *metav1.Time) {
in.Status.LastSyncedTime = time
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/proxydefaults_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ func TestProxyDefaults_SetSyncedCondition(t *testing.T) {
func TestProxyDefaults_SetLastSyncedTime(t *testing.T) {
proxyDefaults := &ProxyDefaults{}
syncedTime := metav1.NewTime(time.Now())
proxyDefaults.SetLastSyncedTime(syncedTime)
proxyDefaults.SetLastSyncedTime(&syncedTime)

require.Equal(t, syncedTime, proxyDefaults.Status.LastSyncedTime)
require.Equal(t, &syncedTime, proxyDefaults.Status.LastSyncedTime)
}

func TestProxyDefaults_GetSyncedConditionStatus(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/servicedefaults_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (in *ServiceDefaults) SetSyncedCondition(status corev1.ConditionStatus, rea
}
}

func (in *ServiceDefaults) SetLastSyncedTime(time metav1.Time) {
func (in *ServiceDefaults) SetLastSyncedTime(time *metav1.Time) {
in.Status.LastSyncedTime = time
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/servicedefaults_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ func TestServiceDefaults_SetSyncedCondition(t *testing.T) {
func TestServiceDefaults_SetLastSyncedTime(t *testing.T) {
serviceDefaults := &ServiceDefaults{}
syncedTime := metav1.NewTime(time.Now())
serviceDefaults.SetLastSyncedTime(syncedTime)
serviceDefaults.SetLastSyncedTime(&syncedTime)

require.Equal(t, syncedTime, serviceDefaults.Status.LastSyncedTime)
require.Equal(t, &syncedTime, serviceDefaults.Status.LastSyncedTime)
}

func TestServiceDefaults_GetSyncedConditionStatus(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/serviceintentions_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (in *ServiceIntentions) SetSyncedCondition(status corev1.ConditionStatus, r
}
}

func (in *ServiceIntentions) SetLastSyncedTime(time metav1.Time) {
func (in *ServiceIntentions) SetLastSyncedTime(time *metav1.Time) {
in.Status.LastSyncedTime = time
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/serviceintentions_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ func TestServiceIntentions_SetSyncedCondition(t *testing.T) {
func TestServiceIntentions_SetLastSyncedTime(t *testing.T) {
serviceIntentions := &ServiceIntentions{}
syncedTime := metav1.NewTime(time.Now())
serviceIntentions.SetLastSyncedTime(syncedTime)
serviceIntentions.SetLastSyncedTime(&syncedTime)

require.Equal(t, syncedTime, serviceIntentions.Status.LastSyncedTime)
require.Equal(t, &syncedTime, serviceIntentions.Status.LastSyncedTime)
}

func TestServiceIntentions_GetSyncedConditionStatus(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/serviceresolver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (in *ServiceResolver) SetSyncedCondition(status corev1.ConditionStatus, rea
}
}

func (in *ServiceResolver) SetLastSyncedTime(time metav1.Time) {
func (in *ServiceResolver) SetLastSyncedTime(time *metav1.Time) {
in.Status.LastSyncedTime = time
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/serviceresolver_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ func TestServiceResolver_SetSyncedCondition(t *testing.T) {
func TestServiceResolver_SetLastSyncedTime(t *testing.T) {
serviceResolver := &ServiceResolver{}
syncedTime := metav1.NewTime(time.Now())
serviceResolver.SetLastSyncedTime(syncedTime)
serviceResolver.SetLastSyncedTime(&syncedTime)

require.Equal(t, syncedTime, serviceResolver.Status.LastSyncedTime)
require.Equal(t, &syncedTime, serviceResolver.Status.LastSyncedTime)
}

func TestServiceResolver_GetSyncedConditionStatus(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/servicerouter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (in *ServiceRouter) SetSyncedCondition(status corev1.ConditionStatus, reaso
}
}

func (in *ServiceRouter) SetLastSyncedTime(time metav1.Time) {
func (in *ServiceRouter) SetLastSyncedTime(time *metav1.Time) {
in.Status.LastSyncedTime = time
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/servicerouter_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ func TestServiceRouter_SetSyncedCondition(t *testing.T) {
func TestServiceRouter_SetLastSyncedTime(t *testing.T) {
serviceRouter := &ServiceRouter{}
syncedTime := metav1.NewTime(time.Now())
serviceRouter.SetLastSyncedTime(syncedTime)
serviceRouter.SetLastSyncedTime(&syncedTime)

require.Equal(t, syncedTime, serviceRouter.Status.LastSyncedTime)
require.Equal(t, &syncedTime, serviceRouter.Status.LastSyncedTime)
}

func TestServiceRouter_GetSyncedConditionStatus(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/servicesplitter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (in *ServiceSplitter) SetSyncedCondition(status corev1.ConditionStatus, rea
}
}

func (in *ServiceSplitter) SetLastSyncedTime(time metav1.Time) {
func (in *ServiceSplitter) SetLastSyncedTime(time *metav1.Time) {
in.Status.LastSyncedTime = time
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/servicesplitter_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ func TestServiceSplitter_SetSyncedCondition(t *testing.T) {
func TestServiceSplitter_SetLastSyncedTime(t *testing.T) {
serviceSplitter := &ServiceSplitter{}
syncedTime := metav1.NewTime(time.Now())
serviceSplitter.SetLastSyncedTime(syncedTime)
serviceSplitter.SetLastSyncedTime(&syncedTime)

require.Equal(t, syncedTime, serviceSplitter.Status.LastSyncedTime)
require.Equal(t, &syncedTime, serviceSplitter.Status.LastSyncedTime)
}

func TestServiceSplitter_GetSyncedConditionStatus(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type Status struct {

// LastSyncedTime is the last time the resource successfully synced with Consul.
// +optional
LastSyncedTime metav1.Time `json:"lastSyncedTime,omitempty" description:"last time the condition transitioned from one status to another"`
LastSyncedTime *metav1.Time `json:"lastSyncedTime,omitempty" description:"last time the condition transitioned from one status to another"`
}

func (s *Status) GetCondition(t ConditionType) *Condition {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/terminatinggateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (in *TerminatingGateway) SetSyncedCondition(status corev1.ConditionStatus,
}
}

func (in *TerminatingGateway) SetLastSyncedTime(time metav1.Time) {
func (in *TerminatingGateway) SetLastSyncedTime(time *metav1.Time) {
in.Status.LastSyncedTime = time
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/terminatinggateway_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ func TestTerminatingGateway_SetSyncedCondition(t *testing.T) {
func TestTerminatingGateway_SetLastSyncedTime(t *testing.T) {
terminatingGateway := &TerminatingGateway{}
syncedTime := metav1.NewTime(time.Now())
terminatingGateway.SetLastSyncedTime(syncedTime)
terminatingGateway.SetLastSyncedTime(&syncedTime)

require.Equal(t, syncedTime, terminatingGateway.Status.LastSyncedTime)
require.Equal(t, &syncedTime, terminatingGateway.Status.LastSyncedTime)
}

func TestTerminatingGateway_GetSyncedConditionStatus(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

3 changes: 2 additions & 1 deletion controller/configentry_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ func (r *ConfigEntryController) syncFailed(ctx context.Context, logger logr.Logg

func (r *ConfigEntryController) syncSuccessful(ctx context.Context, updater Controller, configEntry common.ConfigEntryResource) (ctrl.Result, error) {
configEntry.SetSyncedCondition(corev1.ConditionTrue, "", "")
configEntry.SetLastSyncedTime(metav1.NewTime(time.Now()))
timeNow := metav1.NewTime(time.Now())
configEntry.SetLastSyncedTime(&timeNow)
return ctrl.Result{}, updater.UpdateStatus(ctx, configEntry)
}

Expand Down

0 comments on commit 3c5e456

Please sign in to comment.