Skip to content

Commit

Permalink
clean up feature keys
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto committed Oct 27, 2023
1 parent 7c92928 commit 992f6f6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
7 changes: 4 additions & 3 deletions pkg/webhook/podspec_dryrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"knative.dev/pkg/logging"
logtesting "knative.dev/pkg/logging/testing"
"knative.dev/pkg/ptr"
"knative.dev/serving/pkg/apis/config"
v1 "knative.dev/serving/pkg/apis/serving/v1"
)

Expand All @@ -52,7 +53,7 @@ func TestExtraServiceValidation(t *testing.T) {
Name: "valid",
Namespace: "foo",
Annotations: map[string]string{
"features.knative.dev/podspec-dryrun": "enabled",
config.DryRunFeatureKey: "enabled",
},
}

Expand Down Expand Up @@ -152,7 +153,7 @@ func TestConfigurationValidation(t *testing.T) {
Name: "valid",
Namespace: "foo",
Annotations: map[string]string{
"features.knative.dev/podspec-dryrun": "enabled",
config.DryRunFeatureKey: "enabled",
},
}

Expand Down Expand Up @@ -186,7 +187,7 @@ func TestConfigurationValidation(t *testing.T) {
"serving.knative.dev/service": "skip-me",
},
Annotations: map[string]string{
"features.knative.dev/podspec-dryrun": "enabled",
config.DryRunFeatureKey: "enabled",
},
},
Spec: goodConfigSpec,
Expand Down
7 changes: 2 additions & 5 deletions pkg/webhook/validate_unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ import (
v1 "knative.dev/serving/pkg/apis/serving/v1"
)

// PodSpecDryRunAnnotation gates the podspec dryrun feature and runs with the value 'enabled'
const PodSpecDryRunAnnotation = "features.knative.dev/podspec-dryrun"

// DryRunMode represents possible values of the PodSpecDryRunAnnotation
// DryRunMode represents possible values of the config.DryRunFeatureKey annotation
type DryRunMode string

const (
Expand Down Expand Up @@ -62,7 +59,7 @@ func ValidateConfiguration(ctx context.Context, uns *unstructured.Unstructured)
func validateRevisionTemplate(ctx context.Context, uns *unstructured.Unstructured) error {
content := uns.UnstructuredContent()

mode := DryRunMode(uns.GetAnnotations()[PodSpecDryRunAnnotation])
mode := DryRunMode(uns.GetAnnotations()[config.DryRunFeatureKey])
features := config.FromContextOrDefaults(ctx).Features
switch features.PodSpecDryRun {
case config.Enabled:
Expand Down
10 changes: 5 additions & 5 deletions pkg/webhook/validate_unstructured_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
"name": "valid",
"namespace": "foo",
"annotations": map[string]interface{}{
"features.knative.dev/podspec-dryrun": "enabled",
config.DryRunFeatureKey: "enabled",
},
}
)
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestDryRunFeatureFlag(t *testing.T) {
"name": "valid",
"namespace": "foo",
"annotations": map[string]interface{}{
"features.knative.dev/podspec-dryrun": "strict",
config.DryRunFeatureKey: "strict",
},
},
"spec": true, // Invalid, spec is expected to be a struct
Expand All @@ -153,7 +153,7 @@ func TestDryRunFeatureFlag(t *testing.T) {
"name": "invalid",
"namespace": "foo",
"annotations": map[string]interface{}{
"features.knative.dev/podspec-dryrun": "enabled",
config.DryRunFeatureKey: "enabled",
},
},
"spec": true, // Invalid, spec is expected to be a struct
Expand All @@ -167,7 +167,7 @@ func TestDryRunFeatureFlag(t *testing.T) {
"name": "invalid",
"namespace": "foo",
"annotations": map[string]interface{}{
"features.knative.dev/podspec-dryrun": "strict",
config.DryRunFeatureKey: "strict",
},
},
"spec": true, // Invalid, spec is expected to be a struct
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestSkipUpdate(t *testing.T) {
validService := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"features.knative.dev/podspec-dryrun": "enabled",
config.DryRunFeatureKey: "enabled",
},
},
Spec: v1.ServiceSpec{
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/service_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"
"testing"

"knative.dev/serving/pkg/apis/config"
v1 "knative.dev/serving/pkg/apis/serving/v1"
"knative.dev/serving/pkg/webhook"
"knative.dev/serving/test"
Expand Down Expand Up @@ -51,7 +52,7 @@ func TestServiceValidationWithInvalidPodSpec(t *testing.T) {

// Setup Service
service, err := v1test.CreateService(t, clients, names,
WithServiceAnnotation(webhook.PodSpecDryRunAnnotation, string(webhook.DryRunStrict)))
WithServiceAnnotation(config.DryRunFeatureKey, string(webhook.DryRunStrict)))
if err != nil {
t.Fatal("Create Service:", err)
}
Expand Down

0 comments on commit 992f6f6

Please sign in to comment.