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

Create Asset Generation CLI Enhancement #214

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

JonahSussman
Copy link

No description provided.

Signed-off-by: JonahSussman <[email protected]>
@JonahSussman JonahSussman force-pushed the JonahSussman-patch-2 branch 3 times, most recently from 9a9ce03 to a8e6c48 Compare January 20, 2025 20:07
Signed-off-by: JonahSussman <[email protected]>
Copy link

@gciavarrini gciavarrini left a comment

Choose a reason for hiding this comment

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

I took a look at this draft PR to start getting familiar with your idea for implementing the CLI. Some questions 😀

Comment on lines +54 to +55
We propose modifying the existing Kantra CLI instead of developing an entirely
new CLI to ensure a smoother adoption process for users. Leveraging Kantra's

Choose a reason for hiding this comment

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

For phase 1, integration into existing MTA/Kantra CLI was set as non-goal. The idea, if I'm not wrong, is to be independent to other projects to deliver faster the 1st phase.
Do you think that having a simple CLI for the phase 1 will overcomplicate a future integration?

Copy link
Author

Choose a reason for hiding this comment

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

The approach I'm envisioning is to integrate with the existing Kantra from the beginning to ensure we can deliver value to customers more quickly, as they already will have Kantra vetting in their security processes.

The core functionality will be implemented as a standalone Go library, which will serve as the foundation for this enhancement. This ensures that the Kantra integration remains a thin frontend layer while keeping the library modular and reusable for future projects.

- Create a standalone library for integration with other tools and workflows.
- Extend Kantra to support:
- `discover` command: Output a YAML/JSON representation of Cloud Foundry resources.
- `generate` command: Produce Helm charts for deployment to Kubernetes.

Choose a reason for hiding this comment

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

I think generate can produce values.yaml (generated from the canonical form) and an example helm template. That helm template will need to be tuned by the user.
It's too complex to generate decent helm charts.

- `generate`: This command takes a canonical representation and a Helm
template to produce deployment-ready Helm charts. Details:
- **Flags and Options:**
- `--input=<file>` (required): Specifies the canonical configuration file

Choose a reason for hiding this comment

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

I'd like to have the option to provide a CF manifest as input. IMO, This will be useful if a user provides the CF manifest directly, for testing purposes and during the development.

Copy link
Author

Choose a reason for hiding this comment

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

I think this overlaps with the purpose of the canonical configuration. The idea is that the users wouldn't need to rely on the original platforms input formats once it is generated.

Is there a specific use case you're thinking that the canonical config doesn't cover for generate?

Comment on lines +143 to +144
- Implement the core functionality as a standalone library in Go for reuse in
Kantra and other projects.

Choose a reason for hiding this comment

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

Can you clarify this? It seems different from the Motivation section

Copy link
Author

Choose a reason for hiding this comment

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

The idea is that the Kantra CLI will use the library, but other projects can use the library as well if they want to

Signed-off-by: Savitha Raghunathan <[email protected]>
disk), and deployment settings.
- **Error Handling:**
- Detect and report missing or malformed input files with detailed error messages.
- Provide retry options for transient errors during discovery.

Choose a reason for hiding this comment

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

This could be addressed by the user by evaluating the exit code and retrying when it's not 0. I think adding a retry logic is a complexity we might want to avoid as it adds burden to our cli when it does not guarantee it solves the problem.

application name, instances, routes), runtime information (e.g., memory,
disk), and deployment settings.
- **Error Handling:**
- Detect and report missing or malformed input files with detailed error messages.

Choose a reason for hiding this comment

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

What do you have in mind? a structured error output? or just free text as error? Should the CLI exit when an error occurs or do you think it should consolidate all the errors and output them together as well as any generated file?

enhancements/assets-generation/cli/README.md Show resolved Hide resolved
enhancements/assets-generation/cli/README.md Show resolved Hide resolved
enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved
- Validates the generated artifacts for completeness and correctness.
- **Error Handling:**
- Log errors when applying Helm templates.
- Support a dry-run mode to identify potential issues without generating artifacts.

Choose a reason for hiding this comment

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

Do we need to allow server side checks when generating non-yaml/json templates, such as Dockerfile or EAP xml configuration files?

Copy link
Author

Choose a reason for hiding this comment

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

I don't think I understand. Could you phrase it differently?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jordigilh that would mean writing some custom validators. XML should be quite straightforward as we have XSD schemas, but other files such a Dockerfile would be a bit trickier. Sounds like a nice to have for further iterations, but I'd move forward without it for the moment.

Choose a reason for hiding this comment

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

Sounds good.

Kubernetes.
- Validates the generated artifacts for completeness and correctness.
- **Error Handling:**
- Log errors when applying Helm templates.

Choose a reason for hiding this comment

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

What do you mean by applying Helm templates? Do you think the CLI should render the helm templates? or just render the non-yaml/json templates?

Copy link
Author

@JonahSussman JonahSussman Jan 29, 2025

Choose a reason for hiding this comment

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

