Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 1cdd572

Browse files
committed
Print warning if dumping components with external resources
1 parent 21c937e commit 1cdd572

21 files changed

Lines changed: 184 additions & 112 deletions

File tree

cmd/create/broker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
tmbroker "github.com/triggermesh/tmctl/pkg/triggermesh/components/broker"
3131
)
3232

33-
func (o *CreateOptions) NewBrokerCmd() *cobra.Command {
33+
func (o *createOptions) NewBrokerCmd() *cobra.Command {
3434
return &cobra.Command{
3535
Use: "broker <name>",
3636
// Short: "TriggerMesh broker",
@@ -44,7 +44,7 @@ func (o *CreateOptions) NewBrokerCmd() *cobra.Command {
4444
}
4545
}
4646

47-
func (o *CreateOptions) broker(name string) error {
47+
func (o *createOptions) broker(name string) error {
4848
ctx := context.Background()
4949

5050
o.Manifest.Path = path.Join(o.ConfigBase, name, triggermesh.ManifestFile)

cmd/create/cmd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"github.com/triggermesh/tmctl/pkg/triggermesh/crd"
3131
)
3232

33-
type CreateOptions struct {
33+
type createOptions struct {
3434
ConfigBase string
3535
Context string
3636
Version string
@@ -39,7 +39,7 @@ type CreateOptions struct {
3939
}
4040

4141
func NewCmd() *cobra.Command {
42-
o := &CreateOptions{}
42+
o := &createOptions{}
4343
createCmd := &cobra.Command{
4444
Use: "create <resource>",
4545
Short: "Create TriggerMesh objects",
@@ -58,7 +58,7 @@ func NewCmd() *cobra.Command {
5858
return createCmd
5959
}
6060

61-
func (o *CreateOptions) initialize() {
61+
func (o *createOptions) initialize() {
6262
o.ConfigBase = path.Dir(viper.ConfigFileUsed())
6363
o.Context = viper.GetString("context")
6464
o.Version = viper.GetString("triggermesh.version")
@@ -94,7 +94,7 @@ func argsToMap(args []string) map[string]string {
9494
return result
9595
}
9696

97-
func (o *CreateOptions) translateEventSource(eventSourcesFilter []string) ([]string, error) {
97+
func (o *createOptions) translateEventSource(eventSourcesFilter []string) ([]string, error) {
9898
var result []string
9999
for _, source := range eventSourcesFilter {
100100
s, err := components.GetObject(source, o.CRD, o.Version, o.Manifest)

cmd/create/completion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/triggermesh/tmctl/pkg/triggermesh/crd"
2828
)
2929

30-
func (o *CreateOptions) sourcesCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
30+
func (o *createOptions) sourcesCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
3131
if len(args) == 0 {
3232
sources, err := crd.ListSources(o.CRD)
3333
if err != nil {
@@ -100,7 +100,7 @@ func (o *CreateOptions) sourcesCompletion(cmd *cobra.Command, args []string, toC
100100
return append(spec, "--name\tOptional component name."), cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp
101101
}
102102

103-
func (o *CreateOptions) targetsCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
103+
func (o *createOptions) targetsCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
104104
if len(args) == 0 {
105105
targets, err := crd.ListTargets(o.CRD)
106106
if err != nil {

cmd/create/source.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/triggermesh/tmctl/pkg/triggermesh/crd"
3535
)
3636

37-
func (o *CreateOptions) NewSourceCmd() *cobra.Command {
37+
func (o *createOptions) NewSourceCmd() *cobra.Command {
3838
return &cobra.Command{
3939
Use: "source [kind]/[--from-image <image>][--name <name>]",
4040
// Short: "TriggerMesh source",
@@ -86,7 +86,7 @@ func (o *CreateOptions) NewSourceCmd() *cobra.Command {
8686
}
8787
}
8888

89-
func (o *CreateOptions) source(name, kind string, params map[string]string) error {
89+
func (o *createOptions) source(name, kind string, params map[string]string) error {
9090
ctx := context.Background()
9191
broker, err := tmbroker.New(o.Context, o.Manifest.Path)
9292
if err != nil {
@@ -98,7 +98,7 @@ func (o *CreateOptions) source(name, kind string, params map[string]string) erro
9898
}
9999
params["sink.uri"] = "http://host.docker.internal:" + port
100100

101-
s := source.New(name, o.CRD, kind, o.Context, o.Version, params)
101+
s := source.New(name, o.CRD, kind, o.Context, o.Version, params, nil)
102102

103103
secrets, secretsEnv, err := components.ProcessSecrets(s.(triggermesh.Parent), o.Manifest)
104104
if err != nil {
@@ -116,16 +116,17 @@ func (o *CreateOptions) source(name, kind string, params map[string]string) erro
116116
secretsChanged = true
117117
}
118118
}
119-
restart, err := o.Manifest.Add(s)
120-
if err != nil {
121-
return fmt.Errorf("unable to update manifest: %w", err)
122-
}
123119

124120
status, err := s.(triggermesh.Reconcilable).Initialize(ctx, secretsEnv)
125121
if err != nil {
126122
return fmt.Errorf("source initialization: %w", err)
127123
}
128124
s.(triggermesh.Reconcilable).UpdateStatus(status)
125+
126+
restart, err := o.Manifest.Add(s)
127+
if err != nil {
128+
return fmt.Errorf("unable to update manifest: %w", err)
129+
}
129130
log.Println("Starting container")
130131
if _, err := s.(triggermesh.Runnable).Start(ctx, secretsEnv, (restart || secretsChanged)); err != nil {
131132
return err
@@ -134,7 +135,7 @@ func (o *CreateOptions) source(name, kind string, params map[string]string) erro
134135
return nil
135136
}
136137

137-
func (o *CreateOptions) sourceFromImage(name, image string, params map[string]string) error {
138+
func (o *createOptions) sourceFromImage(name, image string, params map[string]string) error {
138139
ctx := context.Background()
139140
broker, err := tmbroker.New(o.Context, o.Manifest.Path)
140141
if err != nil {

cmd/create/target.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"github.com/triggermesh/tmctl/pkg/triggermesh/crd"
3737
)
3838

39-
func (o *CreateOptions) NewTargetCmd() *cobra.Command {
39+
func (o *createOptions) NewTargetCmd() *cobra.Command {
4040
return &cobra.Command{
4141
Use: "target [kind]/[--from-image <image>][--name <name>][--source <name>,<name>...][--event-types <type>,<type>...]",
4242
// Short: "TriggerMesh target",
@@ -100,7 +100,7 @@ func (o *CreateOptions) NewTargetCmd() *cobra.Command {
100100
}
101101
}
102102

103-
func (o *CreateOptions) target(name, kind string, args map[string]string, eventSourcesFilter, eventTypesFilter []string) error {
103+
func (o *createOptions) target(name, kind string, args map[string]string, eventSourcesFilter, eventTypesFilter []string) error {
104104
ctx := context.Background()
105105

106106
et, err := o.translateEventSource(eventSourcesFilter)
@@ -154,7 +154,7 @@ func (o *CreateOptions) target(name, kind string, args map[string]string, eventS
154154
return nil
155155
}
156156

157-
func (o *CreateOptions) createTrigger(name string, target triggermesh.Component, filter *eventingbroker.Filter) (triggermesh.Component, error) {
157+
func (o *createOptions) createTrigger(name string, target triggermesh.Component, filter *eventingbroker.Filter) (triggermesh.Component, error) {
158158
trigger, err := tmbroker.NewTrigger(name, o.Context, o.ConfigBase, target, filter)
159159
if err != nil {
160160
return nil, err
@@ -168,7 +168,7 @@ func (o *CreateOptions) createTrigger(name string, target triggermesh.Component,
168168
return trigger, nil
169169
}
170170

171-
func (o *CreateOptions) updateTriggers(target triggermesh.Component) error {
171+
func (o *createOptions) updateTriggers(target triggermesh.Component) error {
172172
triggers, err := tmbroker.GetTargetTriggers(target.GetName(), o.Context, o.ConfigBase)
173173
if err != nil {
174174
return fmt.Errorf("target triggers: %w", err)
@@ -182,7 +182,7 @@ func (o *CreateOptions) updateTriggers(target triggermesh.Component) error {
182182
return nil
183183
}
184184

185-
func (o *CreateOptions) targetFromImage(name, image string, params map[string]string, eventSourcesFilter, eventTypesFilter []string) error {
185+
func (o *createOptions) targetFromImage(name, image string, params map[string]string, eventSourcesFilter, eventTypesFilter []string) error {
186186
ctx := context.Background()
187187

188188
et, err := o.translateEventSource(eventSourcesFilter)

cmd/create/transformation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ For more samples please visit:
6161
https://github.com/triggermesh/triggermesh/tree/main/config/samples/bumblebee`
6262
)
6363

64-
func (o *CreateOptions) NewTransformationCmd() *cobra.Command {
64+
func (o *createOptions) NewTransformationCmd() *cobra.Command {
6565
var name, target, file string
6666
var eventSourcesFilter, eventTypesFilter []string
6767
transformationCmd := &cobra.Command{
@@ -94,7 +94,7 @@ func (o *CreateOptions) NewTransformationCmd() *cobra.Command {
9494
return transformationCmd
9595
}
9696

97-
func (o *CreateOptions) transformation(name, target, file string, eventSourcesFilter, eventTypesFilter []string) error {
97+
func (o *createOptions) transformation(name, target, file string, eventSourcesFilter, eventTypesFilter []string) error {
9898
ctx := context.Background()
9999
var targetComponent triggermesh.Component
100100
if target != "" {
@@ -239,7 +239,7 @@ func readInput() (string, error) {
239239
return lines, scn.Err()
240240
}
241241

242-
func (o *CreateOptions) lookupTarget(ctx context.Context, target string) (triggermesh.Component, error) {
242+
func (o *createOptions) lookupTarget(ctx context.Context, target string) (triggermesh.Component, error) {
243243
targetObject, err := components.GetObject(target, o.CRD, o.Version, o.Manifest)
244244
if err != nil {
245245
return nil, fmt.Errorf("transformation target: %w", err)

cmd/create/trigger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
tmbroker "github.com/triggermesh/tmctl/pkg/triggermesh/components/broker"
2929
)
3030

31-
func (o *CreateOptions) NewTriggerCmd() *cobra.Command {
31+
func (o *createOptions) NewTriggerCmd() *cobra.Command {
3232
var name, target string
3333
var eventSourcesFilter, eventTypesFilter []string
3434
triggerCmd := &cobra.Command{
@@ -61,7 +61,7 @@ func (o *CreateOptions) NewTriggerCmd() *cobra.Command {
6161
return triggerCmd
6262
}
6363

64-
func (o *CreateOptions) trigger(name string, eventSourcesFilter, eventTypesFilter []string, target string) error {
64+
func (o *createOptions) trigger(name string, eventSourcesFilter, eventTypesFilter []string, target string) error {
6565
et, err := o.translateEventSource(eventSourcesFilter)
6666
if err != nil {
6767
return err

cmd/delete/delete.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
"github.com/triggermesh/tmctl/pkg/triggermesh/crd"
4040
)
4141

42-
type DeleteOptions struct {
42+
type deleteOptions struct {
4343
ConfigBase string
4444
Context string
4545
Version string
@@ -48,7 +48,7 @@ type DeleteOptions struct {
4848
}
4949

5050
func NewCmd() *cobra.Command {
51-
o := &DeleteOptions{}
51+
o := &deleteOptions{}
5252
var broker string
5353
deleteCmd := &cobra.Command{
5454
Use: "delete <component_name_1, component_name_2...> [--broker <name>]",
@@ -76,7 +76,7 @@ func NewCmd() *cobra.Command {
7676
return deleteCmd
7777
}
7878

79-
func (o *DeleteOptions) initialize() {
79+
func (o *deleteOptions) initialize() {
8080
o.ConfigBase = path.Dir(viper.ConfigFileUsed())
8181
o.Context = viper.GetString("context")
8282
o.Version = viper.GetString("triggermesh.version")
@@ -90,7 +90,7 @@ func (o *DeleteOptions) initialize() {
9090
_ = o.Manifest.Read()
9191
}
9292

93-
func (o *DeleteOptions) deleteBroker(broker string) error {
93+
func (o *deleteOptions) deleteBroker(broker string) error {
9494
oo := *o
9595
oo.Context = broker
9696
oo.Manifest = manifest.New(path.Join(oo.ConfigBase, broker, triggermesh.ManifestFile))
@@ -108,7 +108,7 @@ func (o *DeleteOptions) deleteBroker(broker string) error {
108108
return nil
109109
}
110110

111-
func (o *DeleteOptions) deleteComponents(names []string, deleteBroker bool) error {
111+
func (o *deleteOptions) deleteComponents(names []string, deleteBroker bool) error {
112112
ctx := context.Background()
113113
client, err := docker.NewClient()
114114
if err != nil {
@@ -143,13 +143,13 @@ func (o *DeleteOptions) deleteComponents(names []string, deleteBroker bool) erro
143143
return nil
144144
}
145145

146-
func (o *DeleteOptions) deleteEverything(ctx context.Context, object kubernetes.Object, client *client.Client) {
146+
func (o *deleteOptions) deleteEverything(ctx context.Context, object kubernetes.Object, client *client.Client) {
147147
log.Printf("Deleting %q %s", object.Metadata.Name, strings.ToLower(object.Kind))
148148
if object.Kind == tmbroker.BrokerKind {
149149
object.Metadata.Name = object.Metadata.Name + "-broker"
150150
}
151-
if err := o.removeExternalServices(ctx, object); err != nil {
152-
log.Printf("WARN: external services are not deleted: %v", err)
151+
if err := o.removeExternalServices(ctx, object); err != nil && !strings.HasPrefix(err.Error(), "Unsubscribed from topic") {
152+
log.Printf("WARNING: external services are not deleted: %v", err)
153153
}
154154
// not all components are runnable, but removeContainer should try to stop it anyway
155155
_ = o.removeContainer(ctx, object.Metadata.Name, client)
@@ -158,7 +158,7 @@ func (o *DeleteOptions) deleteEverything(ctx context.Context, object kubernetes.
158158
o.cleanupSecrets(object.Metadata.Name)
159159
}
160160

161-
func (o *DeleteOptions) removeObject(component string) {
161+
func (o *deleteOptions) removeObject(component string) {
162162
for _, object := range o.Manifest.Objects {
163163
if component != object.Metadata.Name {
164164
continue
@@ -179,11 +179,11 @@ func (o *DeleteOptions) removeObject(component string) {
179179
}
180180
}
181181

182-
func (o *DeleteOptions) removeContainer(ctx context.Context, name string, client *client.Client) error {
182+
func (o *deleteOptions) removeContainer(ctx context.Context, name string, client *client.Client) error {
183183
return docker.ForceStop(ctx, name, client)
184184
}
185185

186-
func (o *DeleteOptions) cleanupTriggers(target string) {
186+
func (o *deleteOptions) cleanupTriggers(target string) {
187187
triggers, err := tmbroker.GetTargetTriggers(target, o.Context, o.ConfigBase)
188188
if err != nil {
189189
return
@@ -199,7 +199,7 @@ func (o *DeleteOptions) cleanupTriggers(target string) {
199199
}
200200
}
201201

202-
func (o *DeleteOptions) cleanupSecrets(component string) {
202+
func (o *deleteOptions) cleanupSecrets(component string) {
203203
for _, object := range o.Manifest.Objects {
204204
if object.Metadata.Name == component+"-secret" && object.Kind == "Secret" {
205205
if err := o.Manifest.Remove(object.Metadata.Name, object.Kind); err != nil {
@@ -209,7 +209,7 @@ func (o *DeleteOptions) cleanupSecrets(component string) {
209209
}
210210
}
211211

212-
func (o *DeleteOptions) removeExternalServices(ctx context.Context, object kubernetes.Object) error {
212+
func (o *deleteOptions) removeExternalServices(ctx context.Context, object kubernetes.Object) error {
213213
component, err := components.GetObject(object.Metadata.Name, o.CRD, o.Version, o.Manifest)
214214
if err != nil {
215215
return err
@@ -229,7 +229,7 @@ func (o *DeleteOptions) removeExternalServices(ctx context.Context, object kuber
229229
return r.Finalize(ctx, secretsEnv)
230230
}
231231

232-
func (o *DeleteOptions) switchContext() error {
232+
func (o *deleteOptions) switchContext() error {
233233
list, err := brokers.List(o.ConfigBase, o.Context)
234234
if err != nil {
235235
return fmt.Errorf("list brokers: %w", err)
@@ -243,7 +243,7 @@ func (o *DeleteOptions) switchContext() error {
243243
return viper.WriteConfig()
244244
}
245245

246-
func (o *DeleteOptions) deleteCompletion(cmd *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
246+
func (o *deleteOptions) deleteCompletion(cmd *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
247247
if len(args) == 0 {
248248
return append(completion.ListAll(o.Manifest), "--broker"),
249249
cobra.ShellCompDirectiveNoFileComp

cmd/describe/describe.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ const (
4444
offlineColorCode = "\u001b[31m"
4545
)
4646

47-
type DescribeOptions struct {
47+
type describeOptions struct {
4848
ConfigBase string
4949
CRD string
5050
Version string
5151
Manifest *manifest.Manifest
5252
}
5353

5454
func NewCmd() *cobra.Command {
55-
o := &DescribeOptions{}
55+
o := &describeOptions{}
5656
return &cobra.Command{
5757
Use: "describe [broker]",
5858
Short: "Show broker status",
@@ -78,7 +78,7 @@ func NewCmd() *cobra.Command {
7878
}
7979
}
8080

81-
func (o DescribeOptions) describe(b string) error {
81+
func (o *describeOptions) describe(b string) error {
8282
broker := tabwriter.NewWriter(os.Stdout, 10, 5, 5, ' ', 0)
8383
triggers := tabwriter.NewWriter(os.Stdout, 10, 5, 5, ' ', 0)
8484
producers := tabwriter.NewWriter(os.Stdout, 10, 5, 5, ' ', 0)

0 commit comments

Comments
 (0)