Skip to content

Commit

Permalink
Use tables to drive CRD setup
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Kitt <skitt@redhat.com>
  • Loading branch information
skitt authored and tpantelis committed May 10, 2024
1 parent f4372ec commit 35028e2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 48 deletions.
49 changes: 15 additions & 34 deletions pkg/gateway/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,21 @@ import (
// Ensure ensures that the required resources are deployed on the target system.
// The resources handled here are the gateway CRDs: Cluster and Endpoint.
func Ensure(ctx context.Context, crdUpdater crd.Updater) error {
_, err := crdUpdater.CreateOrUpdateFromEmbedded(ctx,
embeddedyamls.Deploy_submariner_crds_submariner_io_clusters_yaml)
if err != nil && !apierrors.IsAlreadyExists(err) {
return errors.Wrap(err, "error provisioning the Cluster CRD")
}

_, err = crdUpdater.CreateOrUpdateFromEmbedded(ctx,
embeddedyamls.Deploy_submariner_crds_submariner_io_endpoints_yaml)
if err != nil && !apierrors.IsAlreadyExists(err) {
return errors.Wrap(err, "error provisioning the Endpoint CRD")
}

_, err = crdUpdater.CreateOrUpdateFromEmbedded(ctx,
embeddedyamls.Deploy_submariner_crds_submariner_io_gateways_yaml)
if err != nil && !apierrors.IsAlreadyExists(err) {
return errors.Wrap(err, "error provisioning the Gateway CRD")
}

_, err = crdUpdater.CreateOrUpdateFromEmbedded(ctx,
embeddedyamls.Deploy_submariner_crds_submariner_io_clusterglobalegressips_yaml)
if err != nil && !apierrors.IsAlreadyExists(err) {
return errors.Wrap(err, "error provisioning the ClusterGlobalEgressIP CRD")
}

_, err = crdUpdater.CreateOrUpdateFromEmbedded(ctx,
embeddedyamls.Deploy_submariner_crds_submariner_io_globalegressips_yaml)
if err != nil && !apierrors.IsAlreadyExists(err) {
return errors.Wrap(err, "error provisioning the GlobalEgressIP CRD")
}

_, err = crdUpdater.CreateOrUpdateFromEmbedded(ctx,
embeddedyamls.Deploy_submariner_crds_submariner_io_globalingressips_yaml)
if err != nil && !apierrors.IsAlreadyExists(err) {
return errors.Wrap(err, "error provisioning the GlobalIngressIP CRD")
for _, ref := range []struct {
name string
crd string
}{
{embeddedyamls.Deploy_submariner_crds_submariner_io_clusters_yaml, "Cluster"},
{embeddedyamls.Deploy_submariner_crds_submariner_io_endpoints_yaml, "Endpoint"},
{embeddedyamls.Deploy_submariner_crds_submariner_io_gateways_yaml, "Gateway"},
{embeddedyamls.Deploy_submariner_crds_submariner_io_clusterglobalegressips_yaml, "ClusterGlobalEgressIP"},
{embeddedyamls.Deploy_submariner_crds_submariner_io_globalegressips_yaml, "GlobalEgressIP"},
{embeddedyamls.Deploy_submariner_crds_submariner_io_globalingressips_yaml, "GlobalIngressIP"},
} {
_, err := crdUpdater.CreateOrUpdateFromEmbedded(ctx, ref.name)
if err != nil && !apierrors.IsAlreadyExists(err) {
return errors.Wrapf(err, "error provisioning the %s CRD", ref.crd)
}
}

return nil
Expand Down
31 changes: 17 additions & 14 deletions pkg/operator/crds/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@ func Ensure(ctx context.Context, crdUpdater crd.Updater) (bool, error) {
// Attempt to update or create the CRD definitions.
// TODO(majopela): In the future we may want to report when we have updated the existing
// CRD definition with new versions
submarinerCreated, err := crdUpdater.CreateOrUpdateFromEmbedded(ctx,
embeddedyamls.Deploy_crds_submariner_io_submariners_yaml)
if err != nil {
return false, errors.Wrap(err, "error provisioning Submariner CRD")
created := false

for _, ref := range []struct {
name string
crd string
}{
{embeddedyamls.Deploy_crds_submariner_io_submariners_yaml, "Submariner"},
{embeddedyamls.Deploy_crds_submariner_io_servicediscoveries_yaml, "ServiceDiscovery"},
{embeddedyamls.Deploy_crds_submariner_io_brokers_yaml, "Broker"},
} {
iterCreated, err := crdUpdater.CreateOrUpdateFromEmbedded(ctx, ref.name)
if err != nil {
return false, errors.Wrapf(err, "error provisioning the %s CRD", ref.crd)
}

created = created || iterCreated
}

serviceDiscoveryCreated, err := crdUpdater.CreateOrUpdateFromEmbedded(ctx,
embeddedyamls.Deploy_crds_submariner_io_servicediscoveries_yaml)
if err != nil {
return false, errors.Wrap(err, "error provisioning ServiceDiscovery CRD")
}

brokerCreated, err := crdUpdater.CreateOrUpdateFromEmbedded(ctx,
embeddedyamls.Deploy_crds_submariner_io_brokers_yaml)

return submarinerCreated || serviceDiscoveryCreated || brokerCreated, errors.Wrap(err, "error provisioning Broker CRD")
return created, nil
}

0 comments on commit 35028e2

Please sign in to comment.