Skip to content

Commit 6322aaa

Browse files
committed
add allow-crds-mismatch flag, check suite version
Signed-off-by: Mattia Lavacca <[email protected]>
1 parent b1f0239 commit 6322aaa

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

conformance/experimental_conformance_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var (
4747
namespaceAnnotations map[string]string
4848
implementation *confv1a1.Implementation
4949
mode string
50+
allowCRDsMismatch bool
5051
conformanceProfiles sets.Set[suite.ConformanceProfileName]
5152
skipTests []string
5253
)
@@ -81,6 +82,7 @@ func TestExperimentalConformance(t *testing.T) {
8182
// experimental conformance flags
8283
conformanceProfiles = suite.ParseConformanceProfiles(*flags.ConformanceProfiles)
8384
mode = *flags.Mode
85+
allowCRDsMismatch = *flags.AllowCRDsMismatch
8486

8587
if conformanceProfiles.Len() > 0 {
8688
// if some conformance profiles have been set, run the experimental conformance suite...
@@ -124,6 +126,7 @@ func testExperimentalConformance(t *testing.T) {
124126
SkipTests: skipTests,
125127
},
126128
Mode: mode,
129+
AllowCRDsMismatch: allowCRDsMismatch,
127130
Implementation: *implementation,
128131
ConformanceProfiles: conformanceProfiles,
129132
})

conformance/utils/flags/experimental_flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var (
3535
ImplementationVersion = flag.String("version", "", "Implementation's version to issue conformance to")
3636
ImplementationContact = flag.String("contact", "", "Comma-separated list of contact information for the maintainers")
3737
Mode = flag.String("mode", DefaultMode, "The operating mode of the implementation.")
38+
AllowCRDsMismatch = flag.Bool("allow-crds-mismatch", false, "Flag to allow the suite not to fail in case there is a mismatch between CRDs versions and channels.")
3839
ConformanceProfiles = flag.String("conformance-profiles", "", "Comma-separated list of the conformance profiles to run")
3940
ReportOutput = flag.String("report-output", "", "The file where to write the conformance report")
4041
)

conformance/utils/suite/experimental_suite.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,15 @@ type ExperimentalConformanceOptions struct {
9797
Options
9898

9999
Mode string
100+
AllowCRDsMismatch bool
100101
Implementation confv1a1.Implementation
101102
ConformanceProfiles sets.Set[ConformanceProfileName]
102103
}
103104

105+
const (
106+
undefinedKeyword = "UNDEFINED"
107+
)
108+
104109
// NewExperimentalConformanceTestSuite is a helper to use for creating a new ExperimentalConformanceTestSuite.
105110
func NewExperimentalConformanceTestSuite(options ExperimentalConformanceOptions) (*ExperimentalConformanceTestSuite, error) {
106111
config.SetupTimeoutConfig(&options.TimeoutConfig)
@@ -117,7 +122,14 @@ func NewExperimentalConformanceTestSuite(options ExperimentalConformanceOptions)
117122
}
118123
apiVersion, apiChannel, err := getAPIVersionAndChannel(installedCRDs.Items)
119124
if err != nil {
120-
return nil, err
125+
// in case an error is returned and the AllowCRDsMismatch flag is false, the suite fails.
126+
// This is the default behavior but can be customized in case one wants to experiment
127+
// with mixed versions/channels of the API.
128+
if !options.AllowCRDsMismatch {
129+
return nil, err
130+
}
131+
apiVersion = undefinedKeyword
132+
apiChannel = undefinedKeyword
121133
}
122134

123135
mode := flags.DefaultMode
@@ -395,5 +407,9 @@ func getAPIVersionAndChannel(crds []apiextensionsv1.CustomResourceDefinition) (v
395407
if version == "" || channel == "" {
396408
return "", "", errors.New("no Gateway API CRDs with the proper annotations found in the cluster")
397409
}
410+
if version != consts.BundleVersion {
411+
return "", "", errors.New("the installed CRDs version is different from the suite version")
412+
}
413+
398414
return version, channel, nil
399415
}

pkg/consts/consts.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ const (
2020
// BundleVersionAnnotation is the annotation key used in the Gateway API CRDs to specify
2121
// the installed Gateway API version.
2222
BundleVersionAnnotation = "gateway.networking.k8s.io/bundle-version"
23+
2324
// ChannelAnnotation is the annotation key used in the Gateway API CRDs to specify
2425
// the installed Gateway API channel.
2526
ChannelAnnotation = "gateway.networking.k8s.io/channel"
27+
28+
// BundleVersion is the value used for the "gateway.networking.k8s.io/bundle-version" annotation.
29+
// These value must be updated during the release process.
30+
BundleVersion = "v1.0.0"
31+
32+
// ApprovalLink is the value used for the "api-approved.kubernetes.io" annotation.
33+
// These value must be updated during the release process.
34+
ApprovalLink = "https://github.com/kubernetes-sigs/gateway-api/pull/2466"
2635
)

pkg/generator/main.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ import (
3232
"sigs.k8s.io/gateway-api/pkg/consts"
3333
)
3434

35-
const (
36-
// These values must be updated during the release process
37-
bundleVersion = "v1.0.0"
38-
approvalLink = "https://github.com/kubernetes-sigs/gateway-api/pull/2466"
39-
)
40-
4135
var standardKinds = map[string]bool{
4236
"GatewayClass": true,
4337
"Gateway": true,
@@ -103,9 +97,9 @@ func main() {
10397
if crdRaw.ObjectMeta.Annotations == nil {
10498
crdRaw.ObjectMeta.Annotations = map[string]string{}
10599
}
106-
crdRaw.ObjectMeta.Annotations[consts.BundleVersionAnnotation] = bundleVersion
100+
crdRaw.ObjectMeta.Annotations[consts.BundleVersionAnnotation] = consts.BundleVersion
107101
crdRaw.ObjectMeta.Annotations[consts.ChannelAnnotation] = channel
108-
crdRaw.ObjectMeta.Annotations[apiext.KubeAPIApprovedAnnotation] = approvalLink
102+
crdRaw.ObjectMeta.Annotations[apiext.KubeAPIApprovedAnnotation] = consts.ApprovalLink
109103

110104
// Prevent the top level metadata for the CRD to be generated regardless of the intention in the arguments
111105
crd.FixTopLevelMetadata(crdRaw)

0 commit comments

Comments
 (0)