Skip to content

Commit d00794c

Browse files
committed
Add appProtocol to EndpointSlice.Port
1 parent 077f825 commit d00794c

File tree

12 files changed

+185
-49
lines changed

12 files changed

+185
-49
lines changed

api/openapi-spec/swagger.json

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

pkg/apis/discovery/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ type EndpointPort struct {
130130
// If this is not specified, ports are not restricted and must be
131131
// interpreted in the context of the specific consumer.
132132
Port *int32
133+
// The application protocol for this port.
134+
// This field follows standard Kubernetes label syntax.
135+
// Un-prefixed names are reserved for IANA standard service names (as per
136+
// RFC-6335 and http://www.iana.org/assignments/service-names).
137+
// Non-standard protocols should use prefixed names.
138+
// Default is empty string.
139+
// +optional
140+
AppProtocol *string
133141
}
134142

135143
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

pkg/apis/discovery/v1alpha1/zz_generated.conversion.go

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

pkg/apis/discovery/validation/validation.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ func validatePorts(endpointPorts []discovery.EndpointPort, fldPath *field.Path)
143143
} else if !supportedPortProtocols.Has(string(*endpointPort.Protocol)) {
144144
allErrs = append(allErrs, field.NotSupported(idxPath.Child("protocol"), *endpointPort.Protocol, supportedPortProtocols.List()))
145145
}
146+
147+
if endpointPort.AppProtocol != nil {
148+
for _, msg := range validation.IsQualifiedName(*endpointPort.AppProtocol) {
149+
allErrs = append(allErrs, field.Invalid(idxPath.Child("appProtocol"), endpointPort.AppProtocol, msg))
150+
}
151+
}
146152
}
147153

148154
return allErrs

pkg/apis/discovery/validation/validation_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,34 @@ func TestValidateEndpointSlice(t *testing.T) {
8888
}},
8989
},
9090
},
91+
"app-protocols": {
92+
expectedErrors: 0,
93+
endpointSlice: &discovery.EndpointSlice{
94+
ObjectMeta: standardMeta,
95+
AddressType: addressTypePtr(discovery.AddressTypeIP),
96+
Ports: []discovery.EndpointPort{{
97+
Name: utilpointer.StringPtr("one"),
98+
Protocol: protocolPtr(api.ProtocolTCP),
99+
AppProtocol: utilpointer.StringPtr("HTTP"),
100+
}, {
101+
Name: utilpointer.StringPtr("two"),
102+
Protocol: protocolPtr(api.ProtocolTCP),
103+
AppProtocol: utilpointer.StringPtr("https"),
104+
}, {
105+
Name: utilpointer.StringPtr("three"),
106+
Protocol: protocolPtr(api.ProtocolTCP),
107+
AppProtocol: utilpointer.StringPtr("my-protocol"),
108+
}, {
109+
Name: utilpointer.StringPtr("four"),
110+
Protocol: protocolPtr(api.ProtocolTCP),
111+
AppProtocol: utilpointer.StringPtr("example.com/custom-protocol"),
112+
}},
113+
Endpoints: []discovery.Endpoint{{
114+
Addresses: generateIPAddresses(1),
115+
Hostname: utilpointer.StringPtr("valid-123"),
116+
}},
117+
},
118+
},
91119
"empty-port-name": {
92120
expectedErrors: 0,
93121
endpointSlice: &discovery.EndpointSlice{
@@ -390,6 +418,22 @@ func TestValidateEndpointSlice(t *testing.T) {
390418
}},
391419
},
392420
},
421+
"bad-app-protocol": {
422+
expectedErrors: 1,
423+
endpointSlice: &discovery.EndpointSlice{
424+
ObjectMeta: standardMeta,
425+
AddressType: addressTypePtr(discovery.AddressTypeIP),
426+
Ports: []discovery.EndpointPort{{
427+
Name: utilpointer.StringPtr("http"),
428+
Protocol: protocolPtr(api.ProtocolTCP),
429+
AppProtocol: utilpointer.StringPtr("--"),
430+
}},
431+
Endpoints: []discovery.Endpoint{{
432+
Addresses: generateIPAddresses(1),
433+
Hostname: utilpointer.StringPtr("valid-123"),
434+
}},
435+
},
436+
},
393437
"empty-everything": {
394438
expectedErrors: 3,
395439
endpointSlice: &discovery.EndpointSlice{

pkg/apis/discovery/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.

pkg/controller/endpointslice/endpointslice_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func TestSyncServiceFull(t *testing.T) {
267267
slice := sliceList.Items[0]
268268
assert.Len(t, slice.Endpoints, 2, "Expected 2 endpoints in first slice")
269269
assert.Equal(t, slice.Annotations["endpoints.kubernetes.io/last-change-trigger-time"], serviceCreateTime.Format(time.RFC3339Nano))
270-
assert.EqualValues(t, []discovery.EndpointPort{{
270+
assert.ElementsMatch(t, []discovery.EndpointPort{{
271271
Name: strPtr("tcp-example"),
272272
Protocol: protoPtr(v1.ProtocolTCP),
273273
Port: int32Ptr(int32(80)),

staging/src/k8s.io/api/discovery/v1alpha1/generated.pb.go

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

staging/src/k8s.io/api/discovery/v1alpha1/generated.proto

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

staging/src/k8s.io/api/discovery/v1alpha1/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ type EndpointPort struct {
135135
// If this is not specified, ports are not restricted and must be
136136
// interpreted in the context of the specific consumer.
137137
Port *int32 `json:"port,omitempty" protobuf:"bytes,3,opt,name=port"`
138+
// The application protocol for this port.
139+
// This field follows standard Kubernetes label syntax.
140+
// Un-prefixed names are reserved for IANA standard service names (as per
141+
// RFC-6335 and http://www.iana.org/assignments/service-names).
142+
// Non-standard protocols should use prefixed names.
143+
// Default is empty string.
144+
AppProtocol *string `json:"appProtocol,omitempty" protobuf:"bytes,4,name=appProtocol"`
138145
}
139146

140147
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

0 commit comments

Comments
 (0)