Skip to content

Commit 910baba

Browse files
committed
Change ResourceBinding.Applied from bool to *bool
1 parent 22e4b06 commit 910baba

14 files changed

+82
-29
lines changed

api/addons/v1beta1/conversion_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
28+
"k8s.io/utils/ptr"
2829
"sigs.k8s.io/randfill"
2930

3031
addonsv1 "sigs.k8s.io/cluster-api/api/addons/v1beta2"
@@ -75,11 +76,20 @@ func spokeClusterResourceSetStatus(in *ClusterResourceSetStatus, c randfill.Cont
7576

7677
func ClusterResourceSetBindingFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
7778
return []interface{}{
79+
hubResourceBinding,
7880
hubClusterResourceSetStatus,
7981
spokeClusterResourceSetBindingSpec,
8082
}
8183
}
8284

85+
func hubResourceBinding(in *addonsv1.ResourceBinding, c randfill.Continue) {
86+
c.FillNoCustom(in)
87+
88+
if in.Applied == nil {
89+
in.Applied = ptr.To(false) // Applied is a required field and nil does not round trip
90+
}
91+
}
92+
8393
func spokeClusterResourceSetBindingSpec(in *ClusterResourceSetBindingSpec, c randfill.Continue) {
8494
c.FillNoCustom(in)
8595

api/addons/v1beta1/zz_generated.conversion.go

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/addons/v1beta2/clusterresourcesetbinding_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"reflect"
2121

2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/utils/ptr"
2324
)
2425

2526
// ResourceBinding shows the status of a resource that belongs to a ClusterResourceSet matched by the owner cluster of the ClusterResourceSetBinding object.
@@ -40,7 +41,7 @@ type ResourceBinding struct {
4041

4142
// applied is to track if a resource is applied to the cluster or not.
4243
// +required
43-
Applied bool `json:"applied"`
44+
Applied *bool `json:"applied,omitempty"`
4445
}
4546

4647
// ResourceSetBinding keeps info on all of the resources in a ClusterResourceSet.
@@ -61,7 +62,7 @@ type ResourceSetBinding struct {
6162
// IsApplied returns true if the resource is applied to the cluster by checking the cluster's binding.
6263
func (r *ResourceSetBinding) IsApplied(resourceRef ResourceRef) bool {
6364
resourceBinding := r.GetResource(resourceRef)
64-
return resourceBinding != nil && resourceBinding.Applied
65+
return resourceBinding != nil && ptr.Deref(resourceBinding.Applied, false)
6566
}
6667

6768
// GetResource returns a ResourceBinding for a resource ref if present.

api/addons/v1beta2/clusterresourcesetbinding_types_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/google/go-cmp/cmp"
2424
. "github.com/onsi/gomega"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
"k8s.io/utils/ptr"
2627
)
2728

