Skip to content
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
1 change: 1 addition & 0 deletions pkg/webhook/cluster_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func getSpecClusterRole() (*v1.ClusterRole, error) {
Verbs: []string{
"get",
"list",
"watch",
},
},
// Needed for pkg/config/sync.go:109 (SetupControllerConfig)
Expand Down
6 changes: 3 additions & 3 deletions webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func main() {
os.Exit(1)
}

err = createWebhooks(mgr)
err = createWebhooks(mgr, nonCachedClient)
if err != nil {
log.Error(err, "Failed to create webhooks")
os.Exit(1)
Expand Down Expand Up @@ -198,15 +198,15 @@ func main() {
}
}

func createWebhooks(mgr manager.Manager) error {
func createWebhooks(mgr manager.Manager, nonCachedClient client.Client) error {
log.Info("Configuring Webhook Server")
err := server.ConfigureWebhookServer(mgr)
if err != nil {
return err
}

log.Info("Configuring Webhooks")
if err := workspace.Configure(context.TODO(), mgr); err != nil {
if err := workspace.Configure(context.TODO(), mgr, nonCachedClient); err != nil {
return err
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions webhook/workspace/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
)

// Configure configures mutate/validating webhooks that provides exec access into workspace for creator only
func Configure(ctx context.Context, mgr manager.Manager) error {
func Configure(ctx context.Context, mgr manager.Manager, nonCachingClient client.Client) error {
log.Info("Configuring devworkspace webhooks")
c, err := createClient()
if err != nil {
Expand Down Expand Up @@ -88,7 +88,7 @@ func Configure(ctx context.Context, mgr manager.Manager) error {
log.Info("Created devworkspace mutating webhook configuration")
}

server.GetWebhookServer().Register(mutateWebhookPath, &webhook.Admission{Handler: NewResourcesMutator(saUID, saName, mgr)})
server.GetWebhookServer().Register(mutateWebhookPath, &webhook.Admission{Handler: NewResourcesMutator(saUID, saName, mgr, nonCachingClient)})

if err := c.Create(ctx, validateWebhookCfg); err != nil {
if !apierrors.IsAlreadyExists(err) {
Expand All @@ -111,7 +111,7 @@ func Configure(ctx context.Context, mgr manager.Manager) error {
log.Info("Created devworkspace validating webhook configuration")
}

server.GetWebhookServer().Register(validateWebhookPath, &webhook.Admission{Handler: NewResourcesValidator(saUID, saName, mgr)})
server.GetWebhookServer().Register(validateWebhookPath, &webhook.Admission{Handler: NewResourcesValidator(saUID, saName, mgr, nonCachingClient)})

return nil
}
Expand Down
1 change: 1 addition & 0 deletions webhook/workspace/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type WebhookHandler struct {
ControllerUID string
ControllerSAName string
Client client.Client
NonCachingClient client.Client
Decoder admission.Decoder
}

Expand Down
2 changes: 1 addition & 1 deletion webhook/workspace/handler/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (h *WebhookHandler) resolveDevWorkspace(
flattenHelpers := flatten.ResolverTools{
WorkspaceNamespace: workspace.Namespace,
Context: ctx,
K8sClient: h.Client,
K8sClient: h.NonCachingClient,
HttpClient: httpClient,
DefaultResourceRequirements: workspace.Config.Workspace.DefaultContainerResources,
}
Expand Down
5 changes: 3 additions & 2 deletions webhook/workspace/handler/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func newTestWebhookHandler(t *testing.T) *WebhookHandler {
WithScheme(s).
Build()
return &WebhookHandler{
Client: fakeClient,
Decoder: admission.NewDecoder(s),
Client: fakeClient,
NonCachingClient: fakeClient,
Decoder: admission.NewDecoder(s),
}
}

Expand Down
5 changes: 3 additions & 2 deletions webhook/workspace/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/devfile/devworkspace-operator/webhook/workspace/handler"
Expand All @@ -33,8 +34,8 @@ type ResourcesMutator struct {
*handler.WebhookHandler
}

func NewResourcesMutator(controllerUID, controllerSAName string, mgr manager.Manager) *ResourcesMutator {
return &ResourcesMutator{&handler.WebhookHandler{ControllerUID: controllerUID, ControllerSAName: controllerSAName, Decoder: admission.NewDecoder(mgr.GetScheme()), Client: mgr.GetClient()}}
func NewResourcesMutator(controllerUID, controllerSAName string, mgr manager.Manager, nonCachingClient client.Client) *ResourcesMutator {
return &ResourcesMutator{&handler.WebhookHandler{ControllerUID: controllerUID, ControllerSAName: controllerSAName, Decoder: admission.NewDecoder(mgr.GetScheme()), Client: mgr.GetClient(), NonCachingClient: nonCachingClient}}
}

// ResourcesMutator verify if operation is a valid from Workspace controller perspective
Expand Down
5 changes: 3 additions & 2 deletions webhook/workspace/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/devfile/devworkspace-operator/webhook/workspace/handler"
Expand All @@ -33,8 +34,8 @@ type ResourcesValidator struct {
*handler.WebhookHandler
}

func NewResourcesValidator(controllerUID, controllerSAName string, mgr manager.Manager) *ResourcesValidator {
return &ResourcesValidator{&handler.WebhookHandler{ControllerUID: controllerUID, ControllerSAName: controllerSAName, Decoder: admission.NewDecoder(mgr.GetScheme()), Client: mgr.GetClient()}}
func NewResourcesValidator(controllerUID, controllerSAName string, mgr manager.Manager, nonCachingClient client.Client) *ResourcesValidator {
return &ResourcesValidator{&handler.WebhookHandler{ControllerUID: controllerUID, ControllerSAName: controllerSAName, Decoder: admission.NewDecoder(mgr.GetScheme()), Client: mgr.GetClient(), NonCachingClient: nonCachingClient}}
}

func (v *ResourcesValidator) Handle(ctx context.Context, req admission.Request) admission.Response {
Expand Down
Loading