From 5d47074c106ed590ef93b882a9748e60d627a368 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Thu, 10 Aug 2023 16:45:30 +0200 Subject: [PATCH 1/2] Remove unusable flag from cmd --- docs/cmd/kn_trigger_update.md | 1 - pkg/kn/commands/trigger/update_flags.go | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/cmd/kn_trigger_update.md b/docs/cmd/kn_trigger_update.md index 43c02c7afe..a8967fe65a 100644 --- a/docs/cmd/kn_trigger_update.md +++ b/docs/cmd/kn_trigger_update.md @@ -24,7 +24,6 @@ kn trigger update NAME ### Options ``` - --broker string Name of the Broker which the trigger associates with. (default "default") --filter strings Key-value pair for exact CloudEvent attribute matching against incoming events, e.g type=dev.knative.foo -h, --help help for update -n, --namespace string Specify the namespace to operate in. diff --git a/pkg/kn/commands/trigger/update_flags.go b/pkg/kn/commands/trigger/update_flags.go index 80467b8cd2..3c21867e4d 100644 --- a/pkg/kn/commands/trigger/update_flags.go +++ b/pkg/kn/commands/trigger/update_flags.go @@ -50,7 +50,10 @@ func (f *TriggerUpdateFlags) GetUpdateFilters() (map[string]string, []string, er // Add is to set parameters func (f *TriggerUpdateFlags) Add(cmd *cobra.Command) { - cmd.Flags().StringVar(&f.Broker, "broker", "default", "Name of the Broker which the trigger associates with.") + if cmd.Name() != "update" { + // Spec.Broker is immutable field + cmd.Flags().StringVar(&f.Broker, "broker", "default", "Name of the Broker which the trigger associates with.") + } // The Sugar controller was integrated into main Eventing controller. With that the default behavior was changed as well. // Users need to configure 'Automatic Broker Creation' per linked docs. // Deprecated in 1.4, remove in 1.6. From cf296dcfc626271785b45d515747709b324fbd2a Mon Sep 17 00:00:00 2001 From: David Simansky Date: Thu, 10 Aug 2023 16:57:50 +0200 Subject: [PATCH 2/2] Fix unit test --- pkg/kn/commands/trigger/update_test.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pkg/kn/commands/trigger/update_test.go b/pkg/kn/commands/trigger/update_test.go index 35ca990403..b9fb700eec 100644 --- a/pkg/kn/commands/trigger/update_test.go +++ b/pkg/kn/commands/trigger/update_test.go @@ -62,20 +62,6 @@ func TestTriggerUpdateWithError(t *testing.T) { eventingRecorder.Validate() } -func TestTriggerUpdateInvalidBroker(t *testing.T) { - eventingClient := clienteventingv1.NewMockKnEventingClient(t) - eventingRecorder := eventingClient.Recorder() - present := createTrigger("default", triggerName, map[string]string{"type": "dev.knative.new"}, "mybroker", "newsvc") - eventingRecorder.GetTrigger(triggerName, present, nil) - - out, err := executeTriggerCommand(eventingClient, nil, "update", triggerName, - "--broker", "newbroker") - assert.ErrorContains(t, err, "broker is immutable") - assert.Assert(t, util.ContainsAll(out, "Usage", triggerName)) - - eventingRecorder.Validate() -} - func TestTriggerUpdateDeletionTimestampNotNil(t *testing.T) { eventingClient := clienteventingv1.NewMockKnEventingClient(t)