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

Asset generation discover and generate commands #435

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
.idea/

env.local

vendor/
**/coverage/*
**/ginkgo.report
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,18 @@ podman machine init <vm_name>

## Usage

Kantra has three subcommands:
Kantra has five subcommands:

1. _analyze_: This subcommand allows running source code analysis on input source code or a binary.

2. _transform_: This subcommand allows either converting XML rules to YAML or running OpenRewrite recipes on source code.

3. _test_: This subcommand allows testing YAML rules.

4. _discover_: This subcommand allows to discover application and outputs a YAML representation of source platform resources.

5. _generate_: This subcommand allora to analyze the source plaftform and/or application and output a discovery manifest.

### Analyze

_analyze_ subcommand allows running source code and binary analysis using [analyzer-lsp](https://github.com/konveyor/analyzer-lsp)
Expand Down Expand Up @@ -255,6 +259,57 @@ The output of tests is printed on the console.

See different ways to run the test command in the [test runner doc](./docs/testrunner.md#running-tests)

### Asset Generation

Asset generation consist of two subcommands _discover_ and _generate_.

#### Discover
Discover application outputs a YAML representation of source platform resources.

To run a discover, run:

`kantra discover --input=<path/to/yaml/manifest>`

_--input_ must point to a yaml manifest file.


All flags:

```sh
Flags:
-h, --help help for discover
--list-platforms List available supported discovery platform.
```

#### Generate

Analyze the source platform and/or application and output discovery manifest.


To generate a discovery manifest, run:

`kantra generate helm --input=<path/to/discover/manifest> --chart-dir=<path/to/helmchart>`

All flags

```sh
Flags:
-h, --help help for generate
```
_generate_ subcommand has a _helm_ subcommand that generates the helm template manifest.

All flags:

```sh
Flags:
--chart-dir string Directory to the Helm chart to use for chart generation.
-h, --help help for helm
--input string Specifies the discover manifest file
--non-k8s-only Render only the non-Kubernetes templates located in the files/konveyor directory of the chart
--output-dir string Directory to save the generated Helm chart. Defaults to stdout
--set stringArray Set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
```

## References

- [Example usage scenarios](./docs/examples.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cloud_foundry_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestCloudFoundry(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "CloudFoundry Suite")
}
73 changes: 73 additions & 0 deletions cmd/asset_generation/discover/cloud_foundry/discover.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package cloud_foundry

import (
"fmt"
"io"
"os"

discover "github.com/gciavarrini/cf-application-discovery/pkg/discover/cloud_foundry"
"github.com/go-logr/logr"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)

var (
useLive bool
input string
output string
)

func NewDiscoverCloudFoundryCommand(log logr.Logger) (string, *cobra.Command) {

cmd := &cobra.Command{
Aliases: []string{"cf"},
Use: "cloud-foundry",
Short: "Discover Cloud Foundry applications",
PreRunE: func(cmd *cobra.Command, args []string) error {
if err := cmd.ParseFlags(args); err != nil {
return err
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
return discoverManifest(cmd.OutOrStdout())
},
}
cmd.Flags().StringVar(&input, "input", "", "specify the location of the manifest.yaml to analyze.")
cmd.Flags().StringVar(&output, "output", "", "output file (default: standard output).")
cmd.Flags().BoolVar(&useLive, "use-live-connection", false, "uses live platform connections for real-time discovery (not implemented)")
cmd.MarkFlagFilename("input", "yaml", "yml")
cmd.MarkFlagFilename("output")
cmd.MarkFlagRequired("input")

return "Cloud Foundry V3 (local manifest)", cmd
}

func discoverManifest(writer io.Writer) error {
b, err := os.ReadFile(input)
if err != nil {
return err
}

ma := discover.AppManifest{}
err = yaml.Unmarshal(b, &ma)
if err != nil {
return err
}
a, err := discover.Discover(ma, "1", "default")
if err != nil {
return err

}

b, err = yaml.Marshal(a)
if err != nil {
return err

}
if output == "" {
fmt.Fprintf(writer, "%s", b)
return nil
}
return os.WriteFile(output, b, 0444)
}
Loading