Skip to content

Commit

Permalink
Change CRTB Status lastUpdatedTime format (rancher#48514)
Browse files Browse the repository at this point in the history
  • Loading branch information
raulcabello authored Dec 20, 2024
1 parent 1d2341c commit ad994c4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/management/auth/crtb_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (c *crtbLifecycle) updateStatus(crtb *v3.ClusterRoleTemplateBinding, localC
}
}

crtbFromCluster.Status.LastUpdateTime = timeNow().String()
crtbFromCluster.Status.LastUpdateTime = timeNow().Format(time.RFC3339)
crtbFromCluster.Status.ObservedGenerationLocal = crtb.ObjectMeta.Generation
crtbFromCluster.Status.LocalConditions = localConditions
crtbFromCluster, err = c.crtbClient.UpdateStatus(crtbFromCluster)
Expand Down
18 changes: 9 additions & 9 deletions pkg/controllers/management/auth/crtb_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func TestUpdateStatus(t *testing.T) {
},
},
},
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
},
}
crtbSubjectAndBindingExist := &v3.ClusterRoleTemplateBinding{
Expand All @@ -473,7 +473,7 @@ func TestUpdateStatus(t *testing.T) {
},
},
},
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
},
}
crtbSubjectError := &v3.ClusterRoleTemplateBinding{
Expand All @@ -488,17 +488,17 @@ func TestUpdateStatus(t *testing.T) {
},
},
},
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
},
}
crtbEmptyStatus := &v3.ClusterRoleTemplateBinding{
Status: v3.ClusterRoleTemplateBindingStatus{
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
},
}
crtbEmptyStatusRemoteComplete := &v3.ClusterRoleTemplateBinding{
Status: v3.ClusterRoleTemplateBindingStatus{
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
SummaryRemote: status.SummaryCompleted,
},
}
Expand All @@ -524,7 +524,7 @@ func TestUpdateStatus(t *testing.T) {
},
},
},
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
SummaryLocal: status.SummaryCompleted,
},
})
Expand Down Expand Up @@ -556,7 +556,7 @@ func TestUpdateStatus(t *testing.T) {
},
},
},
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
SummaryLocal: status.SummaryCompleted,
SummaryRemote: status.SummaryCompleted,
Summary: status.SummaryCompleted,
Expand All @@ -583,7 +583,7 @@ func TestUpdateStatus(t *testing.T) {
},
},
},
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
SummaryLocal: status.SummaryError,
Summary: status.SummaryError,
},
Expand All @@ -609,7 +609,7 @@ func TestUpdateStatus(t *testing.T) {
},
},
},
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
SummaryLocal: status.SummaryCompleted,
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"reflect"
"time"

apisv3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
"github.com/rancher/rancher/pkg/clustermanager"
Expand Down Expand Up @@ -597,7 +598,7 @@ func (c *globalRoleBindingLifecycle) updateStatus(grb *apisv3.GlobalRoleBinding,
}
}

