forked from kubernetes-sigs/controller-tools
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the OPENSHIFT_REQUIRED_FEATURESET env var and openshift:enable:fe…
…atureSet marker
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package markers | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
"k8s.io/apimachinery/pkg/util/sets" | ||
"sigs.k8s.io/controller-tools/pkg/markers" | ||
) | ||
|
||
var RequiredFeatureSets = sets.NewString("") | ||
|
||
func init() { | ||
featureSet := os.Getenv("OPENSHIFT_REQUIRED_FEATURESET") | ||
if len(featureSet) == 0 { | ||
return | ||
} | ||
|
||
for _, curr := range strings.Split(featureSet, ",") { | ||
RequiredFeatureSets.Insert(curr) | ||
} | ||
} | ||
|
||
const OpenShiftFeatureSetMarkerName = "openshift:enable:FeatureSets" | ||
|
||
func init() { | ||
FieldOnlyMarkers = append(FieldOnlyMarkers, | ||
must(markers.MakeDefinition(OpenShiftFeatureSetMarkerName, markers.DescribesField, []string{})). | ||
WithHelp(markers.SimpleHelp("OpenShift", "specifies the FeatureSet that is required to generate this field.")), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package crd | ||
|
||
import ( | ||
"fmt" | ||
|
||
crdmarkers "sigs.k8s.io/controller-tools/pkg/crd/markers" | ||
"sigs.k8s.io/controller-tools/pkg/markers" | ||
) | ||
|
||
// mayHandleField returns true if the field should be considered by this invocation of the generator. | ||
// Right now, the only sip is based on the featureset marker. | ||
func mayHandleField(field markers.FieldInfo) bool { | ||
uncastFeatureSet := field.Markers.Get(crdmarkers.OpenShiftFeatureSetMarkerName) | ||
if uncastFeatureSet == nil { | ||
return true | ||
} | ||
|
||
featureSetsForField, ok := uncastFeatureSet.([]string) | ||
if !ok { | ||
panic(fmt.Sprintf("actually got %t", uncastFeatureSet)) | ||
} | ||
// if any of the field's declared featureSets match any of the manifest's declared featuresets, include the field. | ||
for _, currFeatureSetForField := range featureSetsForField { | ||
if crdmarkers.RequiredFeatureSets.Has(currFeatureSetForField) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package schemapatcher | ||
|
||
import ( | ||
"strings" | ||
|
||
crdmarkers "sigs.k8s.io/controller-tools/pkg/crd/markers" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
kyaml "sigs.k8s.io/yaml" | ||
) | ||
|
||
// mayHandleFile returns true if this manifest should progress past the file collection stage. | ||
// Currently, the only check is the feature-set annotation. | ||
func mayHandleFile(filename string, rawContent []byte) bool { | ||
manifest := &unstructured.Unstructured{} | ||
if err := kyaml.Unmarshal(rawContent, &manifest); err != nil { | ||
return true | ||
} | ||
|
||
manifestFeatureSets := sets.String{} | ||
if manifestFeatureSetString := manifest.GetAnnotations()["release.openshift.io/feature-set"]; len(manifestFeatureSets) > 0 { | ||
for _, curr := range strings.Split(manifestFeatureSetString, ",") { | ||
manifestFeatureSets.Insert(curr) | ||
} | ||
} | ||
return manifestFeatureSets.Equal(crdmarkers.RequiredFeatureSets) | ||
} |