Skip to content

Commit

Permalink
update bundle target to create unified CSV
Browse files Browse the repository at this point in the history
Signed-off-by: Nitin Goyal <[email protected]>
  • Loading branch information
iamniting committed Sep 10, 2024
1 parent cd1c1a3 commit 698318f
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 149 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,15 @@ endif
endif

.PHONY: bundle
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
bundle: manifests kustomize operator-sdk extract-maifests ## Generate bundle manifests and metadata, then validate generated files.
rm -rf bundle/manifests
$(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
$(OPERATOR_SDK) bundle validate ./bundle
find config/child -type f ! -name '*clusterserviceversion.yaml' -exec cp {} bundle/manifests/ \;
go run cmd/csv-merger/main.go --csv-input-files "$(shell find config/child -type f -name '*clusterserviceversion.yaml')"
$(OPERATOR_SDK) bundle validate ./bundle

.PHONY: bundle-build
bundle-build: ## Build the bundle image.
Expand Down
109 changes: 109 additions & 0 deletions cmd/csv-merger/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package main

import (
"flag"
"fmt"
"log"
"os"
"strings"

operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
"sigs.k8s.io/yaml"
)

var (
csvInputFiles = flag.String("csv-input-files", "", "the space separated CSV input files of child operators")
)

func main() {
flag.Parse()

if *csvInputFiles == "" {
log.Fatal("--csv-input-files is required")
}

odfCsvInputFile := "bundle/manifests/odf-operator.clusterserviceversion.yaml"
odfCsvOutputFile := "bundle/manifests/odf-operator.clusterserviceversion.yaml"
deploymentsOutputFile := "config/deployments/deployments.yaml"

csvFiles := strings.Split(*csvInputFiles, " ")
odfCsv := unmarshalCSV(odfCsvInputFile)

deployments := []appsv1.Deployment{}
apis := []string{}

for _, csvFile := range csvFiles {
csv := unmarshalCSV(csvFile)

// whitelisting APIs
for _, crd := range csv.Spec.CustomResourceDefinitions.Owned {
apis = append(apis, crd.Name)
}

odfCsv.Spec.CustomResourceDefinitions.Owned = append(
odfCsv.Spec.CustomResourceDefinitions.Owned, csv.Spec.CustomResourceDefinitions.Owned...)

odfCsv.Spec.InstallStrategy.StrategySpec.ClusterPermissions = append(
odfCsv.Spec.InstallStrategy.StrategySpec.ClusterPermissions, csv.Spec.InstallStrategy.StrategySpec.ClusterPermissions...)

odfCsv.Spec.InstallStrategy.StrategySpec.Permissions = append(
odfCsv.Spec.InstallStrategy.StrategySpec.Permissions, csv.Spec.InstallStrategy.StrategySpec.Permissions...)

for _, deploymentSpec := range csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs {

// Append the deployments to the odf CSV
if deploymentSpec.Name == "" {
odfCsv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs = append(
odfCsv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs, csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs...)
continue
}

// Append the deployments to the deployments
deployment := &appsv1.Deployment{}
deployment.ObjectMeta.Name = deploymentSpec.Name
deployment.ObjectMeta.Labels = deploymentSpec.Label
deployment.Spec = deploymentSpec.Spec

deployments = append(deployments, *deployment)
}
}

odfCsv.Annotations["operators.operatorframework.io/internal-objects"] = "[\"" + strings.Join(apis, "\",\"") + "\"]"

writeObjectToFile(deployments, deploymentsOutputFile)
writeObjectToFile(odfCsv, odfCsvOutputFile)
}

// unmarshalCSV reads the csv yaml from a given filePath and return a CSV structure
func unmarshalCSV(filePath string) *operatorsv1alpha1.ClusterServiceVersion {

fmt.Printf("Reading file %s\n", filePath)
bytes, err := os.ReadFile(filePath)
if err != nil {
panic(err)
}

csv := &operatorsv1alpha1.ClusterServiceVersion{}
err = yaml.Unmarshal(bytes, csv)
if err != nil {
panic(err)
}

return csv
}

// writeObjectToFile writes a k8s object to the given filePath into yaml format
func writeObjectToFile(object interface{}, filePath string) {

bytes, err := yaml.Marshal(object)
if err != nil {
panic(err)
}

fmt.Printf("Writing file %s\n", filePath)
err = os.WriteFile(filePath, bytes, 0644)
if err != nil {
panic(err)
}
}
85 changes: 44 additions & 41 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,73 +1,76 @@
module github.com/red-hat-storage/odf-operator

go 1.21
go 1.22.0

require (
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
k8s.io/apimachinery v0.29.2
k8s.io/client-go v0.29.2
sigs.k8s.io/controller-runtime v0.17.3
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/operator-framework/api v0.27.0
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
k8s.io/client-go v0.31.0
sigs.k8s.io/controller-runtime v0.19.0
sigs.k8s.io/yaml v1.4.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.2 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/swag v0.22.9 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.16.1 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.2 // indirect
k8s.io/apiextensions-apiserver v0.29.2 // indirect
k8s.io/component-base v0.29.2 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
k8s.io/apiextensions-apiserver v0.31.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit 698318f

Please sign in to comment.