Skip to content

Commit

Permalink
fix: webhook not working when settings spark job namespaces to empty (#…
Browse files Browse the repository at this point in the history
…2163)

Signed-off-by: Yi Chen <[email protected]>
  • Loading branch information
ChenYi015 authored Sep 13, 2024
1 parent e6a7805 commit 7785107
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions internal/webhook/sparkpod_defaulter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -49,15 +50,19 @@ type SparkPodDefaulter struct {
var _ admission.CustomDefaulter = &SparkPodDefaulter{}

// NewSparkPodDefaulter creates a new SparkPodDefaulter instance.
func NewSparkPodDefaulter(client client.Client, sparkJobNamespaces []string) *SparkPodDefaulter {
m := make(map[string]bool)
for _, ns := range sparkJobNamespaces {
m[ns] = true
func NewSparkPodDefaulter(client client.Client, namespaces []string) *SparkPodDefaulter {
nsMap := make(map[string]bool)
if len(namespaces) == 0 {
nsMap[metav1.NamespaceAll] = true
} else {
for _, ns := range namespaces {
nsMap[ns] = true
}
}

return &SparkPodDefaulter{
client: client,
sparkJobNamespaces: m,
sparkJobNamespaces: nsMap,
}
}

Expand Down Expand Up @@ -93,7 +98,7 @@ func (d *SparkPodDefaulter) Default(ctx context.Context, obj runtime.Object) err
}

func (d *SparkPodDefaulter) isSparkJobNamespace(ns string) bool {
return d.sparkJobNamespaces[ns]
return d.sparkJobNamespaces[metav1.NamespaceAll] || d.sparkJobNamespaces[ns]
}

type mutateSparkPodOption func(pod *corev1.Pod, app *v1beta2.SparkApplication) error
Expand Down

0 comments on commit 7785107

Please sign in to comment.