Skip to content

Commit

Permalink
Address reviewer comments
Browse files Browse the repository at this point in the history
Signed-off-by: Predrag Knezevic <predrag.knezevic@upbound.io>
  • Loading branch information
pedjak committed Apr 19, 2024
1 parent b5462b5 commit d049fcc
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 64 deletions.
2 changes: 1 addition & 1 deletion apis/common/v1/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type Condition struct {
}

// Equal returns true if the condition is identical to the supplied condition,
// ignoring the LastTransitionTime.
// ignoring the LastTransitionTime and ObservedGeneration.
func (c Condition) Equal(other Condition) bool {
return c.Type == other.Type &&
c.Status == other.Status &&
Expand Down
10 changes: 5 additions & 5 deletions pkg/resource/unstructured/claim/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (c *Unstructured) SetPublishConnectionDetailsTo(ref *xpv1.PublishConnection

// GetCondition of this composite resource claim.
func (c *Unstructured) GetCondition(ct xpv1.ConditionType) xpv1.Condition {
conditioned := xpv1.ResourceStatus{}
conditioned := xpv1.ConditionedStatus{}
// The path is directly `status` because conditions are inline.
if err := fieldpath.Pave(c.Object).GetValueInto("status", &conditioned); err != nil {
return xpv1.Condition{}
Expand All @@ -233,7 +233,7 @@ func (c *Unstructured) GetCondition(ct xpv1.ConditionType) xpv1.Condition {

// SetConditions of this composite resource claim.
func (c *Unstructured) SetConditions(conditions ...xpv1.Condition) {
conditioned := xpv1.ResourceStatus{}
conditioned := xpv1.ConditionedStatus{}
// The path is directly `status` because conditions are inline.
_ = fieldpath.Pave(c.Object).GetValueInto("status", &conditioned)
conditioned.SetConditions(conditions...)
Expand All @@ -256,15 +256,15 @@ func (c *Unstructured) SetConnectionDetailsLastPublishedTime(t *metav1.Time) {

// SetObservedGeneration of this composite resource claim.
func (c *Unstructured) SetObservedGeneration(generation int64) {
status := &xpv1.ResourceStatus{}
status := &xpv1.ObservedStatus{}
_ = fieldpath.Pave(c.Object).GetValueInto("status", status)
status.SetObservedGeneration(generation)
_ = fieldpath.Pave(c.Object).SetValue("status", status)
_ = fieldpath.Pave(c.Object).SetValue("status.observedGeneration", status.ObservedGeneration)
}

// GetObservedGeneration of this composite resource claim.
func (c *Unstructured) GetObservedGeneration() int64 {
status := &xpv1.ResourceStatus{}
status := &xpv1.ObservedStatus{}
_ = fieldpath.Pave(c.Object).GetValueInto("status", status)
return status.GetObservedGeneration()
}
36 changes: 20 additions & 16 deletions pkg/resource/unstructured/claim/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,22 +370,26 @@ func TestConnectionDetailsLastPublishedTime(t *testing.T) {
}

func TestObservedGeneration(t *testing.T) {
u := &Unstructured{unstructured.Unstructured{Object: map[string]any{}}}
want := int64(123)
u.SetObservedGeneration(want)

if got := u.GetObservedGeneration(); got != want {
t.Errorf("u.GetObservedGeneration() got: %v, want %v", got, want)
}
if g := u.GetUnstructured().Object["status"].(map[string]any)["observedGeneration"]; g != want {
t.Errorf("Generations do not match! got: %v (%T)", g, g)
cases := map[string]struct {
u *Unstructured
want int64
}{
"Set": {
u: New(func(u *Unstructured) {
u.SetObservedGeneration(123)
}),
want: 123,
},
"NotFound": {
u: New(),
},
}
}

func TestObservedGenerationNotFound(t *testing.T) {
u := &Unstructured{unstructured.Unstructured{Object: map[string]any{}}}

if g := u.GetObservedGeneration(); g != 0 {
t.Errorf("u.GetObservedGeneration(): expected nil, but got %v", g)
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
got := tc.u.GetObservedGeneration()
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("\nu.GetObservedGeneration(): -want, +got:\n%s", diff)
}
})
}
}
10 changes: 5 additions & 5 deletions pkg/resource/unstructured/composed/composed.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (cr *Unstructured) GetUnstructured() *unstructured.Unstructured {

// GetCondition of this Composed resource.
func (cr *Unstructured) GetCondition(ct xpv1.ConditionType) xpv1.Condition {
conditioned := xpv1.ResourceStatus{}
conditioned := xpv1.ConditionedStatus{}
// The path is directly `status` because conditions are inline.
if err := fieldpath.Pave(cr.Object).GetValueInto("status", &conditioned); err != nil {
return xpv1.Condition{}
Expand All @@ -82,7 +82,7 @@ func (cr *Unstructured) GetCondition(ct xpv1.ConditionType) xpv1.Condition {

// SetConditions of this Composed resource.
func (cr *Unstructured) SetConditions(c ...xpv1.Condition) {
conditioned := xpv1.ResourceStatus{}
conditioned := xpv1.ConditionedStatus{}
// The path is directly `status` because conditions are inline.
_ = fieldpath.Pave(cr.Object).GetValueInto("status", &conditioned)
conditioned.SetConditions(c...)
Expand Down Expand Up @@ -171,15 +171,15 @@ func (cr *UnstructuredList) GetUnstructuredList() *unstructured.UnstructuredList

// SetObservedGeneration of this composite resource claim.
func (cr *Unstructured) SetObservedGeneration(generation int64) {
status := &xpv1.ResourceStatus{}
status := &xpv1.ObservedStatus{}
_ = fieldpath.Pave(cr.Object).GetValueInto("status", status)
status.SetObservedGeneration(generation)
_ = fieldpath.Pave(cr.Object).SetValue("status", status)
_ = fieldpath.Pave(cr.Object).SetValue("status.observedGeneration", status.ObservedGeneration)
}

// GetObservedGeneration of this composite resource claim.
func (cr *Unstructured) GetObservedGeneration() int64 {
status := &xpv1.ResourceStatus{}
status := &xpv1.ObservedStatus{}
_ = fieldpath.Pave(cr.Object).GetValueInto("status", status)
return status.GetObservedGeneration()
}
36 changes: 20 additions & 16 deletions pkg/resource/unstructured/composed/composed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,26 @@ func TestWriteConnectionSecretToReference(t *testing.T) {
}

func TestObservedGeneration(t *testing.T) {
u := &Unstructured{unstructured.Unstructured{Object: map[string]any{}}}
want := int64(123)
u.SetObservedGeneration(want)

if got := u.GetObservedGeneration(); got != want {
t.Errorf("u.GetObservedGeneration() got: %v, want %v", got, want)
}
if g := u.GetUnstructured().Object["status"].(map[string]any)["observedGeneration"]; g != want {
t.Errorf("Generations do not match! got: %v (%T)", g, g)
cases := map[string]struct {
u *Unstructured
want int64
}{
"Set": {
u: New(func(u *Unstructured) {
u.SetObservedGeneration(123)
}),
want: 123,
},
"NotFound": {
u: New(),
},
}
}

func TestObservedGenerationNotFound(t *testing.T) {
u := &Unstructured{unstructured.Unstructured{Object: map[string]any{}}}

if g := u.GetObservedGeneration(); g != 0 {
t.Errorf("u.GetObservedGeneration(): expected nil, but got %v", g)
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
got := tc.u.GetObservedGeneration()
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("\nu.GetObservedGeneration(): -want, +got:\n%s", diff)
}
})
}
}
10 changes: 5 additions & 5 deletions pkg/resource/unstructured/composite/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (c *Unstructured) SetPublishConnectionDetailsTo(ref *xpv1.PublishConnection

// GetCondition of this Composite resource.
func (c *Unstructured) GetCondition(ct xpv1.ConditionType) xpv1.Condition {
conditioned := xpv1.ResourceStatus{}
conditioned := xpv1.ConditionedStatus{}
// The path is directly `status` because conditions are inline.
if err := fieldpath.Pave(c.Object).GetValueInto("status", &conditioned); err != nil {
return xpv1.Condition{}
Expand All @@ -216,7 +216,7 @@ func (c *Unstructured) GetCondition(ct xpv1.ConditionType) xpv1.Condition {

// SetConditions of this Composite resource.
func (c *Unstructured) SetConditions(conditions ...xpv1.Condition) {
conditioned := xpv1.ResourceStatus{}
conditioned := xpv1.ConditionedStatus{}
// The path is directly `status` because conditions are inline.
_ = fieldpath.Pave(c.Object).GetValueInto("status", &conditioned)
conditioned.SetConditions(conditions...)
Expand Down Expand Up @@ -261,15 +261,15 @@ func (c *Unstructured) SetEnvironmentConfigReferences(refs []corev1.ObjectRefere

// SetObservedGeneration of this composite resource claim.
func (c *Unstructured) SetObservedGeneration(generation int64) {
status := &xpv1.ResourceStatus{}
status := &xpv1.ObservedStatus{}
_ = fieldpath.Pave(c.Object).GetValueInto("status", status)
status.SetObservedGeneration(generation)
_ = fieldpath.Pave(c.Object).SetValue("status", status)
_ = fieldpath.Pave(c.Object).SetValue("status.observedGeneration", status.ObservedGeneration)
}

// GetObservedGeneration of this composite resource claim.
func (c *Unstructured) GetObservedGeneration() int64 {
status := &xpv1.ResourceStatus{}
status := &xpv1.ObservedStatus{}
_ = fieldpath.Pave(c.Object).GetValueInto("status", status)
return status.GetObservedGeneration()
}
36 changes: 20 additions & 16 deletions pkg/resource/unstructured/composite/composite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,22 +358,26 @@ func TestConnectionDetailsLastPublishedTime(t *testing.T) {
}

func TestObservedGeneration(t *testing.T) {
u := &Unstructured{unstructured.Unstructured{Object: map[string]any{}}}
want := int64(123)
u.SetObservedGeneration(want)

if got := u.GetObservedGeneration(); got != want {
t.Errorf("u.GetObservedGeneration() got: %v, want %v", got, want)
}
if g := u.GetUnstructured().Object["status"].(map[string]any)["observedGeneration"]; g != want {
t.Errorf("Generations do not match! got: %v (%T)", g, g)
cases := map[string]struct {
u *Unstructured
want int64
}{
"Set": {
u: New(func(u *Unstructured) {
u.SetObservedGeneration(123)
}),
want: 123,
},
"NotFound": {
u: New(),
},
}
}

func TestObservedGenerationNotFound(t *testing.T) {
u := &Unstructured{unstructured.Unstructured{Object: map[string]any{}}}

if g := u.GetObservedGeneration(); g != 0 {
t.Errorf("u.GetObservedGeneration(): expected nil, but got %v", g)
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
got := tc.u.GetObservedGeneration()
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("\nu.GetObservedGeneration(): -want, +got:\n%s", diff)
}
})
}
}

0 comments on commit d049fcc

Please sign in to comment.