Skip to content

Commit

Permalink
OCPBUGS-14922: skip console-plugin installation if console CO is absent
Browse files Browse the repository at this point in the history
This PR fixes the failure to upgrade from OpenShift version 4.13 to
4.14 in environments (such as telco) where `console` ClusterOperator is
disabled. The upgrade fails happens when CMO executes the
console-plugin task which fails due to missing ConsolePlugin.

The fix checks for the presence of `console` ClusterOperator and bails
out (with a log message) if it is absent.

Signed-off-by: Sunil Thaha <sthaha@redhat.com>
  • Loading branch information
sthaha committed Jun 27, 2023
1 parent 70dd5c9 commit 8f03f88
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,25 @@ func (c *Client) ConsoleListWatch(ctx context.Context) *cache.ListWatch {
}
}

func (c *Client) ClusterVersionListWatch(ctx context.Context, name string) *cache.ListWatch {
clusterVersionInterface := c.oscclient.ConfigV1().ClusterVersions()

return &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return clusterVersionInterface.List(ctx,
metav1.ListOptions{
FieldSelector: fields.OneTermEqualSelector("metadata.name", name).String(),
})
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
return clusterVersionInterface.Watch(ctx,
metav1.ListOptions{
FieldSelector: fields.OneTermEqualSelector("metadata.name", name).String(),
})
},
}
}

func (c *Client) ClusterOperatorListWatch(ctx context.Context, name string) *cache.ListWatch {
ClusterOperatorInterface := c.oscclient.ConfigV1().ClusterOperators()

Expand Down Expand Up @@ -1862,6 +1881,19 @@ func (c *Client) PodCapacity(ctx context.Context) (int, error) {
return int(podCapacityTotal), nil
}

func (c *Client) HasClusterCapability(ctx context.Context, capability configv1.ClusterVersionCapability) (bool, error) {
version, err := c.oscclient.ConfigV1().ClusterVersions().Get(ctx, "version", metav1.GetOptions{})
if err != nil {
return false, err
}

return slices.Contains(version.Status.Capabilities.EnabledCapabilities, capability), nil
}

func (c *Client) HasConsoleCapability(ctx context.Context) (bool, error) {
return c.HasClusterCapability(ctx, configv1.ClusterVersionCapabilityConsole)
}

func (c *Client) CreateOrUpdateConsolePlugin(ctx context.Context, plg *consolev1.ConsolePlugin) error {
conClient := c.osconclient.ConsoleV1().ConsolePlugins()
existing, err := conClient.Get(ctx, plg.GetName(), metav1.GetOptions{})
Expand Down
14 changes: 14 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,20 @@ func New(
}
o.informers = append(o.informers, informer)

// Many of the cluster capabilities such as Console can be enabled after
// installation. So this watches for any updates to the ClusterVersion - version
informer = cache.NewSharedIndexInformer(
o.client.ClusterVersionListWatch(ctx, "version"),
&configv1.ClusterVersion{}, resyncPeriod, cache.Indexers{},
)
_, err = informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
UpdateFunc: func(_, newObj interface{}) { o.handleEvent(newObj) },
})
if err != nil {
return nil, err
}
o.informers = append(o.informers, informer)

// Setup PVC informers to sync annotation updates.
for _, ns := range []string{o.namespace, o.namespaceUserWorkload} {
informer = cache.NewSharedIndexInformer(
Expand Down
14 changes: 14 additions & 0 deletions pkg/tasks/monitoring_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/openshift/cluster-monitoring-operator/pkg/client"
"github.com/openshift/cluster-monitoring-operator/pkg/manifests"
"github.com/pkg/errors"
"k8s.io/klog/v2"
)

type MonitoringPluginTask struct {
Expand All @@ -37,6 +38,19 @@ func NewMonitoringPluginTask(client *client.Client, factory *manifests.Factory,
}

func (t *MonitoringPluginTask) Run(ctx context.Context) error {
// ensure console is enabled and bail out if it isn't
{
enabled, err := t.client.HasConsoleCapability(ctx)
if err != nil {
return errors.Wrap(err, "failed to determine if console capability is enabled")
}

if !enabled {
klog.V(4).Infof("Skipping installation of Console Plugin as console capability is disabled")
return nil
}
}

{ // plugin
plg, err := t.factory.MonitoringPlugin()
if err != nil {
Expand Down

0 comments on commit 8f03f88

Please sign in to comment.