Skip to content

Commit 25f974c

Browse files
authored
[GEP-2162] Updated a new field on supported features inference from boolean to enum and remove from report. (#3885)
* Update inferred supported features report from bool to enum to account for exceptional case when only Mesh profile is being tested and no GWC available to determine supported features. * Changed enum names. * Added comment to report enum * Revert change caused by merge. * Converted enums from int to string for better readability. * Removed unused import. * Updated unit tests to reflect enum change to strings. * Removed skip tests from determining if supported features are inferred or manually selected. * Removed source update. * Updated unit tests. * Removed source enum from report. * start error string with lowercase. * Removed source getter. * removed undefined enum and added check for mesh features. * return error if mesh features are populated in gwc. * Updated unit tests. * Removed check for mesh profile before throwing error for publishing mesh features. As with this error we want to prevent mesh features under GWC, not mesh profiles for testing. * removed extra else * Removed not needed field from function. * Cleanup of extra field
1 parent b92e49b commit 25f974c

File tree

3 files changed

+86
-29
lines changed

3 files changed

+86
-29
lines changed

conformance/apis/v1/conformancereport.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ type ConformanceReport struct {
5050
// SucceededProvisionalTests is a list of the names of the provisional tests that
5151
// have been successfully run.
5252
SucceededProvisionalTests []string `json:"succeededProvisionalTests,omitempty"`
53-
54-
// InferredSupportedFeatures indicates whether the supported features were
55-
// automatically detected by the conformance suite.
56-
InferredSupportedFeatures bool `json:"inferredSupportedFeatures"`
5753
}
5854

5955
// Implementation provides metadata information on the downstream

conformance/utils/suite/suite.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type ConformanceTestSuite struct {
8484
// If SupportedFeatures are automatically determined from GWC Status.
8585
// This will be required to report in future iterations as the passing
8686
// will be determined based on this.
87-
isInferredSupportedFeatures bool
87+
supportedFeaturesSource supportedFeaturesSource
8888

8989
// mode is the operating mode of the implementation.
9090
// The default value for it is "default".
@@ -188,24 +188,37 @@ const (
188188
undefinedKeyword = "UNDEFINED"
189189
)
190190

191+
// SupportedFeaturesSource represents the source from which supported features are derived.
192+
// It is used to distinguish between them being inferred from GWC Status or manually
193+
// supplied for the conformance report.
194+
type supportedFeaturesSource string
195+
196+
const (
197+
supportedFeaturesSourceManual supportedFeaturesSource = "Manual"
198+
supportedFeaturesSourceInferred supportedFeaturesSource = "Inferred"
199+
)
200+
191201
// NewConformanceTestSuite is a helper to use for creating a new ConformanceTestSuite.
192202
func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite, error) {
193203
supportedFeatures := options.SupportedFeatures.Difference(options.ExemptFeatures)
194-
isInferred := false
195-
switch {
196-
case options.EnableAllSupportedFeatures:
204+
source := supportedFeaturesSourceManual
205+
if options.EnableAllSupportedFeatures {
197206
supportedFeatures = features.SetsToNamesSet(features.AllFeatures)
198-
case shouldInferSupportedFeatures(&options):
207+
} else if shouldInferSupportedFeatures(&options) {
199208
var err error
200209
supportedFeatures, err = fetchSupportedFeatures(options.Client, options.GatewayClassName)
201210
if err != nil {
202-
return nil, fmt.Errorf("Cannot infer supported features: %w", err)
211+
return nil, fmt.Errorf("cannot infer supported features: %w", err)
212+
}
213+
214+
if hasMeshFeatures(supportedFeatures) {
215+
return nil, fmt.Errorf("mesh features should not be populated in GatewayClass")
203216
}
204-
isInferred = true
217+
source = supportedFeaturesSourceInferred
205218
}
206219

207220
// If features were not inferred from Status, it's a GWC issue.
208-
if isInferred && supportedFeatures.Len() == 0 {
221+
if source == supportedFeaturesSourceInferred && supportedFeatures.Len() == 0 {
209222
return nil, fmt.Errorf("no supported features were determined for test suite")
210223
}
211224

@@ -273,7 +286,7 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
273286
mode: mode,
274287
apiVersion: apiVersion,
275288
apiChannel: apiChannel,
276-
isInferredSupportedFeatures: isInferred,
289+
supportedFeaturesSource: source,
277290
Hook: options.Hook,
278291
}
279292

@@ -394,10 +407,6 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T, tests []ConformanceTest)
394407
}
395408
}
396409

