Skip to content

Commit

Permalink
Patching ConsolePlugin CR with Prometheus service info
Browse files Browse the repository at this point in the history
Signed-off-by: Arun Kumar Mohan <[email protected]>
  • Loading branch information
aruniiird committed May 13, 2022
1 parent a5ada2c commit 8dae6ad
Show file tree
Hide file tree
Showing 10 changed files with 645 additions and 0 deletions.
50 changes: 50 additions & 0 deletions controllers/managedocs_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io/ioutil"
"math"
"net/url"
"reflect"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -50,6 +51,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/go-logr/logr"
consolev1alpha1 "github.com/openshift/api/console/v1alpha1"
openshiftv1 "github.com/openshift/api/network/v1"
promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
promv1a1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
Expand Down Expand Up @@ -105,6 +107,7 @@ const (
convergedDeploymentType = "converged"
consumerDeploymentType = "consumer"
providerDeploymentType = "provider"
ocpConsolePluginName = "odf-console"
)

// ManagedOCSReconciler reconciles a ManagedOCS object
Expand Down Expand Up @@ -149,6 +152,7 @@ type ManagedOCSReconciler struct {
addonParams map[string]string
onboardingValidationKeySecret *corev1.Secret
prometheusKubeRBACConfigMap *corev1.ConfigMap
ocpConsolePlugin *consolev1alpha1.ConsolePlugin
}

// Add necessary rbac permissions for managedocs finalizer in order to set blockOwnerDeletion.
Expand Down Expand Up @@ -435,6 +439,9 @@ func (r *ManagedOCSReconciler) initReconciler(ctx context.Context, req ctrl.Requ
r.prometheusKubeRBACConfigMap.Name = templates.PrometheusKubeRBACPoxyConfigMapName
r.prometheusKubeRBACConfigMap.Namespace = r.namespace

r.ocpConsolePlugin = &consolev1alpha1.ConsolePlugin{}
r.ocpConsolePlugin.Name = ocpConsolePluginName
r.ocpConsolePlugin.Namespace = r.namespace
}

func (r *ManagedOCSReconciler) reconcilePhases() (reconcile.Result, error) {
Expand Down Expand Up @@ -570,6 +577,9 @@ func (r *ManagedOCSReconciler) reconcilePhases() (reconcile.Result, error) {
if err := r.reconcileProviderAPIServerNetworkPolicy(); err != nil {
return ctrl.Result{}, err
}
if err := r.reconcileConsolePlugin(); err != nil {
return ctrl.Result{}, err
}

r.managedOCS.Status.ReconcileStrategy = r.reconcileStrategy

Expand Down Expand Up @@ -1752,6 +1762,46 @@ func (r *ManagedOCSReconciler) updateMCGCSV(csv *opv1a1.ClusterServiceVersion) e
return nil
}

func (r *ManagedOCSReconciler) reconcileConsolePlugin() error {
r.Log.Info("Reconciling ConsolePlugin")
if err := r.get(r.ocpConsolePlugin); err != nil && !errors.IsNotFound(err) {
return err
}
if r.ocpConsolePlugin.UID == "" {
// ODF Operator has to bring this CR,
// so if OCP ConsolePlugin is not ready, we ruturn silently
return nil
}
expectedProxy := templates.ConsolePluginProxyTemplate.DeepCopy()
expectedProxy.Service.Name = prometheusServiceName
expectedProxy.Service.Namespace = r.namespace

var matchingProxy *consolev1alpha1.ConsolePluginProxy
for i := range r.ocpConsolePlugin.Spec.Proxy {
currProxy := &r.ocpConsolePlugin.Spec.Proxy[i]
if currProxy.Service.Name == expectedProxy.Service.Name &&
currProxy.Service.Namespace == expectedProxy.Service.Namespace {
// if both, expected and current, are same then return happily
if reflect.DeepEqual(*currProxy, *expectedProxy) {
return nil
}
matchingProxy = currProxy
break
}
}
// if we didn't find any matching ConsolePluginProxy, append the expected proxy
if matchingProxy == nil {
r.ocpConsolePlugin.Spec.Proxy = append(r.ocpConsolePlugin.Spec.Proxy, *expectedProxy)
} else { // else update with the expected proxy
expectedProxy.DeepCopyInto(matchingProxy)
}
// since the proxy array is changed at this point, update the console plugin
if err := r.update(r.ocpConsolePlugin); err != nil {
return fmt.Errorf("could not update OCP ConsolePlugin: %v", err)
}
return nil
}

func (r *ManagedOCSReconciler) removeOLMComponents() error {

r.Log.Info("deleting deployer csv")
Expand Down
30 changes: 30 additions & 0 deletions templates/consolePlugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package templates

import (
consolev1alpha1 "github.com/openshift/api/console/v1alpha1"
)

const (
ocpConsoleProxyAlias = "consoleproxy"
)

var ConsolePluginProxyTemplate = consolev1alpha1.ConsolePluginProxy{
Type: consolev1alpha1.ProxyTypeService,
Authorize: true,
Alias: ocpConsoleProxyAlias,
Service: consolev1alpha1.ConsolePluginProxyServiceConfig{
Port: int32(KubeRBACProxyPortNumber),
},
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8dae6ad

Please sign in to comment.