Skip to content

Commit c22262e

Browse files
authored
cleanup: final clean up of pointer (#1444)
* final clean up of pointer * upadted docs Signed-off-by: Xiyue Yu <[email protected]> * updated it --------- Signed-off-by: Xiyue Yu <[email protected]>
1 parent 40fdedb commit c22262e

File tree

6 files changed

+27
-52
lines changed

6 files changed

+27
-52
lines changed

api/v1/inferencepool_types.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ type EndpointPickerRef struct {
118118
//
119119
// +optional
120120
// +kubebuilder:default=Service
121-
//nolint:kubeapilinter // ignore kubeapilinter here as we want to use pointer for optional struct.
122-
Kind *Kind `json:"kind,omitempty"`
121+
Kind Kind `json:"kind,omitempty"`
123122

124123
// Name is the name of the referent API object.
125124
//
@@ -131,16 +130,15 @@ type EndpointPickerRef struct {
131130
// unspecified (defaults to "Service").
132131
//
133132
// +optional
134-
//nolint:kubeapilinter // ignore kubeapilinter here as we want to use pointer for optional struct.
133+
//nolint:kubeapilinter // ignore kubeapilinter here as we want to use pointer as zero means all ports in convention, we don't make to use 0 to indicate not set.
135134
PortNumber *PortNumber `json:"portNumber,omitempty"`
136135

137136
// FailureMode configures how the parent handles the case when the Endpoint Picker extension
138137
// is non-responsive. When unspecified, defaults to "FailClose".
139138
//
140139
// +optional
141140
// +kubebuilder:default="FailClose"
142-
//nolint:kubeapilinter // ignore kubeapilinter here as we want to use pointer for optional struct.
143-
FailureMode *EndpointPickerFailureMode `json:"failureMode,omitempty"`
141+
FailureMode EndpointPickerFailureMode `json:"failureMode,omitempty"`
144142
}
145143

146144
// EndpointPickerFailureMode defines the options for how the parent handles the case when the
@@ -286,8 +284,7 @@ type ParentReference struct {
286284
//
287285
// +optional
288286
// +kubebuilder:default=Gateway
289-
//nolint:kubeapilinter // ignore kubeapilinter here as we want to use pointer for optional struct.
290-
Kind *Kind `json:"kind,omitempty"`
287+
Kind Kind `json:"kind,omitempty"`
291288

292289
// Name is the name of the referent API object.
293290
//
@@ -303,6 +300,5 @@ type ParentReference struct {
303300
// documentation for details: https://gateway-api.sigs.k8s.io/api-types/referencegrant/
304301
//
305302
// +optional
306-
//nolint:kubeapilinter // ignore kubeapilinter here as we want to use pointer for optional struct.
307-
Namespace *Namespace `json:"namespace,omitempty"`
303+
Namespace Namespace `json:"namespace,omitempty"`
308304
}

api/v1/zz_generated.deepcopy.go

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

apix/v1alpha2/inferencepool_conversion.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ func toV1ParentRef(in ParentGatewayReference) v1.ParentReference {
159159
}
160160
if in.Kind != nil {
161161
k := v1.Kind(*in.Kind)
162-
out.Kind = &k
162+
out.Kind = k
163163
}
164164
if in.Namespace != nil {
165165
ns := v1.Namespace(*in.Namespace)
166-
out.Namespace = &ns
166+
out.Namespace = ns
167167
}
168168
return out
169169
}
@@ -176,12 +176,12 @@ func fromV1ParentRef(in v1.ParentReference) ParentGatewayReference {
176176
g := Group(*in.Group)
177177
out.Group = &g
178178
}
179-
if in.Kind != nil {
180-
k := Kind(*in.Kind)
179+
if in.Kind != "" {
180+
k := Kind(in.Kind)
181181
out.Kind = &k
182182
}
183-
if in.Namespace != nil {
184-
ns := Namespace(*in.Namespace)
183+
if in.Namespace != "" {
184+
ns := Namespace(in.Namespace)
185185
out.Namespace = &ns
186186
}
187187
return out
@@ -196,14 +196,14 @@ func convertExtensionRefToV1(src *Extension) (v1.EndpointPickerRef, error) {
196196
endpointPickerRef.Group = ptr.To(v1.Group(*src.Group))
197197
}
198198
if src.Kind != nil {
199-
endpointPickerRef.Kind = ptr.To(v1.Kind(*src.Kind))
199+
endpointPickerRef.Kind = v1.Kind(*src.Kind)
200200
}
201201
endpointPickerRef.Name = v1.ObjectName(src.Name)
202202
if src.PortNumber != nil {
203203
endpointPickerRef.PortNumber = ptr.To(v1.PortNumber(*src.PortNumber))
204204
}
205205
if src.FailureMode != nil {
206-
endpointPickerRef.FailureMode = ptr.To(v1.EndpointPickerFailureMode(*src.FailureMode))
206+
endpointPickerRef.FailureMode = v1.EndpointPickerFailureMode(*src.FailureMode)
207207
}
208208

209209
return endpointPickerRef, nil
@@ -217,15 +217,15 @@ func convertEndpointPickerRefFromV1(src *v1.EndpointPickerRef) (Extension, error
217217
if src.Group != nil {
218218
extension.Group = ptr.To(Group(*src.Group))
219219
}
220-
if src.Kind != nil {
221-
extension.Kind = ptr.To(Kind(*src.Kind))
220+
if src.Kind != "" {
221+
extension.Kind = ptr.To(Kind(src.Kind))
222222
}
223223
extension.Name = ObjectName(src.Name)
224224
if src.PortNumber != nil {
225225
extension.PortNumber = ptr.To(PortNumber(*src.PortNumber))
226226
}
227-
if src.FailureMode != nil {
228-
extension.FailureMode = ptr.To(ExtensionFailureMode(*src.FailureMode))
227+
if src.FailureMode != "" {
228+
extension.FailureMode = ptr.To(ExtensionFailureMode(src.FailureMode))
229229
}
230230
return extension, nil
231231
}

apix/v1alpha2/inferencepool_conversion_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ func TestInferencePoolConvertTo(t *testing.T) {
102102
TargetPorts: []v1.Port{{Number: v1.PortNumber(int32(8080))}},
103103
EndpointPickerRef: v1.EndpointPickerRef{
104104
Group: &v1Group,
105-
Kind: &v1Kind,
105+
Kind: v1Kind,
106106
Name: "my-epp-service",
107107
PortNumber: &v1PortNumber,
108-
FailureMode: &v1FailureMode,
108+
FailureMode: v1FailureMode,
109109
},
110110
},
111111
Status: v1.InferencePoolStatus{
@@ -237,10 +237,10 @@ func TestInferencePoolConvertFrom(t *testing.T) {
237237
TargetPorts: []v1.Port{{Number: v1.PortNumber(int32(8080))}},
238238
EndpointPickerRef: v1.EndpointPickerRef{
239239
Group: &v1Group,
240-
Kind: &v1Kind,
240+
Kind: v1Kind,
241241
Name: "my-epp-service",
242242
PortNumber: &v1PortNumber,
243-
FailureMode: &v1FailureMode,
243+
FailureMode: v1FailureMode,
244244
},
245245
},
246246
Status: v1.InferencePoolStatus{

conformance/utils/kubernetes/helpers.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3333
"k8s.io/apimachinery/pkg/types"
3434
"k8s.io/apimachinery/pkg/util/wait"
35-
"k8s.io/utils/ptr"
3635
"sigs.k8s.io/controller-runtime/pkg/client"
3736
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
3837
gatewayapiconfig "sigs.k8s.io/gateway-api/conformance/utils/config"
@@ -106,8 +105,8 @@ func InferencePoolMustHaveCondition(t *testing.T, c client.Reader, poolNN types.
106105
}
107106

108107
for _, parentStatus := range pool.Status.Parents {
109-
if parentStatus.ParentRef.Namespace != nil &&
110-
string(*parentStatus.ParentRef.Namespace) == gateway.Namespace &&
108+
if parentStatus.ParentRef.Namespace != "" &&
109+
string(parentStatus.ParentRef.Namespace) == gateway.Namespace &&
111110
string(parentStatus.ParentRef.Name) == gateway.Name {
112111
if checkCondition(t, parentStatus.Conditions, expectedCondition) {
113112
conditionFound = true
@@ -134,10 +133,10 @@ func InferencePoolMustHaveCondition(t *testing.T, c client.Reader, poolNN types.
134133
}
135134
for i, parentStatus := range lastObservedPool.Status.Parents {
136135
namespace := parentStatus.ParentRef.Namespace
137-
if namespace == nil {
138-
namespace = ptr.To(inferenceapi.Namespace(poolNN.Namespace)) // Fallback to the pool's namespace
136+
if namespace == "" {
137+
namespace = inferenceapi.Namespace(poolNN.Namespace) // Fallback to the pool's namespace
139138
}
140-
debugMsg += fmt.Sprintf("\n Parent %d (Gateway: %s/%s):", i, *namespace, parentStatus.ParentRef.Name)
139+
debugMsg += fmt.Sprintf("\n Parent %d (Gateway: %s/%s):", i, namespace, parentStatus.ParentRef.Name)
141140
if len(parentStatus.Conditions) == 0 {
142141
debugMsg += " (No conditions reported for this parent)"
143142
}

site-src/reference/spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ _Appears in:_
4949
| Field | Description | Default | Validation |
5050
| --- | --- | --- | --- |
5151
| `group` _[Group](#group)_ | Group is the group of the referent API object. When unspecified, the default value<br />is "", representing the Core API group. | | MaxLength: 253 <br />MinLength: 0 <br />Pattern: `^$\|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$` <br /> |
52-
| `kind` _[Kind](#kind)_ | Kind is the Kubernetes resource kind of the referent API object. When unspecified,<br />the referent is assumed to be a "Service" kind.<br />ExternalName services can refer to CNAME DNS records that may live<br />outside of the cluster and as such are difficult to reason about in<br />terms of conformance. They also may not be safe to forward to (see<br />CVE-2021-25740 for more information). Implementations MUST NOT<br />support ExternalName Services. | Service | MaxLength: 63 <br />MinLength: 1 <br />Pattern: `^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$` <br /> |
52+
| `kind` _[Kind](#kind)_ | Kind is the Kubernetes resource kind of the referent.<br />Required if the referent is ambiguous, e.g. service with multiple ports.<br />Defaults to "Service" when not specified.<br />ExternalName services can refer to CNAME DNS records that may live<br />outside of the cluster and as such are difficult to reason about in<br />terms of conformance. They also may not be safe to forward to (see<br />CVE-2021-25740 for more information). Implementations MUST NOT<br />support ExternalName Services. | Service | MaxLength: 63 <br />MinLength: 1 <br />Pattern: `^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$` <br /> |
5353
| `name` _[ObjectName](#objectname)_ | Name is the name of the referent API object. | | MaxLength: 253 <br />MinLength: 1 <br /> |
5454
| `portNumber` _[PortNumber](#portnumber)_ | PortNumber is the port number of the Endpoint Picker extension service. When unspecified,<br />implementations SHOULD infer a default value of 9002 when the kind field is "Service" or<br />unspecified (defaults to "Service"). | | Maximum: 65535 <br />Minimum: 1 <br /> |
5555
| `failureMode` _[EndpointPickerFailureMode](#endpointpickerfailuremode)_ | FailureMode configures how the parent handles the case when the Endpoint Picker extension<br />is non-responsive. When unspecified, defaults to "FailClose". | FailClose | Enum: [FailOpen FailClose] <br /> |

0 commit comments

Comments
 (0)