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

feat(cmd/run): resource option refactoring #2355

Merged
merged 20 commits into from
Jun 16, 2021

Conversation

squakez
Copy link
Contributor

@squakez squakez commented Jun 3, 2021

With this PR we are refactoring the original --resource flag to behave similarly of what we've done with --config.

kamel run --resource [configmap|secret|file]:resourceName[/key][@/path/to/destination]

We are also refactoring the --config flag to include the possiblity to specify /key when using a secret/configmap.

The difference is that the --resource will allow the user to provide any kind of file (also binary files) and those files won't be considered as properties file by the Integration runtime.

  • Added support for Configmaps and Secrets
  • Mantained compatibility with --resource /path/to/file (though, it is marked as deprecated for future removal)
  • Support for @/path/ to let the user chose where the resource (file, secret or configmaps) will be mounted
  • Modeline support verified
  • File size limitation to 1MB introduced
  • Support for all local file synchronization
  • Possibility to filter a secret/configmap key both in --resource and --configmap
  • Updated CRDs to specify resources type (config or resource), resource key selection and destination path
  • Examples
  • E2E integration tests

Closes #2003
Closes #1831
Closes #1534
Closes #1533

Release Note

feat(cmd/run): resource option refactoring 

* Added support to specify a single key from a configmap/secret in --resource or --config flag
* Refactoring the RunConfigOption struct to include the new feature and hide the complexity to usage

Ref apache#2003
@heiko-braun
Copy link

Good work @squakez !


