Skip to content

Commit

Permalink
feat(operator): provide OLM NodeSelector
Browse files Browse the repository at this point in the history
Adding a flag to allow defining any NodeSelector during OLM installation procedure
  • Loading branch information
squakez authored and astefanutti committed Apr 12, 2021
1 parent 654e039 commit dd2ca05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 16 additions & 1 deletion pkg/util/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit dd2ca05

Please sign in to comment.