Skip to content

Commit

Permalink
make the serialized featuregate an input
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Mar 11, 2024
1 parent f608b5d commit b0fe1d7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
9 changes: 7 additions & 2 deletions tools/codegen/cmd/crd_manifest_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package main

import (
"fmt"
"github.com/openshift/api/tools/codegen/pkg/manifestmerge"

"github.com/openshift/api/tools/codegen/pkg/generation"
"github.com/openshift/api/tools/codegen/pkg/manifestmerge"
"github.com/spf13/cobra"
)

var (
manifestMergePayloadManifestPath string
)

// schemapatchCmd represents the schemapatch command
var crdManifestMerge = &cobra.Command{
Use: "crd-manifest-merge",
Expand All @@ -30,6 +33,8 @@ var crdManifestMerge = &cobra.Command{

func init() {
rootCmd.AddCommand(crdManifestMerge)

rootCmd.PersistentFlags().StringVar(&manifestMergePayloadManifestPath, "manifest-merge:payload-manifest-path", manifestmerge.DefaultPayloadFeatureGatePath, "path to directory containing the FeatureGate YAMLs for each FeatureSet,ClusterProfile tuple.")
}

// newSchemaPatchGenerator builds a new schemapatch generator.
Expand Down
8 changes: 4 additions & 4 deletions tools/codegen/pkg/manifestmerge/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/sets"
"os"
"path"
kyaml "sigs.k8s.io/yaml"
"strings"
)

func FilterForFeatureSet(featureSetName string) (ManifestFilter, error) {
func FilterForFeatureSet(payloadFeatureGatePath, featureSetName string) (ManifestFilter, error) {
if featureSetName == "CustomNoUpgrade" {
return &CustomNoUpgrade{}, nil
}

// TODO find pointers to serialized featuregates. I'm sure Joel has some sneaky thing that prevents me from doing the "simple" relative path.
featureGateFilename := ""
switch {
case featureSetName == "TechPreviewNoUpgrade":
featureGateFilename = "payload-manifests/featuregates/featureGate-TechPreviewNoUpgrade.yaml"
featureGateFilename = path.Join(payloadFeatureGatePath, "featureGate-TechPreviewNoUpgrade.yaml")
case featureSetName == "Default":
featureGateFilename = "payload-manifests/featuregates/featureGate-Default.yaml"
featureGateFilename = path.Join(payloadFeatureGatePath, "featureGate-Default.yaml")
default:
return nil, fmt.Errorf("unrecognized featureset name %q", featureSetName)
}
Expand Down
30 changes: 23 additions & 7 deletions tools/codegen/pkg/manifestmerge/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (
kyaml "sigs.k8s.io/yaml"
)

var (
DefaultPayloadFeatureGatePath = filepath.Join("payload-manifests", "featuregates")
)

var defaultClusterProfilesToInject = []string{
"include.release.openshift.io/ibm-cloud-managed",
"include.release.openshift.io/self-managed-high-availability",
Expand All @@ -46,22 +50,34 @@ type Options struct {
// and FeatureGate handling will be required and we'll generate multiple files.
// It also allows the specification of custom clusterProfiles until we normalize that too.
TupleOverrides []generation.TupleOverride

// PayloadFeatureGatePath is a specified path for the featuregate CRD to inform whether particular
// gates are off or on.
// If not set, the default "payload-manifests/featuregates" is used.
PayloadFeatureGatePath string
}

// generator implements the generation.Generator interface.
// It is designed to generate schemapatch updates for a particular API group.
type generator struct {
disabled bool
verify bool
tupleOverrides []generation.TupleOverride
disabled bool
verify bool
tupleOverrides []generation.TupleOverride
payloadFeatureGatePath string
}

// NewGenerator builds a new schemapatch generator.
func NewGenerator(opts Options) generation.Generator {
payloadFeatureGatePath := DefaultPayloadFeatureGatePath
if opts.PayloadFeatureGatePath != "" {
payloadFeatureGatePath = opts.PayloadFeatureGatePath
}

return &generator{
disabled: opts.Disabled,
verify: opts.Verify,
tupleOverrides: opts.TupleOverrides,
disabled: opts.Disabled,
verify: opts.Verify,
tupleOverrides: opts.TupleOverrides,
payloadFeatureGatePath: payloadFeatureGatePath,
}
}

Expand Down Expand Up @@ -252,7 +268,7 @@ func (g *generator) genGroupVersion(group string, version generation.APIVersionC
// this assumption works for everything *except* for authentication.
for _, featureSetName := range []string{"Default", "TechPreviewNoUpgrade", "CustomNoUpgrade"} {
// TODO this will eventually need the clusterprofile too
partialManifestFilter, err := FilterForFeatureSet(featureSetName)
partialManifestFilter, err := FilterForFeatureSet(g.payloadFeatureGatePath, featureSetName)
if err != nil {
errs = append(errs, err)
continue
Expand Down

0 comments on commit b0fe1d7

Please sign in to comment.