Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

[0.21] KafkaChannel hack to upgrade (#5085) #1213

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
6 changes: 5 additions & 1 deletion pkg/apis/messaging/v1/subscription_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ func (s *Subscription) SetDefaults(ctx context.Context) {
}

func (ss *SubscriptionSpec) SetDefaults(ctx context.Context) {
// TODO anything?
// HACK if a channel ref is a kafka channel ref, we need to hack it around to use only v1beta1
// TODO(slinkydeveloper) REMOVE AFTER 0.22 release
if ss.Channel.Kind == "KafkaChannel" && ss.Channel.APIVersion == "messaging.knative.dev/v1alpha1" {
ss.Channel.APIVersion = "messaging.knative.dev/v1beta1"
}
}
10 changes: 9 additions & 1 deletion pkg/apis/messaging/v1/subscription_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,16 @@ func (s *Subscription) CheckImmutableFields(ctx context.Context, original *Subsc
return nil
}

// TODO(slinkydeveloper)
// HACK around the immutability check to make sure the update script can upgrade the api version
// REMOVE AFTER 0.22 release
ignoredFields := []string{"Subscriber", "Reply"}
if original.Spec.Channel.Kind == "KafkaChannel" && original.Spec.Channel.APIVersion == "messaging.knative.dev/v1alpha1" && s.Spec.Channel.APIVersion == "messaging.knative.dev/v1beta1" {
ignoredFields = append(ignoredFields, "Channel.APIVersion")
}

// Only Subscriber and Reply are mutable.
ignoreArguments := cmpopts.IgnoreFields(SubscriptionSpec{}, "Subscriber", "Reply")
ignoreArguments := cmpopts.IgnoreFields(SubscriptionSpec{}, ignoredFields...)
if diff, err := kmp.ShortDiff(original.Spec, s.Spec, ignoreArguments); err != nil {
return &apis.FieldError{
Message: "Failed to diff Subscription",
Expand Down
23 changes: 23 additions & 0 deletions pkg/apis/messaging/v1/subscription_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,29 @@ func TestSubscriptionImmutable(t *testing.T) {
},
},
want: nil,
}, {
name: "valid, kafkachannel hack",
c: &Subscription{
Spec: SubscriptionSpec{
Channel: corev1.ObjectReference{
Name: channelName,
Kind: "KafkaChannel",
APIVersion: "messaging.knative.dev/v1beta1",
},
Subscriber: getValidDestination(),
},
},
og: &Subscription{
Spec: SubscriptionSpec{
Channel: corev1.ObjectReference{
Name: channelName,
Kind: "KafkaChannel",
APIVersion: "messaging.knative.dev/v1alpha1",
},
Subscriber: getValidDestination(),
},
},
want: nil,
}, {
name: "Channel changed",
c: &Subscription{
Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/messaging/v1beta1/subscription_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ func (s *Subscription) SetDefaults(ctx context.Context) {
}

func (ss *SubscriptionSpec) SetDefaults(ctx context.Context) {
// TODO anything?
// HACK if a channel ref is a kafka channel ref, we need to hack it around to use only v1beta1
// TODO(slinkydeveloper) REMOVE AFTER 0.22 release
if ss.Channel.Kind == "KafkaChannel" && ss.Channel.APIVersion == "messaging.knative.dev/v1alpha1" {
ss.Channel.APIVersion = "messaging.knative.dev/v1beta1"
}
}
10 changes: 9 additions & 1 deletion pkg/apis/messaging/v1beta1/subscription_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,16 @@ func (s *Subscription) CheckImmutableFields(ctx context.Context, original *Subsc
return nil
}

// TODO(slinkydeveloper)
// HACK around the immutability check to make sure the update script can upgrade the api version
// REMOVE AFTER 0.22 release
ignoredFields := []string{"Subscriber", "Reply"}
if original.Spec.Channel.Kind == "KafkaChannel" && original.Spec.Channel.APIVersion == "messaging.knative.dev/v1alpha1" && s.Spec.Channel.APIVersion == "messaging.knative.dev/v1beta1" {
ignoredFields = append(ignoredFields, "Channel.APIVersion")
}

// Only Subscriber and Reply are mutable.
ignoreArguments := cmpopts.IgnoreFields(SubscriptionSpec{}, "Subscriber", "Reply")
ignoreArguments := cmpopts.IgnoreFields(SubscriptionSpec{}, ignoredFields...)
if diff, err := kmp.ShortDiff(original.Spec, s.Spec, ignoreArguments); err != nil {
return &apis.FieldError{
Message: "Failed to diff Subscription",
Expand Down
23 changes: 23 additions & 0 deletions pkg/apis/messaging/v1beta1/subscription_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,29 @@ func TestSubscriptionImmutable(t *testing.T) {
},
},
want: nil,
}, {
name: "valid, kafkachannel hack",
c: &Subscription{
Spec: SubscriptionSpec{
Channel: corev1.ObjectReference{
Name: channelName,
Kind: "KafkaChannel",
APIVersion: "messaging.knative.dev/v1beta1",
},
Subscriber: getValidDestination(),
},
},
og: &Subscription{
Spec: SubscriptionSpec{
Channel: corev1.ObjectReference{
Name: channelName,
Kind: "KafkaChannel",
APIVersion: "messaging.knative.dev/v1alpha1",
},
Subscriber: getValidDestination(),
},
},
want: nil,
}, {
name: "valid, new Reply",
c: &Subscription{
Expand Down