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

Add Helm manifest gen #447

Merged
merged 10 commits into from
Aug 26, 2021
Merged
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
64 changes: 64 additions & 0 deletions cmd/cli/cmd/alpha/manifest-gen/implementation/helm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package implementation

import (
"strings"

"capact.io/capact/internal/cli/alpha/manifestgen"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

// NewHelm returns a cobra.Command to bootstrap Helm based manifests.
func NewHelm() *cobra.Command {
var helmCfg manifestgen.HelmConfig

cmd := &cobra.Command{
Use: "helm [MANIFEST_PATH] [HELM_CHART_NAME]",
Short: "Generate Helm chart based manifests",
Long: "Generate Implementation manifests based on a Helm chart",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 2 {
return errors.New("accepts two arguments: [MANIFEST_PATH] [HELM_CHART_NAME]")
}

path := args[0]
if !strings.HasPrefix(path, "cap.implementation.") || len(strings.Split(path, ".")) < 4 {
return errors.New(`manifest path must be in format "cap.implementation.[PREFIX].[NAME]"`)
}

return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
helmCfg.ManifestPath = args[0]
helmCfg.ChartName = args[1]

files, err := manifestgen.GenerateHelmManifests(&helmCfg)
if err != nil {
return errors.Wrap(err, "while generating Helm manifests")
}

outputDir, err := cmd.Flags().GetString("output")
if err != nil {
return errors.Wrap(err, "while reading output flag")
}

overrideManifests, err := cmd.Flags().GetBool("overwrite")
if err != nil {
return errors.Wrap(err, "while reading overwrite flag")
}

if err := manifestgen.WriteManifestFiles(outputDir, files, overrideManifests); err != nil {
return errors.Wrap(err, "while writing manifest files")
}

return nil
},
}

cmd.Flags().StringVarP(&helmCfg.InterfacePathWithRevision, "interface", "i", "", "Path with revision of the Interface, which is implemented by this Implementation")
cmd.Flags().StringVarP(&helmCfg.ManifestRevision, "revision", "r", "0.1.0", "Revision of the Implementation manifest")
cmd.Flags().StringVar(&helmCfg.ChartRepoURL, "repo", "", "URL of the Helm repository")
cmd.Flags().StringVarP(&helmCfg.ChartVersion, "version", "v", "", "Version of the Helm chart")

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func NewCmd() *cobra.Command {
}

cmd.AddCommand(NewTerraform())
cmd.AddCommand(NewHelm())

return cmd
}
10 changes: 5 additions & 5 deletions cmd/cli/cmd/alpha/manifest-gen/implementation/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
"github.com/spf13/cobra"
)

var tfContentCfg manifestgen.TerraformConfig

// NewTerraform returns a cobra.Command to bootstrap Terraform based manifests.
func NewTerraform() *cobra.Command {
var tfContentCfg manifestgen.TerraformConfig

cmd := &cobra.Command{
Use: "terraform [MANIFEST_PATH] [TERRAFORM_MODULE_PATH]",
Short: "Generate Terraform based manifests",
Long: "Generate Terraform based manifests based on a Terraform module",
Long: "Generate Implementation manifests based on a Terraform module",
Example: heredoc.WithCLIName(`
# Generate Implementation manifests
<cli> alpha manifest-gen implementation terraform cap.implementation.aws.rds.deploy ./terraform-modules/aws-rds
Expand Down Expand Up @@ -54,9 +54,9 @@ func NewTerraform() *cobra.Command {
return errors.Wrap(err, "while reading output flag")
}

overrideManifests, err := cmd.Flags().GetBool("override")
overrideManifests, err := cmd.Flags().GetBool("overwrite")
if err != nil {
return errors.Wrap(err, "while overriding existing manifest")
return errors.Wrap(err, "while reading overwrite flag")
}

if err := manifestgen.WriteManifestFiles(outputDir, files, overrideManifests); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cmd/cli/cmd/alpha/manifest-gen/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/spf13/cobra"
)

var interfaceCfg manifestgen.InterfaceConfig

// NewInterface returns a cobra.Command to bootstrap new Interface manifests.
func NewInterface() *cobra.Command {
var interfaceCfg manifestgen.InterfaceConfig

cmd := &cobra.Command{
Use: "interface [PATH]",
Aliases: []string{"iface", "interfaces"},
Expand Down Expand Up @@ -47,9 +47,9 @@ func NewInterface() *cobra.Command {
return errors.Wrap(err, "while reading output flag")
}

overrideManifests, err := cmd.Flags().GetBool("override")
overrideManifests, err := cmd.Flags().GetBool("overwrite")
if err != nil {
return errors.Wrap(err, "while overriding existing manifest")
return errors.Wrap(err, "while reading overwrite flag")
}

if err := manifestgen.WriteManifestFiles(outputDir, files, overrideManifests); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/cmd/alpha/manifest-gen/manifest-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NewCmd() *cobra.Command {
cmd.AddCommand(implementation.NewCmd())

cmd.PersistentFlags().StringP("output", "o", "generated", "Path to the output directory for the generated manifests")
cmd.PersistentFlags().Bool("override", false, "Override existing manifest files")
cmd.PersistentFlags().Bool("overwrite", false, "Overwrite existing manifest files")

return cmd
}
2 changes: 1 addition & 1 deletion cmd/cli/docs/capact_alpha_manifest-gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Subcommand for various manifest generation operations
```
-h, --help help for manifest-gen
-o, --output string Path to the output directory for the generated manifests (default "generated")
--override Override existing manifest files
--overwrite Overwrite existing manifest files
```

### Options inherited from parent commands
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/docs/capact_alpha_manifest-gen_implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ Generate new Implementation manifests for various tools.
```
-c, --config string Path to the YAML config file
-o, --output string Path to the output directory for the generated manifests (default "generated")
--override Override existing manifest files
--overwrite Overwrite existing manifest files
```

### SEE ALSO

* [capact alpha manifest-gen](capact_alpha_manifest-gen.md) - Manifests generation
* [capact alpha manifest-gen implementation helm](capact_alpha_manifest-gen_implementation_helm.md) - Generate Helm chart based manifests
* [capact alpha manifest-gen implementation terraform](capact_alpha_manifest-gen_implementation_terraform.md) - Generate Terraform based manifests

38 changes: 38 additions & 0 deletions cmd/cli/docs/capact_alpha_manifest-gen_implementation_helm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: capact alpha manifest-gen implementation helm
---

## capact alpha manifest-gen implementation helm

Generate Helm chart based manifests

### Synopsis

Generate Implementation manifests based on a Helm chart

```
capact alpha manifest-gen implementation helm [MANIFEST_PATH] [HELM_CHART_NAME] [flags]
```

### Options

```
-h, --help help for helm
-i, --interface string Path with revision of the Interface, which is implemented by this Implementation
--repo string URL of the Helm repository
-r, --revision string Revision of the Implementation manifest (default "0.1.0")
-v, --version string Version of the Helm chart
```

### Options inherited from parent commands

```
-c, --config string Path to the YAML config file
-o, --output string Path to the output directory for the generated manifests (default "generated")
--overwrite Overwrite existing manifest files
```

### SEE ALSO

* [capact alpha manifest-gen implementation](capact_alpha_manifest-gen_implementation.md) - Generate new Implementation manifests

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Generate Terraform based manifests

### Synopsis

Generate Terraform based manifests based on a Terraform module
Generate Implementation manifests based on a Terraform module

```
capact alpha manifest-gen implementation terraform [MANIFEST_PATH] [TERRAFORM_MODULE_PATH] [flags]
Expand Down Expand Up @@ -42,7 +42,7 @@ capact alpha manifest-gen implementation terraform cap.implementation.gcp.clouds
```
-c, --config string Path to the YAML config file
-o, --output string Path to the output directory for the generated manifests (default "generated")
--override Override existing manifest files
--overwrite Overwrite existing manifest files
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/docs/capact_alpha_manifest-gen_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ capact alpha content interface cap.interface.database.postgresql install
```
-c, --config string Path to the YAML config file
-o, --output string Path to the output directory for the generated manifests (default "generated")
--override Override existing manifest files
--overwrite Overwrite existing manifest files
```

### SEE ALSO
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ require (
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd
github.com/Masterminds/goutils v1.1.1
github.com/Masterminds/semver/v3 v3.1.1
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/alecthomas/jsonschema v0.0.0-20210526225647-edb03dcab7bc
github.com/argoproj/argo-workflows/v3 v3.1.0-rc1.0.20210811221840-88520891a037
github.com/avast/retry-go v3.0.0+incompatible
github.com/aws/aws-sdk-go v1.37.0 // indirect
Expand All @@ -33,6 +35,7 @@ require (
github.com/hashicorp/terraform v0.11.12-beta1
github.com/hashicorp/terraform-config-inspect v0.0.0-20210625153042-09f34846faab
github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0
github.com/iancoleman/strcase v0.1.2
github.com/machinebox/graphql v0.2.2
github.com/matryer/is v1.4.0 // indirect
Expand Down Expand Up @@ -65,6 +68,7 @@ require (
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect
google.golang.org/api v0.44.0
google.golang.org/grpc/examples v0.0.0-20210322221411-d26af8e39165 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gotest.tools v2.2.0+incompatible
helm.sh/helm/v3 v3.6.3
k8s.io/api v0.21.3
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ github.com/ahmetb/gen-crd-api-reference-docs v0.2.0/go.mod h1:P/XzJ+c2+khJKNKABc
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/alecthomas/jsonschema v0.0.0-20210526225647-edb03dcab7bc h1:mT8qSzuyEAkxbv4GBln7yeuQZpBnfikr3PTuiPs6Z3k=
github.com/alecthomas/jsonschema v0.0.0-20210526225647-edb03dcab7bc/go.mod h1:/n6+1/DWPltRLWL/VKyUxg6tzsl5kHUCcraimt4vr60=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down Expand Up @@ -843,6 +845,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/huandu/xstrings v1.3.1 h1:4jgBlKK6tLKFvO8u5pmYjG91cqytmDCDvGh7ECVFfFs=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 h1:i462o439ZjprVSFSZLZxcsoAe592sZB1rci2Z8j4wdk=
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/iancoleman/strcase v0.1.1/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/iancoleman/strcase v0.1.2 h1:gnomlvw9tnV3ITTAxzKSgTF+8kFWcU/f+TgttpXGz1U=
github.com/iancoleman/strcase v0.1.2/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
Expand Down Expand Up @@ -1367,6 +1371,7 @@ github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRci
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
Loading