Skip to content

Commit 5797361

Browse files
committed
Handle requiredFeatureGates in partial manifests and manifest merge
1 parent 0b15657 commit 5797361

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

tools/codegen/pkg/emptypartialschemas/content_creator.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ package emptypartialschemas
22

33
import (
44
"fmt"
5+
"os"
6+
"path/filepath"
7+
"strings"
8+
59
"github.com/google/go-cmp/cmp"
610
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
711
"k8s.io/apimachinery/pkg/api/equality"
812
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
913
utilerrors "k8s.io/apimachinery/pkg/util/errors"
1014
"k8s.io/apimachinery/pkg/util/sets"
1115
"k8s.io/klog/v2"
12-
"os"
13-
"path/filepath"
14-
"strings"
1516
)
1617

1718
func createFeatureGatedCRDManifests(allCRDInfo map[string]*CRDInfo, outputDir string, verify bool) error {
@@ -128,12 +129,9 @@ func ensureNoExtraFields(minimalCRD, existingCRD *apiextensionsv1.CustomResource
128129
func minimalCRDFor(crdInfo *CRDInfo, featureGate string) *apiextensionsv1.CustomResourceDefinition {
129130
ret := &apiextensionsv1.CustomResourceDefinition{
130131
ObjectMeta: metav1.ObjectMeta{
131-
Name: crdInfo.CRDName,
132-
Annotations: map[string]string{
133-
// notice that this produces a "" featuregate to mean ungated
134-
fmt.Sprintf("feature-gate.release.openshift.io/%s", featureGate): "true",
135-
},
136-
Labels: map[string]string{},
132+
Name: crdInfo.CRDName,
133+
Annotations: map[string]string{},
134+
Labels: map[string]string{},
137135
},
138136
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
139137
Group: crdInfo.GroupName,
@@ -160,6 +158,12 @@ func minimalCRDFor(crdInfo *CRDInfo, featureGate string) *apiextensionsv1.Custom
160158
PreserveUnknownFields: false,
161159
},
162160
}
161+
162+
for _, fg := range strings.Split(featureGate, "+") {
163+
// notice that this produces a "" featuregate to mean ungated
164+
ret.Annotations[fmt.Sprintf("feature-gate.release.openshift.io/%s", fg)] = "true"
165+
}
166+
163167
if len(crdInfo.FilenameRunLevel) > 0 {
164168
ret.Annotations["api.openshift.io/filename-cvo-runlevel"] = crdInfo.FilenameRunLevel
165169
}

tools/codegen/pkg/emptypartialschemas/tags.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package emptypartialschemas
22

33
import (
44
"fmt"
5-
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
6-
"k8s.io/gengo/types"
75
"strconv"
86
"strings"
7+
8+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
9+
"k8s.io/gengo/types"
910
)
1011

1112
// known tags that are handled by empty partial schema generation.
@@ -83,6 +84,17 @@ func extractFeatureGatesFromValidationMarker(comments []string, tagName string)
8384
}
8485
}
8586

87+
for _, tagVal := range tagVals {
88+
requiredFeatureGates := extractNamedValuesFromSingleLine(tagVal)["requiredFeatureGate"]
89+
90+
// Use + as the separator between required feature gates in file names.
91+
requiredFeatureGates = strings.Replace(requiredFeatureGates, ";", "+", -1)
92+
93+
if len(requiredFeatureGates) > 0 {
94+
ret = append(ret, requiredFeatureGates)
95+
}
96+
}
97+
8698
return ret
8799
}
88100

tools/codegen/pkg/manifestmerge/filters.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ package manifestmerge
22

33
import (
44
"fmt"
5+
"os"
6+
"path"
7+
"path/filepath"
8+
"strings"
9+
510
"github.com/openshift/api/tools/codegen/pkg/utils"
611
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
712
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
813
"k8s.io/apimachinery/pkg/util/sets"
9-
"os"
10-
"path"
11-
"path/filepath"
1214
kyaml "sigs.k8s.io/yaml"
13-
"strings"
1415
)
1516

1617
func AllKnownFeatureSets(payloadFeatureGatePath string) (sets.String, error) {
@@ -149,7 +150,7 @@ func (f *ForFeatureGates) UseManifest(data []byte) (bool, error) {
149150
return true, nil
150151
}
151152

152-
return manifestFeatureGates.HasAny(f.allowedFeatureGates.UnsortedList()...), nil
153+
return f.allowedFeatureGates.HasAll(manifestFeatureGates.UnsortedList()...), nil
153154
}
154155

155156
func (f *ForFeatureGates) String() string {

0 commit comments

Comments
 (0)