Skip to content

Commit

Permalink
wip: test mock
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalPazz committed Feb 19, 2025
1 parent 6a849d8 commit 26365be
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
73 changes: 73 additions & 0 deletions conformance/tests/gateway-optional-address-value.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tests

import (
"context"
"testing"

"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

v1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"
)

func init() {
ConformanceTests = append(ConformanceTests, GatewayOptionalAddressValue)
}

var GatewayOptionalAddressValue = suite.ConformanceTest{
ShortName: "GatewayOptionalAddressValue",
Description: "Check Gateway Support for GatewayAddressEmpty feature",
Features: []features.FeatureName{
features.SupportGateway,
features.SupportGatewayAddressEmpty,
},
Manifests: []string{
"tests/gateway-optional-address-value.yaml",
},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
ns := "gateway-conformance-infra"

kubernetes.NamespacesMustBeReady(t, s.Client, s.TimeoutConfig, []string{ns})

gwNN := types.NamespacedName{
Name: "gateway-without-address-value",
Namespace: "gateway-conformance-infra",
}
ctx, cancel := context.WithTimeout(context.Background(), s.TimeoutConfig.DefaultTestTimeout)
defer cancel()

t.Logf("waiting for namespace %s and Gateway %s to be ready for testing", gwNN.Namespace, gwNN.Name)
kubernetes.GatewayMustHaveLatestConditions(t, s.Client, s.TimeoutConfig, gwNN)

t.Logf("retrieving Gateway %s/%s", gwNN.Namespace, gwNN.Name)
currentGW := &v1.Gateway{}
err := s.Client.Get(ctx, gwNN, currentGW)
require.NoError(t, err, "error getting Gateway: %v", err)
t.Logf("verifying that the Gateway %s/%s is accepted without address value field", gwNN.Namespace, gwNN.Name)
kubernetes.GatewayMustHaveCondition(t, s.Client, s.TimeoutConfig, gwNN, metav1.Condition{
Type: string(v1.GatewayConditionAccepted),
Status: metav1.ConditionTrue,
})

},
}
17 changes: 17 additions & 0 deletions conformance/tests/gateway-optional-address-value.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway-without-address-value
namespace: gateway-conformance-infra
annotations:
gateway-api/skip-this-for-readiness: "true"
spec:
gatewayClassName: "{GATEWAY_CLASS_NAME}"
addresses:
# How should we inject a valid type here?
- type: "VALID_ADDRESS_TYPE_PLACEHOLDER"
listeners:
- name: http
port: 8080
protocol: HTTP
11 changes: 11 additions & 0 deletions pkg/features/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const (
// SupportGatewayInfrastructureAnnotations option indicates support for
// spec.infrastructure.annotations and spec.infrastructure.labels
SupportGatewayInfrastructurePropagation FeatureName = "GatewayInfrastructurePropagation"

// SupportGatewayAddressEmpty option indicates support for an empty
// spec.addresses.value field
SupportGatewayAddressEmpty FeatureName = "GatewayAddressEmpty"
)

var (
Expand All @@ -83,6 +87,12 @@ var (
Name: SupportGatewayInfrastructurePropagation,
Channel: FeatureChannelExperimental,
}

// GatewayAddressEmptyFeature contains metadata for the SupportGatewayAddressEmpty feature.
GatewayEmptyAddressFeature = Feature{
Name: SupportGatewayAddressEmpty,
Channel: FeatureChannelExperimental,
}
)

// GatewayExtendedFeatures are extra generic features that implementations may
Expand All @@ -92,4 +102,5 @@ var GatewayExtendedFeatures = sets.New(
GatewayStaticAddressesFeature,
GatewayHTTPListenerIsolationFeature,
GatewayInfrastructurePropagationFeature,
GatewayEmptyAddressFeature,
)

0 comments on commit 26365be

Please sign in to comment.