Skip to content

Commit

Permalink
remove webConsolePlugin from ToolchainClusterConfig
Browse files Browse the repository at this point in the history
Pendo has been decommisioned, we don't need this plugin anymore

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Jul 26, 2024
1 parent 5caa2b0 commit c0a23a3
Show file tree
Hide file tree
Showing 15 changed files with 12 additions and 731 deletions.
34 changes: 1 addition & 33 deletions cmd/consoleplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@ import (
"time"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/member-operator/pkg/consoleplugin"
"github.com/codeready-toolchain/member-operator/pkg/klog"
membercfg "github.com/codeready-toolchain/toolchain-common/pkg/configuration/memberoperatorconfig"

"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
klogv1 "k8s.io/klog"
klogv2 "k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

Expand Down Expand Up @@ -79,11 +75,6 @@ func main() {
setupLog.Info("Configuring web console plugin server ...")

runtimeScheme := runtime.NewScheme()
cfg, err := config.GetConfig()
if err != nil {
setupLog.Error(err, "getting config failed")
os.Exit(1)
}

if err := toolchainv1alpha1.AddToScheme(runtimeScheme); err != nil {
setupLog.Error(err, "adding toolchain api to scheme failed")
Expand All @@ -94,30 +85,7 @@ func main() {
os.Exit(1)
}

cl, err := client.New(cfg, client.Options{
Scheme: runtimeScheme,
})
if err != nil {
setupLog.Error(err, "creating a new client failed")
os.Exit(1)
}

config, err := membercfg.GetConfiguration(cl)
if err != nil {
setupLog.Error(err, "Error retrieving Configuration")
os.Exit(1)
}

pluginServer := startConsolePluginService(config.WebConsolePlugin())

gracefulShutdown(gracefulTimeout, pluginServer)
}

func startConsolePluginService(config membercfg.WebConsolePluginConfig) *consoleplugin.Server {
consolePluginServer := consoleplugin.NewConsolePluginServer(config, setupLog)
consolePluginServer.Start()

return consolePluginServer
gracefulShutdown(gracefulTimeout)
}

func gracefulShutdown(timeout time.Duration, hs ...shutdown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,6 @@ spec:
description: Defines the timeout for each health check
type: string
type: object
webConsolePlugin:
description: WebConsolePlugin is used to configure the Web Console
Plugin parameters
properties:
deploy:
description: Deploy determines whether the plugin will be deployed
or not
type: boolean
pendoHost:
description: PendoHost allows a host URL to be configured instead
of communicating directly with the Pendo domain
type: string
pendoKey:
description: PendoKey is the key value used to interact with the
Pendo API
type: string
type: object
webhook:
description: Keeps parameters concerned with the webhook
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"

"github.com/codeready-toolchain/member-operator/pkg/autoscaler"
consoledeploy "github.com/codeready-toolchain/member-operator/pkg/consoleplugin/deploy"
"github.com/codeready-toolchain/member-operator/pkg/webhook/deploy"
"github.com/go-logr/logr"
"sigs.k8s.io/controller-runtime/pkg/builder"
Expand Down Expand Up @@ -65,10 +64,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
return reconcile.Result{}, err
}

if err := r.handleWebConsolePluginDeploy(ctx, crtConfig, request.Namespace); err != nil {
return reconcile.Result{}, err
}

return reconcile.Result{}, nil
}

Expand Down Expand Up @@ -116,19 +111,3 @@ func (r *Reconciler) handleWebhookDeploy(ctx context.Context, cfg membercfg.Conf
}
return nil
}

func (r *Reconciler) handleWebConsolePluginDeploy(ctx context.Context, cfg membercfg.Configuration, namespace string) error {
logger := log.FromContext(ctx)

if cfg.WebConsolePlugin().Deploy() {
webconsolepluginImage := os.Getenv("MEMBER_OPERATOR_WEBCONSOLEPLUGIN_IMAGE")
logger.Info("(Re)Deploying web console plugin")
if err := consoledeploy.ConsolePlugin(ctx, r.Client, r.Client.Scheme(), namespace, webconsolepluginImage); err != nil {
return err
}
logger.Info("(Re)Deployed web console plugin")
} else {
logger.Info("Skipping deployment of web console plugin")
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
membercfg "github.com/codeready-toolchain/toolchain-common/pkg/configuration/memberoperatorconfig"
"github.com/codeready-toolchain/toolchain-common/pkg/test"
testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"
errs "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -318,68 +317,6 @@ func TestHandleWebhookDeploy(t *testing.T) {
})
}

