Skip to content
Merged
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
57 changes: 0 additions & 57 deletions pkg/webhook/create_options.go

This file was deleted.

60 changes: 0 additions & 60 deletions pkg/webhook/create_options_test.go

This file was deleted.

4 changes: 1 addition & 3 deletions pkg/webhook/podspec_dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ func dryRunPodSpec(ctx context.Context, pod *corev1.Pod, mode DryRunMode) *apis.
logger := logging.FromContext(ctx)
client := kubeclient.Get(ctx)

pods := newCreateWithOptions(client.CoreV1().RESTClient(), pod.GetNamespace())

options := metav1.CreateOptions{DryRun: []string{metav1.DryRunAll}}
if _, err := pods.createWithOptions(ctx, pod, options); err != nil {
if _, err := client.CoreV1().Pods(pod.GetNamespace()).Create(ctx, pod, options); err != nil {
// Ignore failures for implementations that don't support dry-run.
// This likely means there are other webhooks on the PodSpec Create action which do not declare sideEffects:none
if mode != DryRunStrict && strings.Contains(err.Error(), "does not support dry run") {
Expand Down
27 changes: 8 additions & 19 deletions pkg/webhook/podspec_dryrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
rest "k8s.io/client-go/rest"
ktesting "k8s.io/client-go/testing"

"knative.dev/pkg/apis"
Expand Down Expand Up @@ -62,10 +61,8 @@ func TestExtraServiceValidation(t *testing.T) {
s *v1.Service
want string
modifyContext func(context.Context)
podInterface func(client rest.Interface, namespace string) podInterface
}{{
name: "valid run latest",
podInterface: newTestPods,
name: "valid run latest",
s: &v1.Service{
ObjectMeta: om,
Spec: v1.ServiceSpec{
Expand All @@ -80,8 +77,7 @@ func TestExtraServiceValidation(t *testing.T) {
},
modifyContext: nil,
}, {
name: "dryrun fail",
podInterface: newFailTestPods,
name: "dryrun fail",
s: &v1.Service{
ObjectMeta: om,
Spec: v1.ServiceSpec{
Expand All @@ -94,11 +90,10 @@ func TestExtraServiceValidation(t *testing.T) {
},
},
},
want: "dry run failed with fail-reason: spec.template",
want: "dry run failed with kubeclient error: spec.template",
modifyContext: failKubeCalls,
}, {
name: "no template found",
podInterface: newTestPods,
name: "no template found",
s: &v1.Service{
ObjectMeta: om,
Spec: v1.ServiceSpec{
Expand All @@ -116,7 +111,6 @@ func TestExtraServiceValidation(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
newCreateWithOptions = test.podInterface
ctx, _ := fakekubeclient.With(context.Background())
if test.modifyContext != nil {
test.modifyContext(ctx)
Expand Down Expand Up @@ -167,27 +161,23 @@ func TestConfigurationValidation(t *testing.T) {
c *v1.Configuration
want string
modifyContext func(context.Context)
podInterface func(client rest.Interface, namespace string) podInterface
}{{
name: "valid run latest",
podInterface: newTestPods,
name: "valid run latest",
c: &v1.Configuration{
ObjectMeta: om,
Spec: goodConfigSpec,
},
modifyContext: nil,
}, {
name: "dryrun fail",
podInterface: newFailTestPods,
name: "dryrun fail",
c: &v1.Configuration{
ObjectMeta: om,
Spec: goodConfigSpec,
},
want: "dry run failed with fail-reason: spec.template",
want: "dry run failed with kubeclient error: spec.template",
modifyContext: failKubeCalls,
}, {
name: "skip service owned",
podInterface: newFailTestPods,
name: "skip service owned",
c: &v1.Configuration{
ObjectMeta: metav1.ObjectMeta{
Name: "valid",
Expand All @@ -206,7 +196,6 @@ func TestConfigurationValidation(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
newCreateWithOptions = test.podInterface
ctx, _ := fakekubeclient.With(context.Background())
if test.modifyContext != nil {
test.modifyContext(ctx)
Expand Down
16 changes: 5 additions & 11 deletions pkg/webhook/validate_unstructured_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
rest "k8s.io/client-go/rest"

"knative.dev/pkg/apis"
fakekubeclient "knative.dev/pkg/client/injection/kube/client/fake"
Expand All @@ -46,16 +45,12 @@ var (
)

func TestUnstructuredValidation(t *testing.T) {
newCreateWithOptions = newTestPods

tests := []struct {
name string
data map[string]interface{}
want string
podInterface func(client rest.Interface, namespace string) podInterface
name string
data map[string]interface{}
want string
}{{
name: "valid run latest",
podInterface: newTestPods,
name: "valid run latest",
data: map[string]interface{}{
"metadata": validMetadata,
"spec": map[string]interface{}{
Expand Down Expand Up @@ -208,7 +203,6 @@ func TestDryRunFeatureFlag(t *testing.T) {
}

func TestSkipUpdate(t *testing.T) {
newCreateWithOptions = newFailTestPods
validService := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
Expand Down Expand Up @@ -247,7 +241,7 @@ func TestSkipUpdate(t *testing.T) {
},
},
},
want: "dry run failed with fail-reason: spec.template",
want: "dry run failed with kubeclient error: spec.template",
}, {
name: "skip_identical_old",
new: validServiceUns,
Expand Down