Skip to content

fix : remove kube-rbac-proxy sidecar metric proxy container from Operator deployment #1437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions build/scripts/generate_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
set -e

# List of environment variables that will be replaced by envsubst
SUBST_VARS='$NAMESPACE $DWO_IMG $RBAC_PROXY_IMAGE $PROJECT_CLONE_IMG $ROUTING_SUFFIX $DEFAULT_ROUTING $PULL_POLICY'
SUBST_VARS='$NAMESPACE $DWO_IMG $PROJECT_CLONE_IMG $ROUTING_SUFFIX $DEFAULT_ROUTING $PULL_POLICY'

SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
DEPLOY_DIR="$SCRIPT_DIR/../../deploy/"
Expand Down Expand Up @@ -177,24 +177,19 @@ fi

# Run kustomize to build yamls
echo "Generating config for Kubernetes"
export RBAC_PROXY_IMAGE="${KUBE_RBAC_PROXY_IMAGE:-quay.io/brancz/kube-rbac-proxy:v0.13.1}"
${KUSTOMIZE} build "${DEPLOY_DIR}/templates/cert-manager" \
| envsubst "$SUBST_VARS" \
> "${KUBERNETES_DIR}/${COMBINED_FILENAME}"
unset RBAC_PROXY_IMAGE
echo "File saved to ${KUBERNETES_DIR}/${COMBINED_FILENAME}"

echo "Generating config for OpenShift"
export RBAC_PROXY_IMAGE="${OPENSHIFT_RBAC_PROXY_IMAGE:-quay.io/brancz/kube-rbac-proxy:v0.13.1}"
${KUSTOMIZE} build "${DEPLOY_DIR}/templates/service-ca" \
| envsubst "$SUBST_VARS" \
> "${OPENSHIFT_DIR}/${COMBINED_FILENAME}"
unset RBAC_PROXY_IMAGE
echo "File saved to ${OPENSHIFT_DIR}/${COMBINED_FILENAME}"

if $GEN_OLM; then
echo "Generating base deployment files for OLM"
export RBAC_PROXY_IMAGE="${OPENSHIFT_RBAC_PROXY_IMAGE:-quay.io/brancz/kube-rbac-proxy:v0.13.1}"
export NAMESPACE=openshift-operators
# Generate .spec.relatedImages for CSV based on deployment
TMPCSV="csv.tmp.yaml"
Expand Down Expand Up @@ -222,7 +217,6 @@ if $GEN_OLM; then
| envsubst "$SUBST_VARS" \
| yq -Y 'select(.kind != "ServiceAccount")' \
> "${OLM_DIR}/${COMBINED_FILENAME}"
unset RBAC_PROXY_IMAGE
echo "File saved to ${OLM_DIR}/${COMBINED_FILENAME}"
fi

