Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate v1 types #5483

Merged
merged 5 commits into from
Sep 12, 2019
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
7 changes: 6 additions & 1 deletion cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
autoscalingv1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1"
apiconfig "knative.dev/serving/pkg/apis/config"
net "knative.dev/serving/pkg/apis/networking/v1alpha1"
"knative.dev/serving/pkg/apis/serving/v1"
"knative.dev/serving/pkg/apis/serving/v1alpha1"
"knative.dev/serving/pkg/apis/serving/v1beta1"
)
Expand Down Expand Up @@ -122,6 +123,10 @@ func main() {
v1beta1.SchemeGroupVersion.WithKind("Configuration"): &v1beta1.Configuration{},
v1beta1.SchemeGroupVersion.WithKind("Route"): &v1beta1.Route{},
v1beta1.SchemeGroupVersion.WithKind("Service"): &v1beta1.Service{},
v1.SchemeGroupVersion.WithKind("Revision"): &v1.Revision{},
v1.SchemeGroupVersion.WithKind("Configuration"): &v1.Configuration{},
v1.SchemeGroupVersion.WithKind("Route"): &v1.Route{},
v1.SchemeGroupVersion.WithKind("Service"): &v1.Service{},
autoscalingv1alpha1.SchemeGroupVersion.WithKind("PodAutoscaler"): &autoscalingv1alpha1.PodAutoscaler{},
autoscalingv1alpha1.SchemeGroupVersion.WithKind("Metric"): &autoscalingv1alpha1.Metric{},
net.SchemeGroupVersion.WithKind("Certificate"): &net.Certificate{},
Expand All @@ -137,7 +142,7 @@ func main() {

// Decorate contexts with the current state of the config.
ctxFunc := func(ctx context.Context) context.Context {
return v1beta1.WithUpgradeViaDefaulting(store.ToContext(ctx))
return v1.WithUpgradeViaDefaulting(store.ToContext(ctx))
}

controller, err := webhook.New(kubeClient, options, admissionControllers, logger, ctxFunc)
Expand Down
3 changes: 3 additions & 0 deletions config/v1beta1/300-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ spec:
- name: v1beta1
served: true
storage: false
- name: v1
served: true
storage: false
names:
kind: Configuration
plural: configurations
Expand Down
3 changes: 3 additions & 0 deletions config/v1beta1/300-revision.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ spec:
- name: v1beta1
served: true
storage: false
- name: v1
served: true
storage: false
names:
kind: Revision
plural: revisions
Expand Down
3 changes: 3 additions & 0 deletions config/v1beta1/300-route.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ spec:
- name: v1beta1
served: true
storage: false
- name: v1
served: true
storage: false
names:
kind: Route
plural: routes
Expand Down
3 changes: 3 additions & 0 deletions config/v1beta1/300-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ spec:
- name: v1beta1
served: true
storage: false
- name: v1
served: true
storage: false
names:
kind: Service
plural: services
Expand Down
4 changes: 2 additions & 2 deletions pkg/activator/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import (
"knative.dev/serving/pkg/apis/networking"
nv1a1 "knative.dev/serving/pkg/apis/networking/v1alpha1"
"knative.dev/serving/pkg/apis/serving"
"knative.dev/serving/pkg/apis/serving/v1"
"knative.dev/serving/pkg/apis/serving/v1alpha1"
"knative.dev/serving/pkg/apis/serving/v1beta1"
servingfake "knative.dev/serving/pkg/client/clientset/versioned/fake"
servinginformers "knative.dev/serving/pkg/client/informers/externalversions"
servingv1informers "knative.dev/serving/pkg/client/informers/externalversions/serving/v1alpha1"
Expand Down Expand Up @@ -526,7 +526,7 @@ func revision(namespace, name string) *v1alpha1.Revision {
},
},
Spec: v1alpha1.RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
RevisionSpec: v1.RevisionSpec{
ContainerConcurrency: ptr.Int64(1),
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/activator/net/revision_backends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (
activatortest "knative.dev/serving/pkg/activator/testing"
"knative.dev/serving/pkg/apis/networking"
"knative.dev/serving/pkg/apis/serving"
"knative.dev/serving/pkg/apis/serving/v1"
"knative.dev/serving/pkg/apis/serving/v1alpha1"
"knative.dev/serving/pkg/apis/serving/v1beta1"
fakeservingclient "knative.dev/serving/pkg/client/injection/client/fake"
fakerevisioninformer "knative.dev/serving/pkg/client/injection/informers/serving/v1alpha1/revision/fake"
"knative.dev/serving/pkg/network"
Expand All @@ -64,7 +64,7 @@ func revision(revID types.NamespacedName, protocol networking.ProtocolType) *v1a
Name: revID.Name,
},
Spec: v1alpha1.RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
RevisionSpec: v1.RevisionSpec{
ContainerConcurrency: ptr.Int64(1),
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Expand Down
25 changes: 19 additions & 6 deletions pkg/apis/serving/v1alpha1/configuration_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"

"knative.dev/pkg/apis"
"knative.dev/serving/pkg/apis/serving/v1"
"knative.dev/serving/pkg/apis/serving/v1beta1"
)

Expand All @@ -33,13 +34,19 @@ func (source *Configuration) ConvertUp(ctx context.Context, obj apis.Convertible
return err
}
return source.Status.ConvertUp(ctx, &sink.Status)
case *v1.Configuration:
sink.ObjectMeta = source.ObjectMeta
if err := source.Spec.ConvertUp(ctx, &sink.Spec); err != nil {
return err
}
return source.Status.ConvertUp(ctx, &sink.Status)
default:
return fmt.Errorf("unknown version, got: %T", sink)
}
}

// ConvertUp helps implement apis.Convertible
func (source *ConfigurationSpec) ConvertUp(ctx context.Context, sink *v1beta1.ConfigurationSpec) error {
func (source *ConfigurationSpec) ConvertUp(ctx context.Context, sink *v1.ConfigurationSpec) error {
if source.DeprecatedBuild != nil {
return ConvertErrorf("build", "build cannot be migrated forward.")
}
Expand All @@ -56,14 +63,14 @@ func (source *ConfigurationSpec) ConvertUp(ctx context.Context, sink *v1beta1.Co
}

// ConvertUp helps implement apis.Convertible
func (source *ConfigurationStatus) ConvertUp(ctx context.Context, sink *v1beta1.ConfigurationStatus) error {
func (source *ConfigurationStatus) ConvertUp(ctx context.Context, sink *v1.ConfigurationStatus) error {
source.Status.ConvertTo(ctx, &sink.Status)

return source.ConfigurationStatusFields.ConvertUp(ctx, &sink.ConfigurationStatusFields)
}

// ConvertUp helps implement apis.Convertible
func (source *ConfigurationStatusFields) ConvertUp(ctx context.Context, sink *v1beta1.ConfigurationStatusFields) error {
func (source *ConfigurationStatusFields) ConvertUp(ctx context.Context, sink *v1.ConfigurationStatusFields) error {
sink.LatestReadyRevisionName = source.LatestReadyRevisionName
sink.LatestCreatedRevisionName = source.LatestCreatedRevisionName
return nil
Expand All @@ -78,26 +85,32 @@ func (sink *Configuration) ConvertDown(ctx context.Context, obj apis.Convertible
return err
}
return sink.Status.ConvertDown(ctx, source.Status)
case *v1.Configuration:
sink.ObjectMeta = source.ObjectMeta
if err := sink.Spec.ConvertDown(ctx, source.Spec); err != nil {
return err
}
return sink.Status.ConvertDown(ctx, source.Status)
default:
return fmt.Errorf("unknown version, got: %T", source)
}
}

// ConvertDown helps implement apis.Convertible
func (sink *ConfigurationSpec) ConvertDown(ctx context.Context, source v1beta1.ConfigurationSpec) error {
func (sink *ConfigurationSpec) ConvertDown(ctx context.Context, source v1.ConfigurationSpec) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Golint naming: receiver name sink should be consistent with previous receiver name source for ConfigurationSpec. More info.

sink.Template = &RevisionTemplateSpec{}
return sink.Template.ConvertDown(ctx, source.Template)
}

// ConvertDown helps implement apis.Convertible
func (sink *ConfigurationStatus) ConvertDown(ctx context.Context, source v1beta1.ConfigurationStatus) error {
func (sink *ConfigurationStatus) ConvertDown(ctx context.Context, source v1.ConfigurationStatus) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Golint naming: receiver name sink should be consistent with previous receiver name source for ConfigurationStatus. More info.

source.Status.ConvertTo(ctx, &sink.Status)

return sink.ConfigurationStatusFields.ConvertDown(ctx, source.ConfigurationStatusFields)
}

// ConvertDown helps implement apis.Convertible
func (sink *ConfigurationStatusFields) ConvertDown(ctx context.Context, source v1beta1.ConfigurationStatusFields) error {
func (sink *ConfigurationStatusFields) ConvertDown(ctx context.Context, source v1.ConfigurationStatusFields) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Golint naming: receiver name sink should be consistent with previous receiver name source for ConfigurationStatusFields. More info.

sink.LatestReadyRevisionName = source.LatestReadyRevisionName
sink.LatestCreatedRevisionName = source.LatestCreatedRevisionName
return nil
Expand Down
125 changes: 78 additions & 47 deletions pkg/apis/serving/v1alpha1/configuration_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/ptr"
"knative.dev/serving/pkg/apis/serving/v1"
"knative.dev/serving/pkg/apis/serving/v1beta1"
)

Expand All @@ -42,7 +44,34 @@ func TestConfigurationConversionBadType(t *testing.T) {
}
}

func TestConfigurationConversionTemplateError(t *testing.T) {
tests := []struct {
name string
cs *ConfigurationSpec
}{{
name: "multiple of",
cs: &ConfigurationSpec{
Template: &RevisionTemplateSpec{},
DeprecatedRevisionTemplate: &RevisionTemplateSpec{},
},
}, {
name: "missing",
cs: &ConfigurationSpec{},
}}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := &v1.ConfigurationSpec{}
if err := test.cs.ConvertUp(context.Background(), result); err == nil {
t.Errorf("ConvertUp() = %#v, wanted error", result)
}
})
}
}