397-
func (suite *ConformanceTestSuite) IsInferredSupportedFeatures() bool {
398-
return suite.isInferredSupportedFeatures
399-
}
400-
401410
func (suite *ConformanceTestSuite) setClientsetForTest(test ConformanceTest) error {
402411
featureNames := []string{}
403412
for _, v := range test.Features {
@@ -552,7 +561,6 @@ func (suite *ConformanceTestSuite) Report() (*confv1.ConformanceReport, error) {
552561
GatewayAPIChannel: suite.apiChannel,
553562
ProfileReports: profileReports.list(),
554563
SucceededProvisionalTests: succeededProvisionalTests,
555-
InferredSupportedFeatures: suite.IsInferredSupportedFeatures(),
556564
}, nil
557565
}
558566

@@ -610,8 +618,6 @@ func shouldInferSupportedFeatures(opts *ConformanceOptions) bool {
610618
return !opts.EnableAllSupportedFeatures &&
611619
opts.SupportedFeatures.Len() == 0 &&
612620
opts.ExemptFeatures.Len() == 0 &&
613-
opts.ConformanceProfiles.Len() == 0 &&
614-
len(opts.SkipTests) == 0 &&
615621
opts.RunTest == ""
616622
}
617623

@@ -645,3 +651,7 @@ func getAPIVersionAndChannel(crds []apiextensionsv1.CustomResourceDefinition) (v
645651

646652
return version, channel, nil
647653
}
654+
655+
func hasMeshFeatures(f FeaturesSet) bool {
656+
return f.HasAny(features.SetsToNamesSet(features.MeshCoreFeatures, features.MeshExtendedFeatures).UnsortedList()...)
657+
}

conformance/utils/suite/suite_test.go

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ func TestSuiteReport(t *testing.T) {
280280
coreProvisionalTest.ShortName,
281281
extendedProvisionalTest.ShortName,
282282
},
283-
InferredSupportedFeatures: true,
284283
},
285284
},
286285
{
@@ -390,7 +389,6 @@ func TestSuiteReport(t *testing.T) {
390389
},
391390
},
392391
},
393-
InferredSupportedFeatures: true,
394392
},
395393
},
396394
}
@@ -434,33 +432,37 @@ func TestInferSupportedFeatures(t *testing.T) {
434432
exemptFeatures FeaturesSet
435433
ConformanceProfile sets.Set[ConformanceProfileName]
436434
expectedFeatures FeaturesSet
437-
expectedIsInferred bool
435+
expectedSource supportedFeaturesSource
438436
}{
439437
{
440-
name: "properly infer supported features",
441-
expectedFeatures: namesToFeatureSet(statusFeatureNames),
442-
expectedIsInferred: true,
438+
name: "properly infer supported features",
439+
expectedFeatures: namesToFeatureSet(statusFeatureNames),
440+
expectedSource: supportedFeaturesSourceInferred,
443441
},
444442
{
445443
name: "no features",
446444
supportedFeatures: sets.New[features.FeatureName]("Gateway"),
447445
expectedFeatures: sets.New[features.FeatureName]("Gateway"),
446+
expectedSource: supportedFeaturesSourceManual,
448447
},
449448
{
450449
name: "remove exempt features",
451450
supportedFeatures: sets.New[features.FeatureName]("Gateway", "HTTPRoute"),
452451
exemptFeatures: sets.New[features.FeatureName]("HTTPRoute"),
453452
expectedFeatures: sets.New[features.FeatureName]("Gateway"),
453+
expectedSource: supportedFeaturesSourceManual,
454454
},
455455
{
456456
name: "allow all features",
457457
allowAllFeatures: true,
458458
expectedFeatures: features.SetsToNamesSet(features.AllFeatures),
459+
expectedSource: supportedFeaturesSourceManual,
459460
},
460461
{
461462
name: "supports conformance profile - core",
462463
ConformanceProfile: sets.New(GatewayHTTPConformanceProfileName),
463-
expectedFeatures: namesToFeatureSet([]string{"Gateway", "HTTPRoute", "ReferenceGrant"}),
464+
expectedFeatures: namesToFeatureSet(statusFeatureNames),
465+
expectedSource: supportedFeaturesSourceInferred,
464466
},
465467
}
466468