I should be more specific. The errors encountered in the generation step, whether that be from helm generators or others, should be logged via the CLI. WDYT?

Choose a reason for hiding this comment

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

Sounds good.

enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved
enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved
enhancements/assets-generation/cli/README.md Show resolved Hide resolved
savitharaghunathan and others added 2 commits January 23, 2025 12:05
Signed-off-by: Savitha Raghunathan <[email protected]>
enhancements/assets-generation/cli/README.md Show resolved Hide resolved

- Create a standalone library for integration with other tools and workflows.
- Extend Kantra to support:
- `discover` command: Output a YAML/JSON representation of Cloud Foundry resources.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should discovery be used for gathering platform info rather than output? It mentions here output of CF resources, but maybe that could be another step after discovery? (e.g. discovery -> runOutPut(?) -> generate). wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

is there a reason we would need an intermediate step? Right now the discovery command is defaulting to standard out and provides an option to write to a file.

enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved
enhancements/assets-generation/cli/README.md Show resolved Hide resolved
enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved
Kubernetes.
- Validates the generated artifacts for completeness and correctness.
- **Error Handling:**
- Log errors when applying Helm templates.
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be nice send helm-specific logs/errors to a log, and keep the cli errors separate.

Choose a reason for hiding this comment

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

If we provide structured logs, that should be an easy task to filter.


- Handling of sensitive resource data, such as secrets, is explicitly out of
scope for this CLI. Instead, we will rely on Konveyor's secure encryption
stores, which users already use with Konveyor.
Copy link
Contributor

Choose a reason for hiding this comment

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

Encryption should be outside the scope of the CLI. However, the CF provider in the CLI is the only thing that understands CF and can identify which values are sensitive. Thinking the canonical manifest (schema) should have a secrets section. When the CLI identifies a sensitive value, it would add an entry to the secrets section containing the sensitive data. The sensitive value would be replace with a reference to the secret.

For example (something like):
CF manifest

password: ABC

canonical manifest:

application:
  password: $(password)
secrets:
 - name: password
 - value: ABC

When the manifest is stored in konveyor, the secret values could be encrypted.

Naming is for example.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jordigilh @gciavarrini is this something we can add to #215 ? Have we identified anything sensitive in the CF spec that should be stored encrypted in the hub in subsequent iterations?

Copy link

@jordigilh jordigilh Feb 7, 2025

Choose a reason for hiding this comment

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

CF app manifest exposes the docker username as a field in the spec. I would consider that to be sensitive data. Right now we're capturing it as a field in the canonical form, but we can follow on what @jortel suggest and store it in a separate section, although it would be stored in a clear format. Let me know if that works for you and I'll update both the logic in the discovery and the enhancement.

Throughout our research on CF, we've seen across a few examples where credentials (username + password) were injected as environment variables in the parameter field of the service in free text format (k/v) for registering services. The value can be structured (json) but it's dependant on the target service and we would not be able to parse and extract the information in all cases. I would suggest to let the users clean up the values after the canonical form is generated to suit their deployment needs for their cases, since the service registration in CF does not follow the same pattern as in K8S services.

@jortel
Copy link
Contributor

jortel commented Jan 27, 2025

Can we add an example: --help output so we can see the proposed/consolidated subcommands and options.
Seeing the big picture would help.

charts). The enhancement will provide a foundational capability for platform
migrations, enabling a tech-preview release in an upcoming version of Kantra and
integration into downstream workflows.

Copy link

Choose a reason for hiding this comment

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

@JonahSussman ,
How would that scale in case we have many applications with same/overlapping run time requirements?
Also. would we check on Kubernetes side whether the required resources are there, and in this case no asset generation will be required?

Copy link
Member

Choose a reason for hiding this comment

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

@istein1 We will be mapping the canonical values to the helm template provided by the user. Any validation and verification of generated assets/manifests are out of scope for this MVP.

overall workflow for existing users already familiar with the tool. To achieve
modularity and maintainability, we will create a standalone library of
functionality to which the CLI will serve as a frontend, allowing for future
integration with other tools and workflows.
Copy link

Choose a reason for hiding this comment

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

Hi @JonahSussman , @savitharaghunathan , What CLI would the new standalone library for asset generation and platform awareness work with ? Containerized CLI or Containerless CLI ?

Copy link

Choose a reason for hiding this comment

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

This does not use analysis; so it's not a matter of containerless vs container CLI in this context. These are new commands.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a valid question though, do we expect to require a container runtime for these new capabilities to execute? I would say we need to avoid that as much as possible. It is important that these new capabilities can be executed in a Tekton Pipeline.

Choose a reason for hiding this comment

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

No, no containers should be executed. Sorry for the confusion

enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved
enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved
enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved
overall workflow for existing users already familiar with the tool. To achieve
modularity and maintainability, we will create a standalone library of
functionality to which the CLI will serve as a frontend, allowing for future
integration with other tools and workflows.
Copy link

Choose a reason for hiding this comment

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

This does not use analysis; so it's not a matter of containerless vs container CLI in this context. These are new commands.

enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved
enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved
- Create a standalone library for integration with other tools and workflows.
- Extend Kantra to support:
- `discover` command: Output a YAML/JSON representation of Cloud Foundry resources.
- `generate` command: Produce Helm charts for deployment to Kubernetes. For the mvp,
Copy link

Choose a reason for hiding this comment

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

Based on my new understanding of how this works; I wonder if we should instead call this render? Under the hood we are essentially passing in a location to a helm chart and rendering the templates. I don't know; I originally liked generate

Copy link
Member

Choose a reason for hiding this comment

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

did we decide on the naming? @dymurray

Choose a reason for hiding this comment

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

discovery manifest I think is what we agreed upon

Copy link
Member

Choose a reason for hiding this comment

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

@dymurray ack. For the command, are we good with generate ?

enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved
- `generate` command: Produce Helm charts for deployment to Kubernetes. For the mvp,
the we will generate a values.yaml file based on the CF discovery manifest,
and combine it with the user's templates to generate a helm chart
- Utilize the [canonical configuration enhancement](link: TODO) to serve as a consistent
Copy link

Choose a reason for hiding this comment

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

The more I understand about this; there is no "canonical config". discover spits out a values.yaml and the user puts that into their helm chart; then calls generate with a path to a helm chart where the templates get rendered.

Copy link
Contributor

Choose a reason for hiding this comment

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

There shouldn't be a need for the user to put the values file in the chart. That should be an input parameter for the CLI, and it will make sure it is passed correctly to the templating engine. Users shouldn't have to move files around for this to work.

enhancements/assets-generation/cli/README.md Outdated Show resolved Hide resolved

- `generate`: This command takes a canonical representation and a Helm
template to produce deployment-ready Helm charts. Details:
- **Flags and Options:**
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add some additional options here. I just want to convey the functionality, I'm open to changes in names and format:

  • --set key=value: Sets a value for the given in the command line. If the key already exists in the values file that was passed, it will override its value.
  • --non-k8s-only: Only renders the non-k8s templates available in the files/konveyor path from the target Helm Chart.

Copy link
Member

Choose a reason for hiding this comment

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

--set key=value: Sets a value for the given in the command line. If the key already exists in the values file that was passed, it will override its value.

@rromannissen - this will override the value for the key in discovery manifest, which in turn will override the values.yaml file in the given helm template. is that correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not really. The discovery manifest and the values.yaml file would remain the same, but when rendering the value of the given key would be overridden by the given value. This is similar to the --set flag from the helm template command.

Copy link
Member

Choose a reason for hiding this comment

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

I updated the flags. Thanks @rromannissen for the clarification

- Validates the generated artifacts for completeness and correctness.
- **Error Handling:**
- Log errors when applying Helm templates.
- Support a dry-run mode to identify potential issues without generating artifacts.
Copy link
Contributor

Choose a reason for hiding this comment

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

@jordigilh that would mean writing some custom validators. XML should be quite straightforward as we have XSD schemas, but other files such a Dockerfile would be a bit trickier. Sounds like a nice to have for further iterations, but I'd move forward without it for the moment.

@dymurray dymurray changed the title [DRAFT] Create Asset Generation CLI Enhancement Create Asset Generation CLI Enhancement Feb 6, 2025
@dymurray dymurray marked this pull request as ready for review February 6, 2025 15:44
Copy link
Contributor

@rromannissen rromannissen left a comment

Choose a reason for hiding this comment

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

LGTM after the changes, I think we are ready to start implementation.

Copy link

@dymurray dymurray 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 to me, the naming updates are fine by me once we all agree upon it.

supports helm. Defaults to `Helm`
- `--set key=value` (optional): Sets a value for the given in the command line.
If the key already exists in the values file that was passed, it will override its value.
- `--non-k8s-only` (optional): Only renders the non-k8s templates available in the files/konveyor

Choose a reason for hiding this comment

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

How does this flag work when the type generator is not helm? We know that for helm we will have to render the files from a directory inside the helm chart, but is that also applicable for other template engines? To me this flag is helm specific and it's being exposed at the same level as the template engine flag.
Maybe the type value should be a command instead of a flag?

kantra generate helm --template ./ --output-dir /tmp --non-k8s-only

and then if we were to use ansible:

kantra generate ansible --playbook ./ --output-dir /tmp 

It looks cleaner since the flags specific for helm (template) are not applicable to ansible (playbook for instance).
WDYT?

specified platform and generating a canonical representation in YAML
format. Details:
- **Flags and Options:**
- `--platform=<platform>` (required): Specifies the platform to discover.

Choose a reason for hiding this comment

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

Same thing here: PCF applications might require to pass specific arguments to enable discovery (e.g. performing discovery over live platform). I suggest to turn this flag as a subcommand to allow specifying flags per platform:

$> kantra discover cloud-foundry --use-live-connection --username <username> --password <password> --server-url https://localhost:8443

Common flags can remain as part of the discovery command, but specific ones will fall into each sub-command/platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants