Skip to content

Error when current namespace is null in config #335

@ThomasCAI-mlv

Description

@ThomasCAI-mlv

Describe the bug

When the current namespace defined in the config file is null:

kafkactl:
  current-namespace: null
  api: http://localhost:8080
  user-token: xxxx

any command line (even trying to switch context) will result in the following error message:

Exception in thread "main" picocli.CommandLine$InitializationException: Could not instantiate class com.michelin.kafkactl.util.VersionProvider: io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for parameter [currentNamespace] of method [setCurrentNamespace] of class: com.michelin.kafkactl.property.KafkactlProperties

Message: Failed to inject value for parameter [currentNamespace] of method [setCurrentNamespace] of class: com.michelin.kafkactl.property.KafkactlProperties

Message: Error resolving property value [kafkactl.current-namespace]. Property doesn't exist
Path Taken:
new @j.i.Singleton c.m.k.u.VersionProvider()
\---> @j.i.Singleton c.m.k.u.VersionProvider#kafkactlProperties
      \---> @i.m.c.a.ConfigurationProperties("kafkactl") c.m.k.p.KafkactlProperties#setCurrentNamespace([String currentNamespace])

To Reproduce

Steps to reproduce the behavior:

  1. Create ~HOME/.kafkactl/config.yml with a context without namespace like
  contexts:
  - name: test
    context:
      api: http://localhost:8080
      user-token: xxxx
  1. Switch to that context with kafkactl config use-context test
  2. Try any command line like kafkactl get to or kafkactl get to -n <myNamespace>
  3. See error

Expected behavior

  • kafkactl get to should result in an explicit error like "No namespace set"
  • kafkactl get to -n <myNamespace> should result in the correct topics listing
  • kafkactl config use-context goodContext should switch context

Environment

  • Kafkactl distribution: N/A
  • Ns4Kafka version: N/A

Steps taken to try and solve the problem

Without the field current-namespace in the config file

kafkactl:
  api: http://localhost:8080
  user-token: xxxx

kafkactl behaviour is normal.

2 fixes might be needed:

  • The kafkactl config use-context on a context without namespace should not initialize a "current-namespace" field
  • If the current-namespace is set to null, kafkactl should still work when setting a namespace in the command line

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions