Skip to content

Commit

Permalink
added rbac permissions for manager
Browse files Browse the repository at this point in the history
Signed-off-by: mzeevi <meytar80@gmail.com>
  • Loading branch information
mzeevi committed May 7, 2024
1 parent 8b10414 commit 59d9153
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
envwebhook "github.com/dana-team/env-route-ns-mutator/internal/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

configv1 "github.com/openshift/api/config/v1"
routev1 "github.com/openshift/api/route/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand All @@ -45,6 +46,7 @@ var (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(routev1.Install(scheme))
utilruntime.Must(configv1.Install(scheme))

//+kubebuilder:scaffold:scheme
}
Expand Down
2 changes: 2 additions & 0 deletions internal/webhook/namespace_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type NamespaceMutator struct {

const DefaultSchedulerAnnotation = "scheduler.alpha.kubernetes.io/defaultTolerations"

// +kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch;create;update;patch

// +kubebuilder:webhook:path=/mutate-v1-namespace,mutating=true,failurePolicy=ignore,sideEffects=None,groups="",resources=namespaces,verbs=create;update,versions=v1,name=namespace.dana.io,admissionReviewVersions=v1;v1beta1

func (r *NamespaceMutator) Handle(ctx context.Context, req admission.Request) admission.Response {
Expand Down
7 changes: 2 additions & 5 deletions internal/webhook/route_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type RouteMutator struct {

const clusterIngressName = "cluster"

// +kubebuilder:rbac:groups="route.openshift.io",resources=routes,verbs=get;list;watch;create;update;patch

// +kubebuilder:webhook:path=/mutate-v1-route,mutating=true,failurePolicy=ignore,sideEffects=None,groups=route.openshift.io,resources=routes,verbs=create;update,versions=v1,name=route.dana.io,admissionReviewVersions=v1;v1beta1

func (r *RouteMutator) Handle(ctx context.Context, req admission.Request) admission.Response {
Expand All @@ -52,11 +54,6 @@ func (r *RouteMutator) Handle(ctx context.Context, req admission.Request) admiss
}

environments := environment.GetEnvironments()
if err != nil {
logger.Error(err, "failed to get environments")
return admission.Errored(http.StatusInternalServerError, err)
}

r.handleInner(logger, &route, clusterIngress, environments, namespace.ObjectMeta.Labels)

marshaledRoute, err := json.Marshal(route)
Expand Down

0 comments on commit 59d9153

Please sign in to comment.