grbFromCluster.Status.LastUpdateTime = c.status.TimeNow().String()
grbFromCluster.Status.LastUpdateTime = c.status.TimeNow().Format(time.RFC3339)
grbFromCluster.Status.ObservedGenerationLocal = grb.ObjectMeta.Generation
grbFromCluster.Status.LocalConditions = localConditions
grbFromCluster, err = c.grbClient.UpdateStatus(grbFromCluster)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestCreateUpdate(t *testing.T) {
GlobalRoleName: gr.Name,
UserName: userName,
Status: v3.GlobalRoleBindingStatus{
LastUpdateTime: mockTime().String(),
LastUpdateTime: mockTime().Format(time.RFC3339),
SummaryLocal: status.SummaryCompleted,
LocalConditions: []metav1.Condition{
{
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestCreateUpdate(t *testing.T) {
GlobalRoleName: gr.Name,
UserName: userName,
Status: v3.GlobalRoleBindingStatus{
LastUpdateTime: mockTime().String(),
LastUpdateTime: mockTime().Format(time.RFC3339),
SummaryLocal: status.SummaryCompleted,
LocalConditions: []metav1.Condition{
{
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestCreateUpdate(t *testing.T) {
GlobalRoleName: gr.Name,
UserName: userName,
Status: v3.GlobalRoleBindingStatus{
LastUpdateTime: mockTime().String(),
LastUpdateTime: mockTime().Format(time.RFC3339),
SummaryLocal: status.SummaryError,
Summary: status.SummaryError,
LocalConditions: []metav1.Condition{
Expand Down Expand Up @@ -553,7 +553,7 @@ func TestCreateUpdate(t *testing.T) {
GlobalRoleName: gr.Name,
UserName: userName,
Status: v3.GlobalRoleBindingStatus{
LastUpdateTime: mockTime().String(),
LastUpdateTime: mockTime().Format(time.RFC3339),
SummaryLocal: status.SummaryError,
Summary: status.SummaryError,
LocalConditions: []metav1.Condition{
Expand Down Expand Up @@ -663,7 +663,7 @@ func TestCreateUpdate(t *testing.T) {
GlobalRoleName: gr.Name,
UserName: userName,
Status: v3.GlobalRoleBindingStatus{
LastUpdateTime: mockTime().String(),
LastUpdateTime: mockTime().Format(time.RFC3339),
SummaryLocal: status.SummaryError,
Summary: status.SummaryError,
LocalConditions: []metav1.Condition{
Expand Down Expand Up @@ -770,7 +770,7 @@ func TestCreateUpdate(t *testing.T) {
GlobalRoleName: gr.Name,
UserName: userName,
Status: v3.GlobalRoleBindingStatus{
LastUpdateTime: mockTime().String(),
LastUpdateTime: mockTime().Format(time.RFC3339),
SummaryLocal: status.SummaryCompleted,
LocalConditions: []metav1.Condition{
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/managementuser/rbac/crtb_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (c *crtbLifecycle) updateStatus(crtb *v3.ClusterRoleTemplateBinding, remote
}
}

crtbFromCluster.Status.LastUpdateTime = timeNow().String()
crtbFromCluster.Status.LastUpdateTime = timeNow().Format(time.RFC3339)
crtbFromCluster.Status.ObservedGenerationRemote = crtb.ObjectMeta.Generation
crtbFromCluster.Status.RemoteConditions = remoteConditions
crtbFromCluster, err = c.crtbClient.UpdateStatus(crtbFromCluster)
Expand Down
16 changes: 8 additions & 8 deletions pkg/controllers/managementuser/rbac/crtb_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func TestUpdateStatus(t *testing.T) {
},
},
},
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
},
}
crtbClusterRoleBindingExists := &v3.ClusterRoleTemplateBinding{
Expand All @@ -333,7 +333,7 @@ func TestUpdateStatus(t *testing.T) {
},
},
},
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
},
}
crtbSubjectError := &v3.ClusterRoleTemplateBinding{
Expand All @@ -348,17 +348,17 @@ func TestUpdateStatus(t *testing.T) {
},
},
},
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
},
}
crtbEmptyStatus := &v3.ClusterRoleTemplateBinding{
Status: v3.ClusterRoleTemplateBindingStatus{
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
},
}
crtbEmptyStatusLocalComplete := &v3.ClusterRoleTemplateBinding{
Status: v3.ClusterRoleTemplateBindingStatus{
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
SummaryLocal: status.SummaryCompleted,
},
}
Expand All @@ -385,7 +385,7 @@ func TestUpdateStatus(t *testing.T) {
},
},
SummaryRemote: status.SummaryCompleted,
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
},
})

Expand Down Expand Up @@ -420,7 +420,7 @@ func TestUpdateStatus(t *testing.T) {
SummaryRemote: status.SummaryCompleted,
SummaryLocal: status.SummaryCompleted,
Summary: status.SummaryCompleted,
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
},
})

Expand All @@ -446,7 +446,7 @@ func TestUpdateStatus(t *testing.T) {
},
SummaryRemote: status.SummaryError,
Summary: status.SummaryError,
LastUpdateTime: mockTime.String(),
LastUpdateTime: mockTime.Format(time.RFC3339),
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rbac

import (
"fmt"
"time"

"github.com/rancher/norman/types/slice"
apisv3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
Expand Down Expand Up @@ -214,7 +215,7 @@ func (c *grbHandler) updateStatus(grb *apisv3.GlobalRoleBinding, remoteCondition
break
}
}
grbFromCluster.Status.LastUpdateTime = c.status.TimeNow().String()
grbFromCluster.Status.LastUpdateTime = c.status.TimeNow().Format(time.RFC3339)
grbFromCluster.Status.ObservedGenerationRemote = grb.ObjectMeta.Generation
grbFromCluster.Status.RemoteConditions = remoteConditions
grbFromCluster, err = c.grbClient.UpdateStatus(grbFromCluster)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestSync(t *testing.T) {
state.grbClientMock.EXPECT().UpdateStatus(&v3.GlobalRoleBinding{
GlobalRoleName: rbac.GlobalAdmin,
Status: v3.GlobalRoleBindingStatus{
LastUpdateTime: mockTime().String(),
LastUpdateTime: mockTime().Format(time.RFC3339),
SummaryRemote: status.SummaryCompleted,
RemoteConditions: []metav1.Condition{
{
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestSync(t *testing.T) {
state.grbClientMock.EXPECT().UpdateStatus(&v3.GlobalRoleBinding{
GlobalRoleName: rbac.GlobalAdmin,
Status: v3.GlobalRoleBindingStatus{
LastUpdateTime: mockTime().String(),
LastUpdateTime: mockTime().Format(time.RFC3339),
SummaryRemote: status.SummaryCompleted,
RemoteConditions: []metav1.Condition{
{
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestSync(t *testing.T) {
state.grbClientMock.EXPECT().UpdateStatus(&v3.GlobalRoleBinding{
GlobalRoleName: "gr",
Status: v3.GlobalRoleBindingStatus{
LastUpdateTime: mockTime().String(),
LastUpdateTime: mockTime().Format(time.RFC3339),
SummaryRemote: status.SummaryCompleted,
},
})
Expand Down

0 comments on commit ad994c4

Please sign in to comment.