From dd2ca05e181612ebbf5ecad67a1a3f15d5120733 Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Fri, 26 Mar 2021 12:51:50 +0100 Subject: [PATCH] feat(operator): provide OLM NodeSelector Adding a flag to allow defining any NodeSelector during OLM installation procedure --- pkg/cmd/install.go | 2 +- pkg/util/olm/operator.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go index e3ec076ae8..1692c15e96 100644 --- a/pkg/cmd/install.go +++ b/pkg/cmd/install.go @@ -223,7 +223,7 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error { if installViaOLM { fmt.Fprintln(cobraCmd.OutOrStdout(), "OLM is available in the cluster") var installed bool - if installed, err = olm.Install(o.Context, olmClient, o.Namespace, o.Global, o.olmOptions, collection, o.Tolerations); err != nil { + if installed, err = olm.Install(o.Context, olmClient, o.Namespace, o.Global, o.olmOptions, collection, o.Tolerations, o.NodeSelectors); err != nil { return err } if !installed { diff --git a/pkg/util/olm/operator.go b/pkg/util/olm/operator.go index 896b241943..74970d03f5 100644 --- a/pkg/util/olm/operator.go +++ b/pkg/util/olm/operator.go @@ -138,7 +138,7 @@ func HasPermissionToInstall(ctx context.Context, client client.Client, namespace } // Install creates a subscription for the OLM package -func Install(ctx context.Context, client client.Client, namespace string, global bool, options Options, collection *kubernetes.Collection, tolerations []string) (bool, error) { +func Install(ctx context.Context, client client.Client, namespace string, global bool, options Options, collection *kubernetes.Collection, tolerations []string, nodeSelectors []string) (bool, error) { options = fillDefaults(options) if installed, err := IsOperatorInstalled(ctx, client, namespace, global, options); err != nil { return false, err @@ -171,6 +171,10 @@ func Install(ctx context.Context, client client.Client, namespace string, global if err != nil { return false, errors.Wrap(err, fmt.Sprintf("could not set tolerations")) } + err = maybeSetNodeSelectors(&sub, nodeSelectors) + if err != nil { + return false, errors.Wrap(err, fmt.Sprintf("could not set node selectors")) + } if collection != nil { collection.Add(&sub) @@ -216,6 +220,17 @@ func maybeSetTolerations(sub *operatorsv1alpha1.Subscription, tolArray []string) return nil } +func maybeSetNodeSelectors(sub *operatorsv1alpha1.Subscription, nsArray []string) error { + if nsArray != nil { + nodeSelectors, err := kubernetes.GetNodeSelectors(nsArray) + if err != nil { + return err + } + sub.Spec.Config.NodeSelector = nodeSelectors + } + return nil +} + // Uninstall removes CSV and subscription from the namespace func Uninstall(ctx context.Context, client client.Client, namespace string, global bool, options Options) error { sub, err := findSubscription(ctx, client, namespace, global, options)