func TestHandleWebConsolePluginDeploy(t *testing.T) {
t.Run("deployment not created when webconsoleplugin deploy is false", func(t *testing.T) {
// given
config := commonconfig.NewMemberOperatorConfigWithReset(t, testconfig.WebConsolePlugin().Deploy(false))
controller, cl := prepareReconcile(t, config)

actualConfig, err := membercfg.GetConfiguration(cl)
require.NoError(t, err)

ctx := log.IntoContext(context.TODO(), controller.Log)

// when
err = controller.handleWebConsolePluginDeploy(ctx, actualConfig, test.MemberOperatorNs)

// then
require.NoError(t, err)
actualDeployment := &appsv1.Deployment{}
err = cl.Get(context.TODO(), test.NamespacedName(test.MemberOperatorNs, "member-operator-console-plugin"), actualDeployment)
require.Error(t, err)
require.True(t, errors.IsNotFound(err))
})

t.Run("deployment created when webconsoleplugin deploy is true", func(t *testing.T) {
// given
config := commonconfig.NewMemberOperatorConfigWithReset(t, testconfig.WebConsolePlugin().Deploy(true))
controller, cl := prepareReconcile(t, config)
actualConfig, err := membercfg.GetConfiguration(cl)
require.NoError(t, err)

ctx := log.IntoContext(context.TODO(), controller.Log)

// when
err = controller.handleWebConsolePluginDeploy(ctx, actualConfig, test.MemberOperatorNs)

// then
require.NoError(t, err)
actualDeployment := &appsv1.Deployment{}
err = cl.Get(context.TODO(), test.NamespacedName(test.MemberOperatorNs, "member-operator-console-plugin"), actualDeployment)
require.NoError(t, err)
})

t.Run("deployment error", func(t *testing.T) {
// given
config := commonconfig.NewMemberOperatorConfigWithReset(t, testconfig.WebConsolePlugin().Deploy(true))
controller, cl := prepareReconcile(t, config)
actualConfig, err := membercfg.GetConfiguration(cl)
require.NoError(t, err)

ctx := log.IntoContext(context.TODO(), controller.Log)

// when
cl.(*test.FakeClient).MockGet = func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
return fmt.Errorf("client error")
}
err = controller.handleWebConsolePluginDeploy(ctx, actualConfig, test.MemberOperatorNs)

// then
require.ErrorContains(t, err, "cannot deploy console plugin template")
require.ErrorContains(t, errs.Cause(err), "client error")
})
}

func prepareReconcile(t *testing.T, initObjs ...runtime.Object) (*Reconciler, client.Client) {
os.Setenv("WATCH_NAMESPACE", test.MemberOperatorNs)
restore := test.SetEnvVarAndRestore(t, "MEMBER_OPERATOR_WEBHOOK_IMAGE", "webhookimage")
Expand Down
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/codeready-toolchain/member-operator

require (
github.com/codeready-toolchain/api v0.0.0-20240708122235-0af5a9a178bb
github.com/codeready-toolchain/toolchain-common v0.0.0-20240716065433-8604fe46b96a
github.com/codeready-toolchain/api v0.0.0-20240717145630-bb67a632867a
github.com/codeready-toolchain/toolchain-common v0.0.0-20240628050807-7f226f55a34a
github.com/go-logr/logr v1.2.3
github.com/google/go-cmp v0.5.9
// using latest commit from 'github.com/openshift/api branch release-4.12'
Expand All @@ -20,13 +20,16 @@ require (
sigs.k8s.io/controller-runtime v0.13.0
)

replace github.com/codeready-toolchain/api => github.com/xcoulon/api v0.0.0-20240725145329-0fc7541fe19e

replace github.com/codeready-toolchain/toolchain-common => github.com/xcoulon/toolchain-common v0.0.0-20240725145759-056fcf98e945

require (
github.com/google/uuid v1.6.0
github.com/prometheus/client_golang v1.12.2
k8s.io/apiextensions-apiserver v0.25.0
k8s.io/apimachinery v0.25.0
k8s.io/kubectl v0.24.0
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed
sigs.k8s.io/yaml v1.3.0
)

Expand Down Expand Up @@ -104,6 +107,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/component-base v0.25.0 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWH
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/codeready-toolchain/api v0.0.0-20240708122235-0af5a9a178bb h1:Wc9CMsv0ODZv9dM5qF3OI0mFDO95YNIXV/8oRvoz8aE=
github.com/codeready-toolchain/api v0.0.0-20240708122235-0af5a9a178bb/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240716065433-8604fe46b96a h1:HcaJtZCLfYkWZCxIa3iTvq3zgn711JGqPLkunBTfGSc=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240716065433-8604fe46b96a/go.mod h1:8M9k7w2VSyRKSK6P08Jo2ddW3uyGgxCcSitnYa3HK9o=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down Expand Up @@ -587,6 +583,10 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/xcoulon/api v0.0.0-20240725145329-0fc7541fe19e h1:6rYzVUcLeuVHmFjd7BU/Oe1SMsPrwdQgak2EYMz+oxM=
github.com/xcoulon/api v0.0.0-20240725145329-0fc7541fe19e/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/xcoulon/toolchain-common v0.0.0-20240725145759-056fcf98e945 h1:s7dhWL8+zBI8+bIFzk0EATb6ASGlkA59PHSRvhhxeBc=
github.com/xcoulon/toolchain-common v0.0.0-20240725145759-056fcf98e945/go.mod h1:7o3ZyfqhV16N2Hc3P6j9lx0x6sLhQ0gaVl2cpGAz3ZE=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand Down
71 changes: 0 additions & 71 deletions pkg/consoleplugin/consolepluginserver.go

This file was deleted.

Loading

0 comments on commit c0a23a3

Please sign in to comment.