@@ -512,8 +514,8 @@ func TestInferSupportedFeatures(t *testing.T) {
512514
t.Fatalf("error initializing conformance suite: %v", err)
513515
}
514516

515-
if cSuite.IsInferredSupportedFeatures() != tc.expectedIsInferred {
516-
t.Errorf("InferredSupportedFeatures mismatch: got %v, want %v", cSuite.IsInferredSupportedFeatures(), tc.expectedIsInferred)
517+
if cSuite.supportedFeaturesSource != tc.expectedSource {
518+
t.Errorf("InferredSupportedFeatures mismatch: got %v, want %v", cSuite.supportedFeaturesSource, tc.expectedSource)
517519
}
518520

519521
if equal := cSuite.SupportedFeatures.Equal(tc.expectedFeatures); !equal {
@@ -523,6 +525,55 @@ func TestInferSupportedFeatures(t *testing.T) {
523525
}
524526
}
525527

528+
func TestGWCPublishedMeshFeatures(t *testing.T) {
529+
gwcName := "ochopintre"
530+
gwc := &gatewayv1.GatewayClass{
531+
ObjectMeta: metav1.ObjectMeta{
532+
Name: gwcName,
533+
},
534+
Spec: gatewayv1.GatewayClassSpec{
535+
ControllerName: "example.com/gateway-controller",
536+
},
537+
Status: gatewayv1.GatewayClassStatus{
538+
Conditions: []metav1.Condition{
539+
{
540+
Type: string(gatewayv1.GatewayConditionAccepted),
541+
Status: metav1.ConditionTrue,
542+
Reason: "Accepted",
543+
Message: "GatewayClass is accepted and ready for use",
544+
},
545+
},
546+
SupportedFeatures: featureNamesToSet([]string{
547+
string(features.SupportGateway),
548+
string(features.SupportGatewayStaticAddresses),
549+
string(features.SupportMeshClusterIPMatching),
550+
string(features.SupportMeshConsumerRoute),
551+
}),
552+
},
553+
}
554+
scheme := runtime.NewScheme()
555+
scheme.AddKnownTypes(gatewayv1.SchemeGroupVersion, &gatewayv1.GatewayClass{})
556+
fakeClient := fake.NewClientBuilder().
557+
WithScheme(scheme).
558+
WithObjects(gwc).
559+
WithLists(&apiextensionsv1.CustomResourceDefinitionList{}).
560+
Build()
561+
562+
gatewayv1.Install(fakeClient.Scheme())
563+
apiextensionsv1.AddToScheme(fakeClient.Scheme())
564+
565+
options := ConformanceOptions{
566+
AllowCRDsMismatch: true,
567+
GatewayClassName: gwcName,
568+
Client: fakeClient,
569+
}
570+
571+
_, err := NewConformanceTestSuite(options)
572+
if err == nil {
573+
t.Fatalf("expected an error but got nil")
574+
}
575+
}
576+
526577
func featureNamesToSet(set []string) []gatewayv1.SupportedFeature {
527578
var features []gatewayv1.SupportedFeature
528579
for _, feature := range set {

0 commit comments

Comments
 (0)