func TestConfigurationConversion(t *testing.T) {
versions := []apis.Convertible{&v1.Configuration{}, &v1beta1.Configuration{}}

tests := []struct {
name string
in *Configuration
Expand All @@ -58,7 +87,7 @@ func TestConfigurationConversion(t *testing.T) {
Spec: ConfigurationSpec{
Template: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
RevisionSpec: v1.RevisionSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Expand Down Expand Up @@ -113,7 +142,7 @@ func TestConfigurationConversion(t *testing.T) {
},
Template: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
RevisionSpec: v1.RevisionSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "busybox",
Expand Down Expand Up @@ -149,55 +178,57 @@ func TestConfigurationConversion(t *testing.T) {
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
beta := &v1beta1.Configuration{}
if err := test.in.ConvertUp(context.Background(), beta); err != nil {
if test.badField != "" {
cce, ok := err.(*CannotConvertError)
if ok && cce.Field == test.badField {
return
for _, version := range versions {
t.Run(test.name, func(t *testing.T) {
ver := version
if err := test.in.ConvertUp(context.Background(), ver); err != nil {
if test.badField != "" {
cce, ok := err.(*CannotConvertError)
if ok && cce.Field == test.badField {
return
}
}
t.Errorf("ConvertUp() = %v", err)
} else if test.badField != "" {
t.Errorf("ConvertUp() = %#v, wanted bad field %q", ver,
test.badField)
return
}
t.Errorf("ConvertUp() = %v", err)
} else if test.badField != "" {
t.Errorf("CovnertUp() = %#v, wanted bad field %q", beta,
test.badField)
return
}
got := &Configuration{}
if err := got.ConvertDown(context.Background(), beta); err != nil {
t.Errorf("ConvertDown() = %v", err)
}
if diff := cmp.Diff(test.in, got); diff != "" {
t.Errorf("roundtrip (-want, +got) = %v", diff)
}
})
got := &Configuration{}
if err := got.ConvertDown(context.Background(), ver); err != nil {
t.Errorf("ConvertDown() = %v", err)
}
if diff := cmp.Diff(test.in, got); diff != "" {
t.Errorf("roundtrip (-want, +got) = %v", diff)
}
})

// A variant of the test that uses `revisionTemplate:` and `container:`,
// but end up with what we have above anyways.
t.Run(test.name+" (deprecated)", func(t *testing.T) {
start := toDeprecated(test.in)
beta := &v1beta1.Configuration{}
if err := start.ConvertUp(context.Background(), beta); err != nil {
if test.badField != "" {
cce, ok := err.(*CannotConvertError)
if ok && cce.Field == test.badField {
return
// A variant of the test that uses `revisionTemplate:` and `container:`,
// but end up with what we have above anyways.
t.Run(test.name+" (deprecated)", func(t *testing.T) {
ver := version
start := toDeprecated(test.in)
if err := start.ConvertUp(context.Background(), ver); err != nil {
if test.badField != "" {
cce, ok := err.(*CannotConvertError)
if ok && cce.Field == test.badField {
return
}
}
t.Errorf("ConvertUp() = %v", err)
} else if test.badField != "" {
t.Errorf("CovnertUp() = %#v, wanted bad field %q", ver,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Errorf("CovnertUp() = %#v, wanted bad field %q", ver,
t.Errorf("ConvertUp() = %#v, wanted bad field %q", ver,

test.badField)
return
}
t.Errorf("ConvertUp() = %v", err)
} else if test.badField != "" {
t.Errorf("CovnertUp() = %#v, wanted bad field %q", beta,
test.badField)
return
}
got := &Configuration{}
if err := got.ConvertDown(context.Background(), beta); err != nil {
t.Errorf("ConvertDown() = %v", err)
}
if diff := cmp.Diff(test.in, got); diff != "" {
t.Errorf("roundtrip (-want, +got) = %v", diff)
}
})
got := &Configuration{}
if err := got.ConvertDown(context.Background(), ver); err != nil {
t.Errorf("ConvertDown() = %v", err)
}
if diff := cmp.Diff(test.in, got); diff != "" {
t.Errorf("roundtrip (-want, +got) = %v", diff)
}
})
}
}
}
10 changes: 5 additions & 5 deletions pkg/apis/serving/v1alpha1/configuration_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"knative.dev/pkg/apis"

"knative.dev/serving/pkg/apis/serving/v1beta1"
"knative.dev/serving/pkg/apis/serving/v1"
)

func (c *Configuration) SetDefaults(ctx context.Context) {
Expand All @@ -30,11 +30,11 @@ func (c *Configuration) SetDefaults(ctx context.Context) {
}

func (cs *ConfigurationSpec) SetDefaults(ctx context.Context) {
if v1beta1.IsUpgradeViaDefaulting(ctx) {
beta := v1beta1.ConfigurationSpec{}
if cs.ConvertUp(ctx, &beta) == nil {
if v1.IsUpgradeViaDefaulting(ctx) {
v1 := v1.ConfigurationSpec{}
if cs.ConvertUp(ctx, &v1) == nil {
alpha := ConfigurationSpec{}
if alpha.ConvertDown(ctx, beta) == nil {
if alpha.ConvertDown(ctx, v1) == nil {
*cs = alpha
}
}
Expand Down
Loading