Skip to content

Commit d39cc82

Browse files
committed
wip: test mock
1 parent e5ed53f commit d39cc82

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package tests
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
"github.com/stretchr/testify/require"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/apimachinery/pkg/types"
26+
27+
v1 "sigs.k8s.io/gateway-api/apis/v1"
28+
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
29+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
30+
"sigs.k8s.io/gateway-api/pkg/features"
31+
)
32+
33+
func init() {
34+
ConformanceTests = append(ConformanceTests, GatewayOptionalAddressValue)
35+
}
36+
37+
var GatewayOptionalAddressValue = suite.ConformanceTest{
38+
ShortName: "GatewayOptionalAddressValue",
39+
Description: "Check Gateway Support for GatewayAddressEmpty feature",
40+
Features: []features.FeatureName{
41+
features.SupportGateway,
42+
features.SupportGatewayAddressEmpty,
43+
},
44+
Manifests: []string{
45+
"tests/gateway-optional-address-value.yaml",
46+
},
47+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
48+
ns := "gateway-conformance-infra"
49+
50+
kubernetes.NamespacesMustBeReady(t, s.Client, s.TimeoutConfig, []string{ns})
51+
52+
gwNN := types.NamespacedName{
53+
Name: "gateway-without-address-value",
54+
Namespace: "gateway-conformance-infra",
55+
}
56+
ctx, cancel := context.WithTimeout(context.Background(), s.TimeoutConfig.DefaultTestTimeout)
57+
defer cancel()
58+
59+
t.Logf("waiting for namespace %s and Gateway %s to be ready for testing", gwNN.Namespace, gwNN.Name)
60+
kubernetes.GatewayMustHaveLatestConditions(t, s.Client, s.TimeoutConfig, gwNN)
61+
62+
t.Logf("retrieving Gateway %s/%s", gwNN.Namespace, gwNN.Name)
63+
currentGW := &v1.Gateway{}
64+
err := s.Client.Get(ctx, gwNN, currentGW)
65+
require.NoError(t, err, "error getting Gateway: %v", err)
66+
t.Logf("verifying that the Gateway %s/%s is accepted without address value field", gwNN.Namespace, gwNN.Name)
67+
kubernetes.GatewayMustHaveCondition(t, s.Client, s.TimeoutConfig, gwNN, metav1.Condition{
68+
Type: string(v1.GatewayConditionAccepted),
69+
Status: metav1.ConditionTrue,
70+
})
71+
72+
},
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
apiVersion: gateway.networking.k8s.io/v1
3+
kind: Gateway
4+
metadata:
5+
name: gateway-without-address-value
6+
namespace: gateway-conformance-infra
7+
annotations:
8+
gateway-api/skip-this-for-readiness: "true"
9+
spec:
10+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
11+
addresses:
12+
# How should we inject a valid type here?
13+
- type: "VALID_ADDRESS_TYPE_PLACEHOLDER"
14+
listeners:
15+
- name: http
16+
port: 8080
17+
protocol: HTTP

pkg/features/gateway.go

+11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ const (
6060
// SupportGatewayInfrastructureAnnotations option indicates support for
6161
// spec.infrastructure.annotations and spec.infrastructure.labels
6262
SupportGatewayInfrastructurePropagation FeatureName = "GatewayInfrastructurePropagation"
63+
64+
// SupportGatewayAddressEmpty option indicates support for an empty
65+
// spec.addresses.value field
66+
SupportGatewayAddressEmpty FeatureName = "GatewayAddressEmpty"
6367
)
6468

6569
var (
@@ -83,6 +87,12 @@ var (
8387
Name: SupportGatewayInfrastructurePropagation,
8488
Channel: FeatureChannelExperimental,
8589
}
90+
91+
// GatewayAddressEmptyFeature contains metadata for the SupportGatewayAddressEmpty feature.
92+
GatewayEmptyAddressFeature = Feature{
93+
Name: SupportGatewayAddressEmpty,
94+
Channel: FeatureChannelExperimental,
95+
}
8696
)
8797

8898
// GatewayExtendedFeatures are extra generic features that implementations may
@@ -92,4 +102,5 @@ var GatewayExtendedFeatures = sets.New(
92102
GatewayStaticAddressesFeature,
93103
GatewayHTTPListenerIsolationFeature,
94104
GatewayInfrastructurePropagationFeature,
105+
GatewayEmptyAddressFeature,
95106
)

0 commit comments

Comments
 (0)