Skip to content

Commit 6806e21

Browse files
authored
Fix recvcheck linter issues (#4505)
* Fix recvcheck linter issue * Add no lint for recvcheck * Update oneof and allof type methods * Controller linter fixes * revert
1 parent b7472cd commit 6806e21

File tree

13 files changed

+56
-51
lines changed

13 files changed

+56
-51
lines changed

v2/internal/duration/duration.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Duration marshalling
2929
TODO: remove after go v2: https://github.com/golang/go/issues/10275
3030
*/
3131

32-
func (d ISO8601) MarshalJSON() ([]byte, error) {
32+
func (d *ISO8601) MarshalJSON() ([]byte, error) {
3333
return []byte(fmt.Sprintf(`"%s"`, d.String())), nil
3434
}
3535

@@ -55,7 +55,7 @@ func (d *ISO8601) UnmarshalJSON(b []byte) error {
5555
}
5656
}
5757

58-
func (d ISO8601) String() string {
58+
func (d *ISO8601) String() string {
5959
if d.Duration == time.Duration(0) {
6060
return "PT0S"
6161
}

v2/internal/genericarmclient/cloud_error.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ func NewTestCloudError(code string, message string) *CloudError {
4747

4848
// Error implements the error interface for type CloudError.
4949
// The contents of the error text are not contractual and subject to change.
50-
func (e CloudError) Error() string {
50+
func (e *CloudError) Error() string {
5151
return e.error.Error()
5252
}
5353

5454
// Code returns the error code from the message, if present, or UnknownErrorCode if not.
55-
func (e CloudError) Code() string {
55+
func (e *CloudError) Code() string {
5656
if e.code != nil && *e.code != "" {
5757
return *e.code
5858
}
@@ -61,7 +61,7 @@ func (e CloudError) Code() string {
6161
}
6262

6363
// Message returns the message from the error, if present, or UnknownErrorMessage if not.
64-
func (e CloudError) Message() string {
64+
func (e *CloudError) Message() string {
6565
if e.message != nil && *e.message != "" {
6666
return *e.message
6767
}
@@ -70,7 +70,7 @@ func (e CloudError) Message() string {
7070
}
7171

7272
// Target returns the target of the error, if present, or an empty string if not.
73-
func (e CloudError) Target() string {
73+
func (e *CloudError) Target() string {
7474
if e.target != nil && *e.target != "" {
7575
return *e.target
7676
}
@@ -79,7 +79,7 @@ func (e CloudError) Target() string {
7979
}
8080

8181
// Details returns the details of the error, if present, or an empty slice if not
82-
func (e CloudError) Details() []*ErrorResponse {
82+
func (e *CloudError) Details() []*ErrorResponse {
8383
return e.details
8484
}
8585

@@ -117,6 +117,6 @@ func (e *CloudError) UnmarshalJSON(data []byte) error {
117117
return nil
118118
}
119119

120-
func (e CloudError) Unwrap() error {
120+
func (e *CloudError) Unwrap() error {
121121
return e.error
122122
}

v2/internal/testcommon/kube_per_test_context.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type KubePerTestContext struct {
5555
tracker *ResourceTracker
5656
}
5757

58-
func (tc KubePerTestContext) CreateTestNamespace(namespaceName string) error {
58+
func (tc *KubePerTestContext) CreateTestNamespace(namespaceName string) error {
5959
ns := &corev1.Namespace{
6060
ObjectMeta: metav1.ObjectMeta{
6161
Name: namespaceName,
@@ -72,22 +72,22 @@ func (tc KubePerTestContext) CreateTestNamespace(namespaceName string) error {
7272
return nil
7373
}
7474

75-
func (tc KubePerTestContext) createTestNamespace() error {
75+
func (tc *KubePerTestContext) createTestNamespace() error {
7676
return tc.CreateTestNamespace(tc.Namespace)
7777
}
7878

79-
func (tc KubePerTestContext) MakeObjectMeta(prefix string) ctrl.ObjectMeta {
79+
func (tc *KubePerTestContext) MakeObjectMeta(prefix string) ctrl.ObjectMeta {
8080
return tc.MakeObjectMetaWithName(tc.Namer.GenerateName(prefix))
8181
}
8282

83-
func (tc KubePerTestContext) MakeObjectMetaWithName(name string) ctrl.ObjectMeta {
83+
func (tc *KubePerTestContext) MakeObjectMetaWithName(name string) ctrl.ObjectMeta {
8484
return ctrl.ObjectMeta{
8585
Name: name,
8686
Namespace: tc.Namespace,
8787
}
8888
}
8989

90-
func (tc KubePerTestContext) MakeObjectMetaWithNameAndCredentialFrom(name string, credentialFrom string) ctrl.ObjectMeta {
90+
func (tc *KubePerTestContext) MakeObjectMetaWithNameAndCredentialFrom(name string, credentialFrom string) ctrl.ObjectMeta {
9191
return ctrl.ObjectMeta{
9292
Name: name,
9393
Namespace: tc.Namespace,
@@ -97,7 +97,7 @@ func (tc KubePerTestContext) MakeObjectMetaWithNameAndCredentialFrom(name string
9797
}
9898
}
9999

100-
func (tc KubePerTestContext) MakeReferenceFromResource(resource client.Object) *genruntime.ResourceReference {
100+
func (tc *KubePerTestContext) MakeReferenceFromResource(resource client.Object) *genruntime.ResourceReference {
101101
gvk, err := apiutil.GVKForObject(resource, tc.scheme)
102102
if err != nil {
103103
tc.T.Fatal(err)
@@ -110,7 +110,7 @@ func (tc KubePerTestContext) MakeReferenceFromResource(resource client.Object) *
110110
}
111111
}
112112

113-
func (tc KubePerTestContext) NewTestResourceGroup() *resources.ResourceGroup {
113+
func (tc *KubePerTestContext) NewTestResourceGroup() *resources.ResourceGroup {
114114
return &resources.ResourceGroup{
115115
ObjectMeta: tc.MakeObjectMeta("rg"),
116116
Spec: resources.ResourceGroup_Spec{

v2/internal/testcommon/test_logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type TestLogger struct {
5454
ignoredPanicMax int
5555
}
5656

57-
func (_ TestLogger) Init(info logr.RuntimeInfo) {
57+
func (_ *TestLogger) Init(info logr.RuntimeInfo) {
5858
}
5959

6060
// kvListFormat was adapted from the klog method of the same name and formats a keysAndValues list into

v2/pkg/genruntime/conditions/conditions.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const (
7575
var _ fmt.Stringer = Condition{}
7676

7777
// Condition defines an extension to status (an observation) of a resource
78+
// nolint:recvcheck
7879
// +kubebuilder:object:generate=true
7980
type Condition struct {
8081
// Type of condition.
@@ -117,7 +118,7 @@ type Condition struct {
117118

118119
// IsEquivalent returns true if this condition is equivalent to the passed in condition.
119120
// Two conditions are equivalent if all of their fields EXCEPT LastTransitionTime are the same.
120-
func (c Condition) IsEquivalent(other Condition) bool {
121+
func (c *Condition) IsEquivalent(other Condition) bool {
121122
return c.Type == other.Type &&
122123
c.Status == other.Status &&
123124
c.Severity == other.Severity &&
@@ -127,7 +128,7 @@ func (c Condition) IsEquivalent(other Condition) bool {
127128
}
128129

129130
// ShouldOverwrite determines if this condition should overwrite the other condition.
130-
func (c Condition) ShouldOverwrite(other Condition) bool {
131+
func (c *Condition) ShouldOverwrite(other Condition) bool {
131132
// Safety check that the two conditions are of the same type. If not they certainly shouldn't overwrite
132133
if c.Type != other.Type {
133134
return false
@@ -161,7 +162,7 @@ func (c Condition) ShouldOverwrite(other Condition) bool {
161162
//
162163
// Keep in mind that this priority is specifically for comparing Conditions with the same ObservedGeneration. If the ObservedGeneration
163164
// is different, the newer one always wins.
164-
func (c Condition) priority() int {
165+
func (c *Condition) priority() int {
165166
switch c.Status {
166167
case metav1.ConditionTrue:
167168
return 5
@@ -188,10 +189,10 @@ func (c Condition) priority() int {
188189
}
189190

190191
// Copy returns an independent copy of the Condition
191-
func (c Condition) Copy() Condition {
192+
func (c *Condition) Copy() Condition {
192193
// NB: If you change this to a non-simple copy
193194
// you will need to update genruntime.CloneSliceOfCondition
194-
return c
195+
return *c
195196
}
196197

197198
// String returns a string representation of this condition

v2/pkg/genruntime/configmaps.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
// ConfigMapReference is a reference to a Kubernetes configmap and key in the same namespace as
1515
// the resource it is on.
16+
// nolint:recvcheck
1617
// +kubebuilder:object:generate=true
1718
type ConfigMapReference struct {
1819
// Name is the name of the Kubernetes configmap being referenced.

v2/pkg/genruntime/core/destination_expression.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ type DestinationExpression struct {
3131
Value string `json:"value,omitempty"`
3232
}
3333

34-
func (s DestinationExpression) String() string {
34+
func (s *DestinationExpression) String() string {
3535
return fmt.Sprintf("Name: %q, Key: %q, Value: %q", s.Name, s.Key, s.Value)
3636
}

v2/pkg/genruntime/resource_reference.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type KnownResourceReference struct {
3939
}
4040

4141
// AsResourceReference transforms this KnownResourceReference into a ResourceReference
42-
func (ref KnownResourceReference) AsResourceReference(group string, kind string) *ResourceReference {
42+
func (ref *KnownResourceReference) AsResourceReference(group string, kind string) *ResourceReference {
4343
if ref.Name == "" {
4444
group = ""
4545
kind = ""
@@ -63,7 +63,7 @@ type KubernetesOwnerReference struct {
6363
}
6464

6565
// AsResourceReference transforms this KnownResourceReference into a ResourceReference
66-
func (ref KubernetesOwnerReference) AsResourceReference(group string, kind string) *ResourceReference {
66+
func (ref *KubernetesOwnerReference) AsResourceReference(group string, kind string) *ResourceReference {
6767
return &ResourceReference{
6868
Group: group,
6969
Kind: kind,
@@ -90,7 +90,7 @@ type ArbitraryOwnerReference struct {
9090
}
9191

9292
// AsResourceReference transforms this ArbitraryOwnerReference into a ResourceReference
93-
func (ref ArbitraryOwnerReference) AsResourceReference() *ResourceReference {
93+
func (ref *ArbitraryOwnerReference) AsResourceReference() *ResourceReference {
9494
return &ResourceReference{
9595
Group: ref.Group,
9696
Kind: ref.Kind,
@@ -102,6 +102,7 @@ func (ref ArbitraryOwnerReference) AsResourceReference() *ResourceReference {
102102
var _ fmt.Stringer = ResourceReference{}
103103

104104
// ResourceReference represents a resource reference, either to a Kubernetes resource or directly to an Azure resource via ARMID
105+
// nolint:recvcheck
105106
// +kubebuilder:object:generate=true
106107
type ResourceReference struct {
107108
// Group is the Kubernetes group of the resource.
@@ -131,12 +132,12 @@ func CreateResourceReferenceFromARMID(armID string) ResourceReference {
131132
}
132133

133134
// IsDirectARMReference returns true if this ResourceReference is referring to an ARMID directly.
134-
func (ref ResourceReference) IsDirectARMReference() bool {
135+
func (ref *ResourceReference) IsDirectARMReference() bool {
135136
return ref.ARMID != "" && ref.Name == "" && ref.Group == "" && ref.Kind == ""
136137
}
137138

138139
// IsKubernetesReference returns true if this ResourceReference is referring to a Kubernetes resource.
139-
func (ref ResourceReference) IsKubernetesReference() bool {
140+
func (ref *ResourceReference) IsKubernetesReference() bool {
140141
return ref.ARMID == "" && ref.Name != "" && ref.Group != "" && ref.Kind != ""
141142
}
142143

@@ -155,7 +156,7 @@ func (ref ResourceReference) String() string {
155156

156157
// TODO: We wouldn't need this if controller-gen supported DUs or OneOf better, see: https://github.com/kubernetes-sigs/controller-tools/issues/461
157158
// Validate validates the ResourceReference to ensure that it is structurally valid.
158-
func (ref ResourceReference) Validate() (admission.Warnings, error) {
159+
func (ref *ResourceReference) Validate() (admission.Warnings, error) {
159160
if ref.ARMID == "" && ref.Name == "" && ref.Group == "" && ref.Kind == "" {
160161
return nil, eris.Errorf("at least one of ['ARMID'] or ['Group', 'Kind', 'Namespace', 'Name'] must be set for ResourceReference")
161162
}
@@ -172,22 +173,22 @@ func (ref ResourceReference) Validate() (admission.Warnings, error) {
172173
}
173174

174175
// AsNamespacedRef creates a NamespacedResourceReference from this reference.
175-
func (ref ResourceReference) AsNamespacedRef(namespace string) NamespacedResourceReference {
176+
func (ref *ResourceReference) AsNamespacedRef(namespace string) NamespacedResourceReference {
176177
// If this is a direct ARM reference, don't append a namespace as it reads weird
177178
if ref.IsDirectARMReference() {
178179
return NamespacedResourceReference{
179-
ResourceReference: ref,
180+
ResourceReference: *ref,
180181
}
181182
}
182183

183184
return NamespacedResourceReference{
184-
ResourceReference: ref,
185+
ResourceReference: *ref,
185186
Namespace: namespace,
186187
}
187188
}
188189

189190
// GroupKind returns the GroupKind of the resource reference
190-
func (ref ResourceReference) GroupKind() schema.GroupKind {
191+
func (ref *ResourceReference) GroupKind() schema.GroupKind {
191192
return schema.GroupKind{
192193
Group: ref.Group,
193194
Kind: ref.Kind,
@@ -214,13 +215,13 @@ func LookupOwnerGroupKind(v interface{}) (string, string) {
214215
}
215216

216217
// Copy makes an independent copy of the KnownResourceReference
217-
func (ref KnownResourceReference) Copy() KnownResourceReference {
218-
return ref
218+
func (ref *KnownResourceReference) Copy() KnownResourceReference {
219+
return *ref
219220
}
220221

221222
// Copy makes an independent copy of the ArbitraryOwnerReference
222-
func (ref ArbitraryOwnerReference) Copy() ArbitraryOwnerReference {
223-
return ref
223+
func (ref *ArbitraryOwnerReference) Copy() ArbitraryOwnerReference {
224+
return *ref
224225
}
225226

226227
// Copy makes an independent copy of the ResourceReference
@@ -229,8 +230,8 @@ func (ref ResourceReference) Copy() ResourceReference {
229230
}
230231

231232
// Copy makes an independent copy of the KubernetesOwnerReference
232-
func (ref KubernetesOwnerReference) Copy() KubernetesOwnerReference {
233-
return ref
233+
func (ref *KubernetesOwnerReference) Copy() KubernetesOwnerReference {
234+
return *ref
234235
}
235236

236237
// ValidateResourceReferences calls Validate on each ResourceReference

v2/pkg/genruntime/secrets.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
// SecretReference is a reference to a Kubernetes secret and key in the same namespace as
1313
// the resource it is on.
14+
// nolint:recvcheck
1415
// +kubebuilder:object:generate=true
1516
type SecretReference struct {
1617
// Name is the name of the Kubernetes secret being referenced.
@@ -62,6 +63,7 @@ func (s NamespacedSecretReference) String() string {
6263

6364
// SecretMapReference is a reference to a Kubernetes secret in the same namespace as
6465
// the resource it is on.
66+
// nolint:recvcheck
6567
// +kubebuilder:object:generate=true
6668
type SecretMapReference struct {
6769
// Name is the name of the Kubernetes secret being referenced.

v2/tools/generator/internal/astmodel/allof_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func BuildAllOfType(types ...Type) Type {
9292
// Types returns what types the AllOf can be.
9393
// Exposed as ReadonlyTypeSet so caller can't break invariants.
9494
func (allOf *AllOfType) Types() ReadonlyTypeSet {
95-
return allOf.types
95+
return &allOf.types
9696
}
9797

9898
// References returns any type referenced by the AllOf types

0 commit comments

Comments
 (0)