Expand Down
19 changes: 9 additions & 10 deletions controllers/cleanupcronjob/cleanupcronjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import (
"fmt"
"time"

"sigs.k8s.io/controller-runtime/pkg/reconcile"

dwv2 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
"github.com/devfile/devworkspace-operator/pkg/conditions"
"github.com/devfile/devworkspace-operator/pkg/config"
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -28,13 +35,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"

dwv2 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
"github.com/devfile/devworkspace-operator/pkg/conditions"
"github.com/devfile/devworkspace-operator/pkg/config"
"github.com/devfile/devworkspace-operator/pkg/infrastructure"

"github.com/operator-framework/operator-lib/prune"
"github.com/robfig/cron/v3"
Expand Down Expand Up @@ -123,10 +123,9 @@ func (r *CleanupCronJobReconciler) SetupWithManager(mgr ctrl.Manager) error {

return ctrl.NewControllerManagedBy(mgr).
Named("CleanupCronJob").
Watches(&source.Kind{Type: &controllerv1alpha1.DevWorkspaceOperatorConfig{}},
handler.EnqueueRequestsFromMapFunc(func(object client.Object) []ctrl.Request {
Watches(&controllerv1alpha1.DevWorkspaceOperatorConfig{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, object client.Object) []reconcile.Request {
operatorNamespace, err := infrastructure.GetNamespace()

// Ignore events from other namespaces
if err != nil || object.GetNamespace() != operatorNamespace || object.GetName() != config.OperatorConfigName {
log.Info("Received event from different namespace, ignoring", "namespace", object.GetNamespace())
Expand Down
6 changes: 5 additions & 1 deletion controllers/controller/devworkspacerouting/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"path/filepath"
"testing"

"sigs.k8s.io/controller-runtime/pkg/webhook"

dwv1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha1"
dwv2 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
Expand Down Expand Up @@ -115,8 +117,10 @@ var _ = BeforeSuite(func() {

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme.Scheme,
Port: 9443,
NewCache: cacheFunc,
WebhookServer: webhook.NewServer(webhook.Options{
Port: 9443,
}),
})
Expect(err).NotTo(HaveOccurred())

Expand Down
20 changes: 9 additions & 11 deletions controllers/workspace/devworkspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/devfile/devworkspace-operator/pkg/library/ssh"

dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
devfilevalidation "github.com/devfile/api/v2/pkg/validation"
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
"github.com/devfile/devworkspace-operator/controllers/workspace/metrics"
Expand All @@ -34,6 +35,7 @@ import (
"github.com/devfile/devworkspace-operator/pkg/dwerrors"
"github.com/devfile/devworkspace-operator/pkg/library/annotate"
containerlib "github.com/devfile/devworkspace-operator/pkg/library/container"
wsDefaults "github.com/devfile/devworkspace-operator/pkg/library/defaults"
"github.com/devfile/devworkspace-operator/pkg/library/env"
"github.com/devfile/devworkspace-operator/pkg/library/flatten"
"github.com/devfile/devworkspace-operator/pkg/library/home"
Expand Down Expand Up @@ -63,10 +65,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
wsDefaults "github.com/devfile/devworkspace-operator/pkg/library/defaults"
)

const (
Expand Down Expand Up @@ -701,7 +699,7 @@ func (r *DevWorkspaceReconciler) SetupWithManager(mgr ctrl.Manager) error {
return err
}

var emptyMapper = func(obj client.Object) []reconcile.Request {
var emptyMapper = func(ctx context.Context, obj client.Object) []reconcile.Request {
return []reconcile.Request{}
}

Expand All @@ -722,12 +720,12 @@ func (r *DevWorkspaceReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&corev1.ConfigMap{}).
Owns(&corev1.Secret{}).
Owns(&corev1.ServiceAccount{}).
Watches(&source.Kind{Type: &corev1.Pod{}}, handler.EnqueueRequestsFromMapFunc(dwRelatedPodsHandler)).
Watches(&source.Kind{Type: &corev1.PersistentVolumeClaim{}}, handler.EnqueueRequestsFromMapFunc(r.dwPVCHandler)).
Watches(&source.Kind{Type: &corev1.Secret{}}, handler.EnqueueRequestsFromMapFunc(r.runningWorkspacesHandler), automountWatcher).
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, handler.EnqueueRequestsFromMapFunc(r.runningWorkspacesHandler), automountWatcher).
Watches(&source.Kind{Type: &corev1.PersistentVolumeClaim{}}, handler.EnqueueRequestsFromMapFunc(r.runningWorkspacesHandler), automountWatcher).
Watches(&source.Kind{Type: &controllerv1alpha1.DevWorkspaceOperatorConfig{}}, handler.EnqueueRequestsFromMapFunc(emptyMapper), configWatcher).
Watches(&corev1.Pod{}, handler.EnqueueRequestsFromMapFunc(dwRelatedPodsHandler)).
Watches(&corev1.PersistentVolumeClaim{}, handler.EnqueueRequestsFromMapFunc(r.dwPVCHandler)).
Watches(&corev1.Secret{}, handler.EnqueueRequestsFromMapFunc(r.runningWorkspacesHandler), automountWatcher).
Watches(&corev1.ConfigMap{}, handler.EnqueueRequestsFromMapFunc(r.runningWorkspacesHandler), automountWatcher).
Watches(&corev1.PersistentVolumeClaim{}, handler.EnqueueRequestsFromMapFunc(r.runningWorkspacesHandler), automountWatcher).
Watches(&controllerv1alpha1.DevWorkspaceOperatorConfig{}, handler.EnqueueRequestsFromMapFunc(emptyMapper), configWatcher).
WithEventFilter(devworkspacePredicates).
WithEventFilter(podPredicates).
Complete(r)
Expand Down
6 changes: 3 additions & 3 deletions controllers/workspace/eventhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

// Mapping the pod to the devworkspace
func dwRelatedPodsHandler(obj client.Object) []reconcile.Request {
func dwRelatedPodsHandler(ctx context.Context, obj client.Object) []reconcile.Request {
labels := obj.GetLabels()
if _, ok := labels[constants.DevWorkspaceNameLabel]; !ok {
return []reconcile.Request{}
Expand All @@ -47,7 +47,7 @@ func dwRelatedPodsHandler(obj client.Object) []reconcile.Request {
}
}

func (r *DevWorkspaceReconciler) dwPVCHandler(obj client.Object) []reconcile.Request {
func (r *DevWorkspaceReconciler) dwPVCHandler(ctx context.Context, obj client.Object) []reconcile.Request {
if obj.GetDeletionTimestamp() == nil {
// Do not reconcile unless PVC is being deleted.
return []reconcile.Request{}
Expand Down Expand Up @@ -118,7 +118,7 @@ func (r *DevWorkspaceReconciler) dwPVCHandler(obj client.Object) []reconcile.Req
return reconciles
}

func (r *DevWorkspaceReconciler) runningWorkspacesHandler(obj client.Object) []reconcile.Request {
func (r *DevWorkspaceReconciler) runningWorkspacesHandler(ctx context.Context, obj client.Object) []reconcile.Request {
dwList := &dw.DevWorkspaceList{}
if err := r.Client.List(context.Background(), dwList, &client.ListOptions{Namespace: obj.GetNamespace()}); err != nil {
return []reconcile.Request{}
Expand Down
6 changes: 5 additions & 1 deletion controllers/workspace/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"path/filepath"
"testing"

"sigs.k8s.io/controller-runtime/pkg/webhook"

dwv1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha1"
dwv2 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
Expand Down Expand Up @@ -117,8 +119,10 @@ var _ = BeforeSuite(func() {

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme.Scheme,
Port: 9443,
NewCache: cacheFunc,
WebhookServer: webhook.NewServer(webhook.Options{
Port: 9443,
}),
})
Expect(err).NotTo(HaveOccurred())

Expand Down
Loading
Loading