Skip to content

Commit

Permalink
csv-merger: merge relatedImages
Browse files Browse the repository at this point in the history
Also drops the extendedCsv struct as it is no longer needed
  • Loading branch information
dprince committed Sep 26, 2023
1 parent 8e8e57c commit 8d4750d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 134 deletions.
54 changes: 18 additions & 36 deletions cmd/csv-merger/csv-merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,8 @@ import (
csvv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// TODO: get rid of this if/when RelatedImages officially appears in github.com/operator-framework/api/pkg/operators/v1alpha1/
type relatedImage struct {
Name string `json:"name"`
Ref string `json:"image"`
}

type clusterServiceVersionSpecExtended struct {
csvv1alpha1.ClusterServiceVersionSpec
RelatedImages []relatedImage `json:"relatedImages,omitempty"`
}

type clusterServiceVersionExtended struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`

Spec clusterServiceVersionSpecExtended `json:"spec"`
Status csvv1alpha1.ClusterServiceVersionStatus `json:"status"`
}

func getEnvsFromFile(filename string) []v1.EnvVar {
csvBytes, err := os.ReadFile(filename)
if err != nil {
Expand Down Expand Up @@ -166,13 +146,14 @@ func main() {

// BaseCSV is built on the bundle/manifests/openstack-operator.clusterserviceversion.yaml from this repo
csvBase := getCSVBase(*baseCsv)
csvExtended := clusterServiceVersionExtended{
csvNew := csvv1alpha1.ClusterServiceVersion{
TypeMeta: csvBase.TypeMeta,
ObjectMeta: csvBase.ObjectMeta,
Spec: clusterServiceVersionSpecExtended{ClusterServiceVersionSpec: csvBase.Spec},
Spec: csvBase.Spec,
Status: csvBase.Status}

installStrategyBase := csvBase.Spec.InstallStrategy.StrategySpec
csvNew.Spec.RelatedImages = csvBase.Spec.RelatedImages

envVarList := []v1.EnvVar{}
if len(*importEnvFiles) > 0 {
Expand Down Expand Up @@ -206,10 +187,11 @@ func main() {
installStrategyBase.DeploymentSpecs = append(installStrategyBase.DeploymentSpecs, csvStruct.Spec.InstallStrategy.StrategySpec.DeploymentSpecs...)
installStrategyBase.ClusterPermissions = append(installStrategyBase.ClusterPermissions, csvStruct.Spec.InstallStrategy.StrategySpec.ClusterPermissions...)
installStrategyBase.Permissions = append(installStrategyBase.Permissions, csvStruct.Spec.InstallStrategy.StrategySpec.Permissions...)
csvNew.Spec.RelatedImages = append(csvNew.Spec.RelatedImages, csvStruct.Spec.RelatedImages...)

for _, owned := range csvStruct.Spec.CustomResourceDefinitions.Owned {
csvExtended.Spec.CustomResourceDefinitions.Owned = append(
csvExtended.Spec.CustomResourceDefinitions.Owned,
csvNew.Spec.CustomResourceDefinitions.Owned = append(
csvNew.Spec.CustomResourceDefinitions.Owned,
csvv1alpha1.CRDDescription{
Name: owned.Name,
Version: owned.Version,
Expand All @@ -221,7 +203,7 @@ func main() {
}

if *almExamples {
csvBaseAlmString := csvExtended.Annotations["alm-examples"]
csvBaseAlmString := csvNew.Annotations["alm-examples"]
csvStructAlmString := csvStruct.Annotations["alm-examples"]
var baseAlmCrs []interface{}
var structAlmCrs []interface{}
Expand All @@ -237,9 +219,9 @@ func main() {
if err != nil {
exitWithError(err.Error())
}
csvExtended.Annotations["alm-examples"] = string(almB)
csvNew.Annotations["alm-examples"] = string(almB)
}
csvExtended.Spec.WebhookDefinitions = append(csvExtended.Spec.WebhookDefinitions, csvStruct.Spec.WebhookDefinitions...)
csvNew.Spec.WebhookDefinitions = append(csvNew.Spec.WebhookDefinitions, csvStruct.Spec.WebhookDefinitions...)
}

}
Expand All @@ -257,7 +239,7 @@ func main() {
// by default we hide all CRDs in the Console
hiddenCrds := []string{}
visibleCrds := strings.Split(*visibleCRDList, ",")
for _, owned := range csvExtended.Spec.CustomResourceDefinitions.Owned {
for _, owned := range csvNew.Spec.CustomResourceDefinitions.Owned {
found := false
for _, name := range visibleCrds {
if owned.Name == name {
Expand All @@ -275,39 +257,39 @@ func main() {
if err != nil {
exitWithError(err.Error())
}
csvExtended.Annotations["operators.operatorframework.io/internal-objects"] = string(hiddenCrdsJ)
csvNew.Annotations["operators.operatorframework.io/internal-objects"] = string(hiddenCrdsJ)

csvExtended.Spec.InstallStrategy.StrategyName = "deployment"
csvExtended.Spec.InstallStrategy = csvv1alpha1.NamedInstallStrategy{
csvNew.Spec.InstallStrategy.StrategyName = "deployment"
csvNew.Spec.InstallStrategy = csvv1alpha1.NamedInstallStrategy{
StrategyName: "deployment",
StrategySpec: installStrategyBase,
}

if csvVersion != "" {
csvExtended.Spec.Version = version.OperatorVersion{
csvNew.Spec.Version = version.OperatorVersion{
Version: semver.MustParse(csvVersion),
}
csvExtended.Name = strings.Replace(csvExtended.Name, "0.0.1", csvVersion, 1)
csvNew.Name = strings.Replace(csvNew.Name, "0.0.1", csvVersion, 1)
}

if *csvOverrides != "" {
csvOBytes := []byte(*csvOverrides)

csvO := &clusterServiceVersionExtended{}
csvO := &csvv1alpha1.ClusterServiceVersion{}

err := yaml.Unmarshal(csvOBytes, csvO)
if err != nil {
exitWithError(err.Error())
}

err = mergo.Merge(&csvExtended, csvO, mergo.WithOverride)
err = mergo.Merge(&csvNew, csvO, mergo.WithOverride)
if err != nil {
exitWithError(err.Error())
}

}

err = util.MarshallObject(csvExtended, os.Stdout)
err = util.MarshallObject(csvNew, os.Stdout)
if err != nil {
exitWithError(err.Error())
}
Expand Down
146 changes: 51 additions & 95 deletions config/manifests/bases/openstack-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,15 @@ spec:
- description: Cinder - Parameters related to the Cinder service
displayName: Cinder
path: cinder
- description: APIOverride, provides the ability to override the generated manifest
of several child resources.
displayName: APIOverride
path: cinder.apiOverride
- description: Enabled - Whether Cinder service should be deployed and managed
displayName: Enabled
path: cinder.enabled
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: IPAddressPool expose VIP via MetalLB on the IPAddressPool
displayName: IPAddress Pool
path: cinder.externalEndpoints[0].ipAddressPool
- description: LoadBalancerIPs, request given IPs from the pool if available.
Using a list to allow dual stack (IPv4/IPv6) support
displayName: Load Balancer IPs
path: cinder.externalEndpoints[0].loadBalancerIPs
- description: SharedIP if true, VIP/VIPs get shared with multiple services
displayName: Shared IP
path: cinder.externalEndpoints[0].sharedIP
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: SharedIPKey specifies the sharing key which gets set as the annotation
on the LoadBalancer service. Services which share the same VIP must have
the same SharedIPKey. Defaults to the IPAddressPool if SharedIP is true,
but no SharedIPKey specified.
displayName: Shared IPKey
path: cinder.externalEndpoints[0].sharedIPKey
- description: Template - Overrides to use when creating Cinder Resources
displayName: Template
path: cinder.template
Expand Down Expand Up @@ -95,35 +81,29 @@ spec:
- description: Glance - Parameters related to the Glance service
displayName: Glance
path: glance
- description: APIOverride, provides the ability to override the generated manifest
of several child resources.
displayName: APIOverride
path: glance.apiOverride
- description: Enabled - Whether Glance service should be deployed and managed
displayName: Enabled
path: glance.enabled
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: IPAddressPool expose VIP via MetalLB on the IPAddressPool
displayName: IPAddress Pool
path: glance.externalEndpoints[0].ipAddressPool
- description: LoadBalancerIPs, request given IPs from the pool if available.
Using a list to allow dual stack (IPv4/IPv6) support
displayName: Load Balancer IPs
path: glance.externalEndpoints[0].loadBalancerIPs
- description: SharedIP if true, VIP/VIPs get shared with multiple services
displayName: Shared IP
path: glance.externalEndpoints[0].sharedIP
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: SharedIPKey specifies the sharing key which gets set as the annotation
on the LoadBalancer service. Services which share the same VIP must have
the same SharedIPKey. Defaults to the IPAddressPool if SharedIP is true,
but no SharedIPKey specified.
displayName: Shared IPKey
path: glance.externalEndpoints[0].sharedIPKey
- description: Template - Overrides to use when creating the Glance Service
displayName: Template
path: glance.template
- description: Heat - Parameters related to the Heat services
displayName: Heat
path: heat
- description: APIOverride, provides the ability to override the generated manifest
of several child resources.
displayName: APIOverride
path: heat.apiOverride
- description: CnfAPIOverride, provides the ability to override the generated
manifest of several child resources.
displayName: Cnf APIOverride
path: heat.cnfAPIOverride
- description: Enabled - Whether Heat services should be deployed and managed
displayName: Enabled
path: heat.enabled
Expand All @@ -135,6 +115,10 @@ spec:
- description: Horizon - Parameters related to the Horizon services
displayName: Horizon
path: horizon
- description: APIOverride, provides the ability to override the generated manifest
of several child resources.
displayName: APIOverride
path: horizon.apiOverride
- description: Ironic - Parameters related to the Ironic services
displayName: Ironic
path: ironic
Expand All @@ -149,32 +133,22 @@ spec:
- description: Keystone - Parameters related to the Keystone service
displayName: Keystone
path: keystone
- description: APIOverride, provides the ability to override the generated manifest
of several child resources.
displayName: APIOverride
path: keystone.apiOverride
- description: Enabled - Whether Keystone service should be deployed and managed
displayName: Enabled
path: keystone.enabled
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: IPAddressPool expose VIP via MetalLB on the IPAddressPool
displayName: IPAddress Pool
path: keystone.externalEndpoints[0].ipAddressPool
- description: LoadBalancerIPs, request given IPs from the pool if available.
Using a list to allow dual stack (IPv4/IPv6) support
displayName: Load Balancer IPs
path: keystone.externalEndpoints[0].loadBalancerIPs
- description: SharedIP if true, VIP/VIPs get shared with multiple services
displayName: Shared IP
path: keystone.externalEndpoints[0].sharedIP
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: SharedIPKey specifies the sharing key which gets set as the annotation
on the LoadBalancer service. Services which share the same VIP must have
the same SharedIPKey. Defaults to the IPAddressPool if SharedIP is true,
but no SharedIPKey specified.
displayName: Shared IPKey
path: keystone.externalEndpoints[0].sharedIPKey
- description: Template - Overrides to use when creating the Keystone service
displayName: Template
path: keystone.template
- description: APIOverride, provides the ability to override the generated manifest
of several child resources.
displayName: APIOverride
path: manila.apiOverride
- description: Enabled - Whether Manila service should be deployed and managed
displayName: Enabled
path: manila.enabled
Expand Down Expand Up @@ -205,12 +179,16 @@ spec:
- description: Neutron - Overrides to use when creating the Neutron Service
displayName: Neutron
path: neutron
- description: APIOverride, provides the ability to override the generated manifest
of several child resources.
displayName: APIOverride
path: neutron.apiOverride
- description: Enabled - Whether Neutron service should be deployed and managed
displayName: Enabled
path: neutron.enabled
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: Template - Overrides to use when creating the Neutron service
- description: Template - Overrides to use when creating the Neutron Service
displayName: Template
path: neutron.template
- description: NodeSelector to target subset of worker nodes running control
Expand All @@ -220,6 +198,16 @@ spec:
- description: Nova - Parameters related to the Nova services
displayName: Nova
path: nova
- description: APIOverride, provides the ability to override the generated manifest
of several child resources.
displayName: APIOverride
path: nova.apiOverride
- description: CellOverride, provides the ability to override the generated
manifest of several child resources for a nova cell. cell0 never have compute
nodes and therefore it won't have a noVNCProxy deployed. Providing an override
for cell0 noVNCProxy does not have an effect.
displayName: Cell Override
path: nova.cellOverride
- description: Enabled - Whether Nova services should be deployed and managed
displayName: Enabled
path: nova.enabled
Expand Down Expand Up @@ -262,29 +250,15 @@ spec:
- description: Placement - Parameters related to the Placement service
displayName: Placement
path: placement
- description: APIOverride, provides the ability to override the generated manifest
of several child resources.
displayName: APIOverride
path: placement.apiOverride
- description: Enabled - Whether Placement service should be deployed and managed
displayName: Enabled
path: placement.enabled
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: IPAddressPool expose VIP via MetalLB on the IPAddressPool
displayName: IPAddress Pool
path: placement.externalEndpoints[0].ipAddressPool
- description: LoadBalancerIPs, request given IPs from the pool if available.
Using a list to allow dual stack (IPv4/IPv6) support
displayName: Load Balancer IPs
path: placement.externalEndpoints[0].loadBalancerIPs
- description: SharedIP if true, VIP/VIPs get shared with multiple services
displayName: Shared IP
path: placement.externalEndpoints[0].sharedIP
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: SharedIPKey specifies the sharing key which gets set as the annotation
on the LoadBalancer service. Services which share the same VIP must have
the same SharedIPKey. Defaults to the IPAddressPool if SharedIP is true,
but no SharedIPKey specified.
displayName: Shared IPKey
path: placement.externalEndpoints[0].sharedIPKey
- description: Template - Overrides to use when creating the Placement API
displayName: Template
path: placement.template
Expand All @@ -299,28 +273,6 @@ spec:
- description: Templates - Overrides to use when creating the Rabbitmq clusters
displayName: Templates
path: rabbitmq.templates
- description: ExternalEndpoint, expose a VIP via MetalLB on the pre-created
address pool
displayName: External Endpoint
path: rabbitmq.templates.externalEndpoint
- description: IPAddressPool expose VIP via MetalLB on the IPAddressPool
displayName: IPAddress Pool
path: rabbitmq.templates.externalEndpoint.ipAddressPool
- description: LoadBalancerIPs, request given IPs from the pool if available.
Using a list to allow dual stack (IPv4/IPv6) support
displayName: Load Balancer IPs
path: rabbitmq.templates.externalEndpoint.loadBalancerIPs
- description: SharedIP if true, VIP/VIPs get shared with multiple services
displayName: Shared IP
path: rabbitmq.templates.externalEndpoint.sharedIP
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: SharedIPKey specifies the sharing key which gets set as the annotation
on the LoadBalancer service. Services which share the same VIP must have
the same SharedIPKey. Defaults to the IPAddressPool if SharedIP is true,
but no SharedIPKey specified.
displayName: Shared IPKey
path: rabbitmq.templates.externalEndpoint.sharedIPKey
- description: Enabled - Whether the Redis service should be deployed and managed
displayName: Enabled
path: redis.enabled
Expand All @@ -344,6 +296,10 @@ spec:
path: swift.enabled
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: ProxyOverride, provides the ability to override the generated
manifest of several child resources.
displayName: Proxy Override
path: swift.proxyOverride
- description: Template - Overrides to use when creating Swift Resources
displayName: Template
path: swift.template
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/openstack-k8s-operators/placement-operator/api v0.1.1-0.20230920125340-3c99d09c7033
github.com/openstack-k8s-operators/swift-operator/api v0.1.1-0.20230920144258-a37c476a2829
github.com/openstack-k8s-operators/telemetry-operator/api v0.1.1-0.20230922102555-fe2794ad1e8c
github.com/operator-framework/api v0.17.3
github.com/operator-framework/api v0.17.6
github.com/rabbitmq/cluster-operator v1.14.0
go.uber.org/zap v1.26.0
k8s.io/api v0.26.9
Expand Down
Loading

0 comments on commit 8d4750d

Please sign in to comment.