Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conformance test flags are exported to other libraries that use the conformance test suite #2843

Merged
merged 8 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ import (
"sigs.k8s.io/gateway-api/conformance/tests"
"sigs.k8s.io/gateway-api/conformance/utils/flags"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"
)

var (
cfg *rest.Config
k8sClientset *kubernetes.Clientset
mgrClient client.Client
supportedFeatures sets.Set[suite.SupportedFeature]
exemptFeatures sets.Set[suite.SupportedFeature]
supportedFeatures sets.Set[features.SupportedFeature]
exemptFeatures sets.Set[features.SupportedFeature]
namespaceLabels map[string]string
namespaceAnnotations map[string]string
implementation *confv1.Implementation
Expand Down
10 changes: 6 additions & 4 deletions conformance/utils/suite/conformance.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import (
"testing"

"k8s.io/apimachinery/pkg/util/sets"

"sigs.k8s.io/gateway-api/pkg/features"
)

// ConformanceTest is used to define each individual conformance test.
type ConformanceTest struct {
ShortName string
Description string
Features []SupportedFeature
Features []features.SupportedFeature
Manifests []string
Slow bool
Parallel bool
Expand Down Expand Up @@ -67,13 +69,13 @@ func (test *ConformanceTest) Run(t *testing.T, suite *ConformanceTestSuite) {

// ParseSupportedFeatures parses flag arguments and converts the string to
// sets.Set[suite.SupportedFeature]
func ParseSupportedFeatures(f string) sets.Set[SupportedFeature] {
func ParseSupportedFeatures(f string) sets.Set[features.SupportedFeature] {
if f == "" {
return nil
}
res := sets.Set[SupportedFeature]{}
res := sets.Set[features.SupportedFeature]{}
for _, value := range strings.Split(f, ",") {
res.Insert(SupportedFeature(value))
res.Insert(features.SupportedFeature(value))
}
return res
}
Expand Down
16 changes: 9 additions & 7 deletions conformance/utils/suite/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"

"k8s.io/apimachinery/pkg/util/sets"

"sigs.k8s.io/gateway-api/pkg/features"
)

func TestParseSupportedFeatures(t *testing.T) {
Expand All @@ -30,13 +32,13 @@ func TestParseSupportedFeatures(t *testing.T) {
"b,c,d",
}

s1 := sets.Set[SupportedFeature]{}
s1.Insert(SupportedFeature("a"))
s2 := sets.Set[SupportedFeature]{}
s2.Insert(SupportedFeature("b"))
s2.Insert(SupportedFeature("c"))
s2.Insert(SupportedFeature("d"))
features := []sets.Set[SupportedFeature]{nil, s1, s2}
s1 := sets.Set[features.SupportedFeature]{}
s1.Insert("a")
s2 := sets.Set[features.SupportedFeature]{}
s2.Insert("b")
s2.Insert("c")
s2.Insert("d")
features := []sets.Set[features.SupportedFeature]{nil, s1, s2}

for i, f := range flags {
expect := features[i]
Expand Down
38 changes: 20 additions & 18 deletions conformance/utils/suite/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"fmt"

"k8s.io/apimachinery/pkg/util/sets"

"sigs.k8s.io/gateway-api/pkg/features"
)

// -----------------------------------------------------------------------------
Expand All @@ -33,8 +35,8 @@ import (
// For more details see the relevant GEP: https://gateway-api.sigs.k8s.io/geps/gep-1709/
type ConformanceProfile struct {
Name ConformanceProfileName
CoreFeatures sets.Set[SupportedFeature]
ExtendedFeatures sets.Set[SupportedFeature]
CoreFeatures sets.Set[features.SupportedFeature]
ExtendedFeatures sets.Set[features.SupportedFeature]
}

type ConformanceProfileName string
Expand Down Expand Up @@ -67,35 +69,35 @@ var (
HTTPConformanceProfile = ConformanceProfile{
Name: HTTPConformanceProfileName,
CoreFeatures: sets.New(
SupportGateway,
SupportReferenceGrant,
SupportHTTPRoute,
features.SupportGateway,
features.SupportReferenceGrant,
features.SupportHTTPRoute,
),
ExtendedFeatures: sets.New[SupportedFeature]().
Insert(GatewayExtendedFeatures.UnsortedList()...).
Insert(HTTPRouteExtendedFeatures.UnsortedList()...),
ExtendedFeatures: sets.New[features.SupportedFeature]().
Insert(features.GatewayExtendedFeatures.UnsortedList()...).
Insert(features.HTTPRouteExtendedFeatures.UnsortedList()...),
}

// TLSConformanceProfile is a ConformanceProfile that covers testing TLS
// related functionality with Gateways.
TLSConformanceProfile = ConformanceProfile{
Name: TLSConformanceProfileName,
CoreFeatures: sets.New(
SupportGateway,
SupportReferenceGrant,
SupportTLSRoute,
features.SupportGateway,
features.SupportReferenceGrant,
features.SupportTLSRoute,
),
ExtendedFeatures: GatewayExtendedFeatures,
ExtendedFeatures: features.GatewayExtendedFeatures,
}

// GRPCConformanceProfile is a ConformanceProfile that covers testing GRPC
// related functionality with Gateways.
GRPCConformanceProfile = ConformanceProfile{
Name: GRPCConformanceProfileName,
CoreFeatures: sets.New(
SupportGateway,
SupportReferenceGrant,
SupportGRPCRoute,
features.SupportGateway,
features.SupportReferenceGrant,
features.SupportGRPCRoute,
),
}

Expand All @@ -104,10 +106,10 @@ var (
MeshConformanceProfile = ConformanceProfile{
Name: MeshConformanceProfileName,
CoreFeatures: sets.New(
SupportMesh,
SupportHTTPRoute,
features.SupportMesh,
features.SupportHTTPRoute,
),
ExtendedFeatures: HTTPRouteExtendedFeatures,
ExtendedFeatures: features.HTTPRouteExtendedFeatures,
}
)

Expand Down
3 changes: 2 additions & 1 deletion conformance/utils/suite/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"

confv1 "sigs.k8s.io/gateway-api/conformance/apis/v1"
"sigs.k8s.io/gateway-api/pkg/features"
)

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -106,7 +107,7 @@ func (p profileReportsMap) list() (profileReports []confv1.ProfileReport) {
return
}

func (p profileReportsMap) compileResults(supportedFeaturesMap map[ConformanceProfileName]sets.Set[SupportedFeature], unsupportedFeaturesMap map[ConformanceProfileName]sets.Set[SupportedFeature]) {
func (p profileReportsMap) compileResults(supportedFeaturesMap map[ConformanceProfileName]sets.Set[features.SupportedFeature], unsupportedFeaturesMap map[ConformanceProfileName]sets.Set[features.SupportedFeature]) {
for key, report := range p {
// report the overall result for core features
switch {
Expand Down
27 changes: 14 additions & 13 deletions conformance/utils/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
"sigs.k8s.io/gateway-api/pkg/consts"
"sigs.k8s.io/gateway-api/pkg/features"
)

// -----------------------------------------------------------------------------
Expand All @@ -63,7 +64,7 @@ type ConformanceTestSuite struct {
BaseManifests string
MeshManifests string
Applier kubernetes.Applier
SupportedFeatures sets.Set[SupportedFeature]
SupportedFeatures sets.Set[features.SupportedFeature]
TimeoutConfig config.TimeoutConfig
SkipTests sets.Set[string]
RunTest string
Expand Down Expand Up @@ -104,11 +105,11 @@ type ConformanceTestSuite struct {

// extendedSupportedFeatures is a compiled list of named features that were
// marked as supported, and is used for reporting the test results.
extendedSupportedFeatures map[ConformanceProfileName]sets.Set[SupportedFeature]
extendedSupportedFeatures map[ConformanceProfileName]sets.Set[features.SupportedFeature]

// extendedUnsupportedFeatures is a compiled list of named features that were
// marked as not supported, and is used for reporting the test results.
extendedUnsupportedFeatures map[ConformanceProfileName]sets.Set[SupportedFeature]
extendedUnsupportedFeatures map[ConformanceProfileName]sets.Set[features.SupportedFeature]

// lock is a mutex to help ensure thread safety of the test suite object.
lock sync.RWMutex
Expand All @@ -130,8 +131,8 @@ type ConformanceOptions struct {
// CleanupBaseResources indicates whether or not the base test
// resources such as Gateways should be cleaned up after the run.
CleanupBaseResources bool
SupportedFeatures sets.Set[SupportedFeature]
ExemptFeatures sets.Set[SupportedFeature]
SupportedFeatures sets.Set[features.SupportedFeature]
ExemptFeatures sets.Set[features.SupportedFeature]
EnableAllSupportedFeatures bool
TimeoutConfig config.TimeoutConfig
// SkipTests contains all the tests not to be run and can be used to opt out
Expand Down Expand Up @@ -213,9 +214,9 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
// cover all features, if they don't they'll need to have provided a
// conformance profile or at least some specific features they support.
if options.EnableAllSupportedFeatures {
options.SupportedFeatures = AllFeatures
options.SupportedFeatures = features.AllFeatures
} else if options.SupportedFeatures == nil {
options.SupportedFeatures = sets.New[SupportedFeature]()
options.SupportedFeatures = sets.New[features.SupportedFeature]()
}

for feature := range options.ExemptFeatures {
Expand Down Expand Up @@ -244,8 +245,8 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
UsableNetworkAddresses: options.UsableNetworkAddresses,
UnusableNetworkAddresses: options.UnusableNetworkAddresses,
results: make(map[string]testResult),
extendedUnsupportedFeatures: make(map[ConformanceProfileName]sets.Set[SupportedFeature]),
extendedSupportedFeatures: make(map[ConformanceProfileName]sets.Set[SupportedFeature]),
extendedUnsupportedFeatures: make(map[ConformanceProfileName]sets.Set[features.SupportedFeature]),
extendedSupportedFeatures: make(map[ConformanceProfileName]sets.Set[features.SupportedFeature]),
conformanceProfiles: options.ConformanceProfiles,
implementation: options.Implementation,
mode: mode,
Expand All @@ -268,12 +269,12 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
for _, f := range conformanceProfile.ExtendedFeatures.UnsortedList() {
if options.SupportedFeatures.Has(f) {
if suite.extendedSupportedFeatures[conformanceProfileName] == nil {
suite.extendedSupportedFeatures[conformanceProfileName] = sets.New[SupportedFeature]()
suite.extendedSupportedFeatures[conformanceProfileName] = sets.New[features.SupportedFeature]()
}
suite.extendedSupportedFeatures[conformanceProfileName].Insert(f)
} else {
if suite.extendedUnsupportedFeatures[conformanceProfileName] == nil {
suite.extendedUnsupportedFeatures[conformanceProfileName] = sets.New[SupportedFeature]()
suite.extendedUnsupportedFeatures[conformanceProfileName] = sets.New[features.SupportedFeature]()
}
suite.extendedUnsupportedFeatures[conformanceProfileName].Insert(f)
}
Expand Down Expand Up @@ -306,7 +307,7 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T) {
suite.Applier.UsableNetworkAddresses = suite.UsableNetworkAddresses
suite.Applier.UnusableNetworkAddresses = suite.UnusableNetworkAddresses

if suite.SupportedFeatures.Has(SupportGateway) {
if suite.SupportedFeatures.Has(features.SupportGateway) {
t.Logf("Test Setup: Ensuring GatewayClass has been accepted")
suite.ControllerName = kubernetes.GWCMustHaveAcceptedConditionTrue(t, suite.Client, suite.TimeoutConfig, suite.GatewayClassName)

Expand Down Expand Up @@ -334,7 +335,7 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T) {
}
kubernetes.NamespacesMustBeReady(t, suite.Client, suite.TimeoutConfig, namespaces)
}
if suite.SupportedFeatures.Has(SupportMesh) {
if suite.SupportedFeatures.Has(features.SupportMesh) {
t.Logf("Test Setup: Applying base manifests")
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, suite.MeshManifests, suite.Cleanup)
t.Logf("Test Setup: Ensuring Gateways and Pods from mesh manifests are ready")
Expand Down
12 changes: 6 additions & 6 deletions hack/supportedfeatures/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (
"sort"
"strings"

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

func main() {
features := make([]string, suite.AllFeatures.Len())
for i, feat := range suite.AllFeatures.UnsortedList() {
features[i] = string(feat)
feats := make([]string, features.AllFeatures.Len())
for i, feat := range features.AllFeatures.UnsortedList() {
feats[i] = string(feat)
}
sort.Strings(features)
fmt.Println(strings.Join(features, ";"))
sort.Strings(feats)
fmt.Println(strings.Join(feats, ";"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package suite
package features

import "k8s.io/apimachinery/pkg/util/sets"

Expand Down