2829
func TestIsResourceApplied(t *testing.T) {
@@ -43,13 +44,13 @@ func TestIsResourceApplied(t *testing.T) {
4344
Resources: []ResourceBinding{
4445
{
4546
ResourceRef: resourceRefApplySucceeded,
46-
Applied: true,
47+
Applied: ptr.To(true),
4748
Hash: "xyz",
4849
LastAppliedTime: metav1.Time{Time: time.Now().UTC()},
4950
},
5051
{
5152
ResourceRef: resourceRefApplyFailed,
52-
Applied: false,
53+
Applied: ptr.To(false),
5354
Hash: "",
5455
LastAppliedTime: metav1.Time{Time: time.Now().UTC()},
5556
},
@@ -106,7 +107,7 @@ func TestResourceSetBindingGetResourceBinding(t *testing.T) {
106107

107108
resourceRefApplyFailedBinding := ResourceBinding{
108109
ResourceRef: resourceRefApplyFailed,
109-
Applied: false,
110+
Applied: ptr.To(false),
110111
Hash: "",
111112
LastAppliedTime: metav1.Time{Time: time.Now().UTC()},
112113
}
@@ -115,7 +116,7 @@ func TestResourceSetBindingGetResourceBinding(t *testing.T) {
115116
Resources: []ResourceBinding{
116117
{
117118
ResourceRef: resourceRefApplySucceeded,
118-
Applied: true,
119+
Applied: ptr.To(true),
119120
Hash: "xyz",
120121
LastAppliedTime: metav1.Time{Time: time.Now().UTC()},
121122
},
@@ -161,15 +162,15 @@ func TestSetResourceBinding(t *testing.T) {
161162
Resources: []ResourceBinding{
162163
{
163164
ResourceRef: resourceRefApplyFailed,
164-
Applied: false,
165+
Applied: ptr.To(false),
165166
Hash: "",
166167
LastAppliedTime: metav1.Time{Time: time.Now().UTC()},
167168
},
168169
},
169170
}
170171
updateFailedResourceBinding := ResourceBinding{
171172
ResourceRef: resourceRefApplyFailed,
172-
Applied: true,
173+
Applied: ptr.To(true),
173174
Hash: "xyz",
174175
LastAppliedTime: metav1.Time{Time: time.Now().UTC()},
175176
}
@@ -179,7 +180,7 @@ func TestSetResourceBinding(t *testing.T) {
179180
Name: "newBinding",
180181
Kind: "Secret",
181182
},
182-
Applied: false,
183+
Applied: ptr.To(false),
183184
Hash: "xyz",
184185
LastAppliedTime: metav1.Time{Time: time.Now().UTC()},
185186
}

api/addons/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/api/addons/v1alpha3/conversion_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
28+
"k8s.io/utils/ptr"
2829
"sigs.k8s.io/randfill"
2930

3031
addonsv1 "sigs.k8s.io/cluster-api/api/addons/v1beta2"
@@ -64,11 +65,20 @@ func hubClusterResourceSetStatus(in *addonsv1.ClusterResourceSetStatus, c randfi
6465

6566
func ClusterResourceSetBindingFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
6667
return []interface{}{
68+
hubResourceBinding,
6769
hubClusterResourceSetStatus,
6870
spokeClusterResourceSetBindingSpec,
6971
}
7072
}
7173

74+
func hubResourceBinding(in *addonsv1.ResourceBinding, c randfill.Continue) {
75+
c.FillNoCustom(in)
76+
77+
if in.Applied == nil {
78+
in.Applied = ptr.To(false) // Applied is a required field and nil does not round trip
79+
}
80+
}
81+
7282
func spokeClusterResourceSetBindingSpec(in *ClusterResourceSetBindingSpec, c randfill.Continue) {
7383
c.FillNoCustom(in)
7484

internal/api/addons/v1alpha3/zz_generated.conversion.go

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/api/addons/v1alpha4/conversion_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
28+
"k8s.io/utils/ptr"
2829
"sigs.k8s.io/randfill"
2930

3031
addonsv1 "sigs.k8s.io/cluster-api/api/addons/v1beta2"
@@ -64,11 +65,20 @@ func hubClusterResourceSetStatus(in *addonsv1.ClusterResourceSetStatus, c randfi
6465

6566
func ClusterResourceSetBindingFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
6667
return []interface{}{
68+
hubResourceBinding,
6769
hubClusterResourceSetStatus,
6870
spokeClusterResourceSetBindingSpec,
6971
}
7072
}
7173

74+
func hubResourceBinding(in *addonsv1.ResourceBinding, c randfill.Continue) {
75+
c.FillNoCustom(in)
76+
77+
if in.Applied == nil {
78+
in.Applied = ptr.To(false) // Applied is a required field and nil does not round trip
79+
}
80+
}
81+
7282
func spokeClusterResourceSetBindingSpec(in *ClusterResourceSetBindingSpec, c randfill.Continue) {
7383
c.FillNoCustom(in)
7484

internal/api/addons/v1alpha4/zz_generated.conversion.go

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controllers/clusterresourceset/clusterresourceset_controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/apimachinery/pkg/types"
3131
kerrors "k8s.io/apimachinery/pkg/util/errors"
3232
"k8s.io/klog/v2"
33+
"k8s.io/utils/ptr"
3334
ctrl "sigs.k8s.io/controller-runtime"
3435
"sigs.k8s.io/controller-runtime/pkg/builder"
3536
"sigs.k8s.io/controller-runtime/pkg/cache"
@@ -410,7 +411,7 @@ func (r *Reconciler) ApplyClusterResourceSet(ctx context.Context, cluster *clust
410411
resourceSetBinding.SetBinding(addonsv1.ResourceBinding{
411412
ResourceRef: resource,
412413
Hash: "",
413-
Applied: false,
414+
Applied: ptr.To(false),
414415
LastAppliedTime: metav1.Time{Time: time.Now().UTC()},
415416
})
416417

@@ -427,7 +428,7 @@ func (r *Reconciler) ApplyClusterResourceSet(ctx context.Context, cluster *clust
427428
resourceSetBinding.SetBinding(addonsv1.ResourceBinding{
428429
ResourceRef: resource,
429430
Hash: "",
430-
Applied: false,
431+
Applied: ptr.To(false),
431432
LastAppliedTime: metav1.Time{Time: time.Now().UTC()},
432433
})
433434

@@ -450,7 +451,7 @@ func (r *Reconciler) ApplyClusterResourceSet(ctx context.Context, cluster *clust
450451
resourceSetBinding.SetBinding(addonsv1.ResourceBinding{
451452
ResourceRef: resource,
452453
Hash: resourceScope.hash(),
453-
Applied: isSuccessful,
454+
Applied: ptr.To(isSuccessful),
454455
LastAppliedTime: metav1.Time{Time: time.Now().UTC()},
455456
})
456457
}

0 commit comments

Comments
 (0)