for _, entry := range entries {
if entry.Type == configurationType {
var item = make(map[string]string)
Copy link
Member

Choose a reason for hiding this comment

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

Probably you could have used the entry struct type instead of map, but it's ok

Copy link
Member

@nicolaferraro nicolaferraro left a comment

Choose a reason for hiding this comment

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

Looks good, should we merge it?

@squakez
Copy link
Contributor Author

squakez commented Jun 14, 2021

Looks good, should we merge it?

Thanks for reviewing! Yes, you can proceed, I am already working on the documentation.

@nicolaferraro
Copy link
Member

Looks good, should we merge it?

Thanks for reviewing! Yes, you can proceed, I am already working on the documentation.

I let @astefanutti do it since he said he was having a look..

@astefanutti
Copy link
Member

Let me do a quick round of review 👍🏼.

Copy link
Member

@astefanutti astefanutti left a comment

Choose a reason for hiding this comment

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

Please find below a couple of points. These may rather be questions or comments, that can possibly be addressed subsequently:

  • I find it a bit hard to reason about the API, we have:

    resources:
      compression
      content
      contentKey
      contentRef
      contentType
      mountPath
      name
      path
      rawContent
      type
    

    and:

    configuration:
      resourceKey
      resourceMountPoint
      resourceType
      type
      value
    

    Do you think this could be improved, e.g., use more consistent name (mountPath vs resourceMountPoint), limit possible values with +kubebuilder:validation:Enum, add documentation, ...

  • For the option value, the format is [configmap|secret|file]:resourceName[/key]: I would find path instead of resourceName a bit more coherent between ConfigMap/Secret and file, mentioning that the path can be name/key for the former. Also, I wonder, should it be documented that the ConfigMap / Secret is implicitly located in the current namespace?

  • Could the --property option be merged with the --config option, to be symmetrical with the --resource option?

  • Should the documentation be updated according to the new CLI options: https://camel.apache.org/camel-k/latest/configuration/configmap-secret.html?

  • For the Integration container layout, I understand that the directories prefixed with _ are application configuration resources, and that this is inherited from the runtime, right? Should we mirror that layout for plain resources? I find adding that extra data directory not adding much meaning.

docs/modules/ROOT/pages/cli/modeline.adoc Outdated Show resolved Hide resolved
docs/modules/ROOT/pages/cli/modeline.adoc Outdated Show resolved Hide resolved
@squakez
Copy link
Contributor Author

squakez commented Jun 15, 2021

Please find below a couple of points. These may rather be questions or comments, that can possibly be addressed subsequently:

* I find it a bit hard to reason about the API, we have:
  ```
  resources:
    compression
    content
    contentKey
    contentRef
    contentType
    mountPath
    name
    path
    rawContent
    type
  ```    
  and:
  ```
  configuration:
    resourceKey
    resourceMountPoint
    resourceType
    type
    value
  ```
  Do you think this could be improved, e.g., use more consistent name (`mountPath` vs `resourceMountPoint`), limit possible values with `+kubebuilder:validation:Enum`, add documentation, ...

Yeah, I had this part in mind as a refactoring tracked in #2320. If you're okey with the approach, we can review your comment as part of that development that I'm planning to do right after #2003 is closed.

* For the option value, the format is `[configmap|secret|file]:resourceName[/key]`: I would find `path` instead of `resourceName` a bit more coherent between ConfigMap/Secret and file, mentioning that the path can be `name/key` for the former. Also, I wonder, should it be documented that the ConfigMap / Secret is implicitly located in the _current_ namespace?

I see your point. I found difficult to show the syntax in the CLI as file won't have key. Any suggestion how to improve that is welcome. About the namespace, there are nice warnings now checking if a cm/secret is not found in the current namespace. The Integration is build, but the CLI will report it.

* Could the `--property` option be merged with the `--config` option, to be symmetrical with the `--resource` option?

I think they have a different meaning. The --property won't generate a file per se, but will be appended to a generated user.properties file. Both --config and --resource will be expected to generate a file on the Integration. A --config could be parsed by the runtime, whilst a --resource won't.

* Should the documentation be updated according to the new CLI options: https://camel.apache.org/camel-k/latest/configuration/configmap-secret.html?

Worry not, another PR is ready with examples and full documentation... I did not want to have this PR larger than it is now!

* For the Integration container layout, I understand that the directories prefixed with `_` are application configuration resources, and that this is inherited from the runtime, right? Should we mirror that layout for plain resources? I find adding that extra `data` directory not adding much meaning.

So, this would be the final tree expected on the Integration:

/etc/camel/sources --> will contain sources

/etc/camel/conf.d --> will contain configuration provided by user
/etc/camel/conf.d/_resources/ --> --config file:
/etc/camel/conf.d/_secrets/ --> --config secret:
/etc/camel/conf.d/_configmaps/ --> --config configmap:   
            
/etc/camel/data --> default location for data provided by the user 
/etc/camel/data/resources/ --> --resource file:
/etc/camel/data/secrets/ --> --resource secret:
/etc/camel/data/configmaps/ --> --resource configmap:

The conf.d is something the final user should ignore at all and it's what is expected by the runtime logic. In fact, I added a validation to avoid any user tampering those directories when using the path feature. The data directory is something that the user may be able to use in his integrations, as this is the default location when the path is not specified in the --resource option. Now, I thought that data can be easily understood by the audience, as well as using an _ in the path may be cumbersome. The new structure will be also explained in the documentation. We can think to have a different directory for what is now called data, I don't have preferences, however, I'd avoid the usage of _.

@astefanutti
Copy link
Member

Please find below a couple of points. These may rather be questions or comments, that can possibly be addressed subsequently:

* I find it a bit hard to reason about the API, we have:

resources:
compression
content
contentKey
contentRef
contentType
mountPath
name
path
rawContent
type

and:

configuration:
resourceKey
resourceMountPoint
resourceType
type
value

Do you think this could be improved, e.g., use more consistent name (`mountPath` vs `resourceMountPoint`), limit possible values with `+kubebuilder:validation:Enum`, add documentation, ...

Yeah, I had this part in mind as a refactoring tracked in #2320. If you're okey with the approach, we can review your comment as part of that development that I'm planning to do right after #2003 is closed.

Great, sounds good. The sooner the better to avoid dealing with backward compatibility.

* For the option value, the format is `[configmap|secret|file]:resourceName[/key]`: I would find `path` instead of `resourceName` a bit more coherent between ConfigMap/Secret and file, mentioning that the path can be `name/key` for the former. Also, I wonder, should it be documented that the ConfigMap / Secret is implicitly located in the _current_ namespace?

I see your point. I found difficult to show the syntax in the CLI as file won't have key. Any suggestion how to improve that is welcome. About the namespace, there are nice warnings now checking if a cm/secret is not found in the current namespace. The Integration is build, but the CLI will report it.

I cannot think of a one-size-fits-all solution, but the following may be other ways:

  • [configmap|secret|file]:path, where path can be name/key for ConfigMap / Secret
  • [configmap|secret|file]:nameOrPath[/key]
* Could the `--property` option be merged with the `--config` option, to be symmetrical with the `--resource` option?

I think they have a different meaning. The --property won't generate a file per se, but will be appended to a generated user.properties file. Both --config and --resource will be expected to generate a file on the Integration. A --config could be parsed by the runtime, whilst a --resource won't.

Ah right. The --property file: syntax seems to overlap the --config file.

* Should the documentation be updated according to the new CLI options: https://camel.apache.org/camel-k/latest/configuration/configmap-secret.html?

Worry not, another PR is ready with examples and full documentation... I did not want to have this PR larger than it is now!

👍🏼

* For the Integration container layout, I understand that the directories prefixed with `_` are application configuration resources, and that this is inherited from the runtime, right? Should we mirror that layout for plain resources? I find adding that extra `data` directory not adding much meaning.

So, this would be the final tree expected on the Integration:

/etc/camel/sources --> will contain sources

/etc/camel/conf.d --> will contain configuration provided by user
/etc/camel/conf.d/_resources/ --> --config file:
/etc/camel/conf.d/_secrets/ --> --config secret:
/etc/camel/conf.d/_configmaps/ --> --config configmap:   
            
/etc/camel/data --> default location for data provided by the user 
/etc/camel/data/resources/ --> --resource file:
/etc/camel/data/secrets/ --> --resource secret:
/etc/camel/data/configmaps/ --> --resource configmap:

The conf.d is something the final user should ignore at all and it's what is expected by the runtime logic. In fact, I added a validation to avoid any user tampering those directories when using the path feature. The data directory is something that the user may be able to use in his integrations, as this is the default location when the path is not specified in the --resource option. Now, I thought that data can be easily understood by the audience, as well as using an _ in the path may be cumbersome. The new structure will be also explained in the documentation. We can think to have a different directory for what is now called data, I don't have preferences, however, I'd avoid the usage of _.

Actually, I would rather get rid of the _ also in conf.d, but my understanding is that it requires changes into the runtime, does it?

For data, I was thinking to get rid of that extra level, that is /etc/camel/resources, /etc/camel/configmaps, ... I think even having a single /etc/camel/resources directory would be better. The likelihood of having conflicts is seldom.

@astefanutti astefanutti added area/cli Kamel CLI area/core Core features of the integration platform labels Jun 15, 2021
@squakez
Copy link
Contributor Author

squakez commented Jun 16, 2021

@astefanutti I've just committed 20b770c to include a clearer option description and to use a single resource directory. If we merge this, I will provide a newer PR with the full documentation. Thanks!

@astefanutti
Copy link
Member

@squakez great, thanks. Let's merge it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli Kamel CLI area/core Core features of the integration platform
Projects
None yet
5 participants