Skip to content

Commit

Permalink
Include configurations for curated packages (aws#2434)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-cool-train authored and wongni committed Jun 21, 2022
1 parent 505da83 commit ef49baa
Show file tree
Hide file tree
Showing 17 changed files with 448 additions and 52 deletions.
1 change: 0 additions & 1 deletion cmd/eksctl-anywhere/cmd/applypackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func applyPackages(ctx context.Context) error {
return fmt.Errorf("unable to initialize executables: %v", err)
}
packages := curatedpackages.NewPackageClient(
nil,
deps.Kubectl,
)

Expand Down
1 change: 1 addition & 0 deletions cmd/eksctl-anywhere/cmd/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func (cc *createClusterOptions) directoriesToMount(clusterSpec *cluster.Spec, cl
if fluxConfig != nil && fluxConfig.Spec.Git != nil {
dirs = append(dirs, filepath.Dir(cliConfig.GitPrivateKeyFile))
dirs = append(dirs, filepath.Dir(cliConfig.GitKnownHostsFile))
dirs = append(dirs, filepath.Dir(cc.installPackages))
}

if clusterSpec.Config.Cluster.Spec.DatacenterRef.Kind == v1alpha1.CloudStackDatacenterKind {
Expand Down
1 change: 0 additions & 1 deletion cmd/eksctl-anywhere/cmd/createpackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func createPackages(ctx context.Context) error {
return fmt.Errorf("unable to initialize executables: %v", err)
}
packages := curatedpackages.NewPackageClient(
nil,
deps.Kubectl,
)

Expand Down
1 change: 0 additions & 1 deletion cmd/eksctl-anywhere/cmd/deletepackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func deleteResources(ctx context.Context, args []string) error {
return fmt.Errorf("unable to initialize executables: %v", err)
}
packages := curatedpackages.NewPackageClient(
nil,
deps.Kubectl,
)

Expand Down
1 change: 0 additions & 1 deletion cmd/eksctl-anywhere/cmd/describepackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func describeResources(ctx context.Context, args []string) error {
return fmt.Errorf("unable to initialize executables: %v", err)
}
packages := curatedpackages.NewPackageClient(
nil,
deps.Kubectl,
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/eksctl-anywhere/cmd/generatepackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func generatePackages(ctx context.Context, args []string) error {
}

packageClient := curatedpackages.NewPackageClient(
bundle,
deps.Kubectl,
args...,
curatedpackages.WithBundle(bundle),
curatedpackages.WithCustomPackages(args),
)
packages, err := packageClient.GeneratePackages()
if err != nil {
Expand Down
22 changes: 17 additions & 5 deletions cmd/eksctl-anywhere/cmd/installpackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
)

type installPackageOptions struct {
source curatedpackages.BundleSource
kubeVersion string
packageName string
registry string
source curatedpackages.BundleSource
kubeVersion string
packageName string
registry string
customConfigs []string
showOptions bool
}

var ipo = &installPackageOptions{}
Expand All @@ -33,6 +35,8 @@ func init() {
log.Fatalf("Error marking flag as required: %v", err)
}
installPackageCommand.Flags().StringVar(&ipo.registry, "registry", "", "Used to specify an alternative registry for discovery")
installPackageCommand.Flags().BoolVar(&ipo.showOptions, "show-options", false, "Used to specify the package options to be used for configuration")
installPackageCommand.Flags().StringArrayVar(&ipo.customConfigs, "set", []string{}, "Provide custom configurations for curated packages. Format key:value")
}

var installPackageCommand = &cobra.Command{
Expand Down Expand Up @@ -79,15 +83,23 @@ func installPackages(ctx context.Context, args []string) error {
}

packages := curatedpackages.NewPackageClient(
bundle,
deps.Kubectl,
curatedpackages.WithBundle(bundle),
curatedpackages.WithCustomConfigs(ipo.customConfigs),
curatedpackages.WithShowOptions(ipo.showOptions),
)

p, err := packages.GetPackageFromBundle(args[0])
if err != nil {
return err
}

if ipo.showOptions {
configs := curatedpackages.GetConfigurationsFromBundle(p)
curatedpackages.DisplayConfigurationOptions(configs)
return nil
}

curatedpackages.PrintLicense()
err = packages.InstallPackage(ctx, p, ipo.packageName, kubeConfig)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/listpackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func listPackages(ctx context.Context) error {
return err
}
packages := curatedpackages.NewPackageClient(
bundle,
deps.Kubectl,
curatedpackages.WithBundle(bundle),
)
packages.DisplayPackages()
return nil
Expand Down
59 changes: 59 additions & 0 deletions designs/curated-packages-configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Curated Packages Customized Configuration

## Problem

Currently, the eks anywhere CLI provides `install` command. This command's aim is to provide the ability for users to install a curated package in the cluster. Currently, this command does not support the ability to override any configurations that would enable the user to customize the curated package.

## Goals and Objectives

As a curated packages user, I want to:

* Provide custom configurations to override default configurations from the CLI

## Possible Solutions

### Provide separate key value pairs from the CLI

The first solution would be to provide separate key value pairs through the cli similar to helm (https://all.docs.genesys.com/PrivateEdition/Current/PEGuide/HelmOverrides)

*Sample*

```bash
$ eksctl anywhere install package harbor --set key=key --set key2=key2
```

### Provide consolidated key value pairs from the CLI

Similar to the first solution, the solution would be to consolidate all the key value pairs into one but separated by a delimiter, similar to cobra (https://github.com/spf13/pflag/pull/133)

*Sample*

```bash
$ eksctl anywhere install package harbor --config=key1=key1, key2=key2
```

### Provide key value pair through a file and pass the file to the CLI

This solution is different than both the previous solution given that it takes a file for the configuration

*Sample*

```bash
$ cat config.txt
secretKey=use-a-secret-key
harborAdminPassword=test
$ eksctl anywhere install package harbor --config ./config.txt
```

## Proposed Solution
Since the amount of configurations required for curated packages is a limited set, we will be implementing [Provide separate key value pairs from the CLI](#Provide-separate-key-value-pairs-from-the-CLI) option.

## Customized Configuration Discovery

In order for the user to identify what configurations are available, the CLI needs to provide a mechanism to identify the configurations available for a package. Similar to helm's show values, we would provide a capability that is inline with this format.

The command would look like below

```bash
$ eksctl anywhere install package harbor --source cluster --show-options
```
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/aws/aws-sdk-go-v2 v1.16.2
github.com/aws/aws-sdk-go-v2/config v1.15.3
github.com/aws/aws-sdk-go-v2/service/ec2 v1.34.0
github.com/aws/eks-anywhere-packages v0.1.10
github.com/aws/eks-anywhere-packages v0.1.11
github.com/aws/eks-anywhere/release v0.0.0-20211130194657-f6e9593c6551
github.com/aws/eks-distro-build-tooling/release v0.0.0-20211103003257-a7e2379eae5e
github.com/aws/smithy-go v1.11.2
Expand All @@ -28,15 +28,14 @@ require (
github.com/stretchr/testify v1.7.0
github.com/tinkerbell/rufio v0.0.0-20220606134123-599b7401b5cc
github.com/tinkerbell/tink v0.6.1-0.20220509141453-30fe9e015575
go.uber.org/multierr v1.7.0
go.uber.org/zap v1.19.1
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
gopkg.in/ini.v1 v1.66.2
gopkg.in/square/go-jose.v2 v2.6.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gopkg.in/yaml.v3 v3.0.0
k8s.io/api v0.23.4
k8s.io/apimachinery v0.23.4
k8s.io/client-go v0.23.4
Expand Down Expand Up @@ -74,7 +73,7 @@ require (
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/bmc-toolbox/bmclib v0.5.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/containerd/containerd v1.6.1 // indirect
github.com/containerd/containerd v1.6.6 // indirect
github.com/coredns/caddy v1.1.0 // indirect
github.com/coredns/corefile-migration v1.0.14 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down Expand Up @@ -129,10 +128,10 @@ require (
github.com/morikuni/aec v1.0.0 // indirect
github.com/mrajashree/etcdadm-bootstrap-provider v1.0.0-rc3 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
Expand All @@ -145,6 +144,7 @@ require (
github.com/subosito/gotenv v1.2.0 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
Expand Down
13 changes: 8 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ github.com/aws/aws-sdk-go-v2/service/sso v1.11.3/go.mod h1:7UQ/e69kU7LDPtY40OyoH
github.com/aws/aws-sdk-go-v2/service/sts v1.6.0/go.mod h1:q7o0j7d7HrJk/vr9uUt3BVRASvcU7gYZB9PUgPiByXg=
github.com/aws/aws-sdk-go-v2/service/sts v1.16.3 h1:cJGRyzCSVwZC7zZZ1xbx9m32UnrKydRYhOvcD1NYP9Q=
github.com/aws/aws-sdk-go-v2/service/sts v1.16.3/go.mod h1:bfBj0iVmsUyUg4weDB4NxktD9rDGeKSVWnjTnwbx9b8=
github.com/aws/eks-anywhere-packages v0.1.10 h1:hxlyTaX1liNwcKfouSMktN/5TjwgvW2rqGD2k4KOofk=
github.com/aws/eks-anywhere-packages v0.1.10/go.mod h1:E9SzysKvx+TGZ+QQ0+S3DbJdjUtahXwWXG2uBXBKUzU=
github.com/aws/eks-anywhere-packages v0.1.11 h1:CC8tdEEWrcmzJxKgpMuK6SHFNeHVyZXSi4GFXOioJXQ=
github.com/aws/eks-anywhere-packages v0.1.11/go.mod h1:g4HXRg4xMgofXwDrlOtMYVkKEQQC3JXgduQTkDfPf6U=
github.com/aws/eks-distro-build-tooling/release v0.0.0-20211103003257-a7e2379eae5e h1:GB6Cn9yKEt31mDF7RrVWyM9WoppNkGYth8zBPIJGJ+w=
github.com/aws/eks-distro-build-tooling/release v0.0.0-20211103003257-a7e2379eae5e/go.mod h1:p/KHVJAMv3kofnUnShkZ6pUnZYzm+LK2G7bIi8nnTKA=
github.com/aws/smithy-go v1.6.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
Expand Down Expand Up @@ -1381,8 +1381,9 @@ github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 h1:rc3tiVYb5z54aKaDfakKn0dDjIyPpTtszkjuMzyt7ec=
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/runc v1.1.2/go.mod h1:Tj1hFw6eFWp/o33uxGf5yF2BX5yz2Z6iptFpuvbbKqc=
github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/runtime-spec v1.0.3-0.20200929063507-e6143ca7d51d/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
Expand Down Expand Up @@ -1442,8 +1443,9 @@ github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQ
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.11.0 h1:HNkLOAEQMIDv/K+04rukrLx6ch7msSRwf3/SASFAGtQ=
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.11.1 h1:+4eQaD7vAZ6DsfsxB15hbE0odUjGI5ARs9yskGu1v4s=
github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down Expand Up @@ -2560,8 +2562,9 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
Expand Down
81 changes: 81 additions & 0 deletions pkg/curatedpackages/configurationclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package curatedpackages

import (
"bytes"
"fmt"
"os"
"strings"
"text/tabwriter"

packagesv1 "github.com/aws/eks-anywhere-packages/api/v1alpha1"
)

func GetConfigurationsFromBundle(bundlePackage *packagesv1.BundlePackage) map[string]packagesv1.VersionConfiguration {
configs := make(map[string]packagesv1.VersionConfiguration)
if bundlePackage == nil || len(bundlePackage.Source.Versions) < 1 {
return configs
}
packageConfigurations := bundlePackage.Source.Versions[0].Configurations

for _, config := range packageConfigurations {
configs[config.Name] = config
}
return configs
}

func UpdateConfigurations(originalConfigs map[string]packagesv1.VersionConfiguration, newConfigs map[string]string) error {
for key, val := range newConfigs {
value, exists := originalConfigs[key]
if !exists {
return fmt.Errorf("invalid key: %s. please specify the correct configurations", key)
}
value.Default = val
originalConfigs[key] = value
}
return nil
}

func GenerateAllValidConfigurations(configs map[string]packagesv1.VersionConfiguration) string {
b := new(bytes.Buffer)
for key, val := range configs {
if val.Default != "" || val.Required {
fmt.Fprintf(b, "%s: \"%s\"\n", key, val.Default)
}
}
return b.String()
}

func GenerateDefaultConfigurations(configs map[string]packagesv1.VersionConfiguration) string {
b := new(bytes.Buffer)
for key, val := range configs {
if val.Required {
fmt.Fprintf(b, "%s: \"%s\"\n", key, val.Default)
}
}
return b.String()
}

func ParseConfigurations(configs []string) (map[string]string, error) {
parsedConfigurations := make(map[string]string)

for _, c := range configs {
keyval := strings.Split(c, "=")
if len(keyval) < 2 {
return nil, fmt.Errorf("please specify %s as key=value", c)
}
key, val := keyval[0], keyval[1]
parsedConfigurations[key] = val
}
return parsedConfigurations, nil
}

func DisplayConfigurationOptions(configs map[string]packagesv1.VersionConfiguration) {
w := new(tabwriter.Writer)
defer w.Flush()
w.Init(os.Stdout, minWidth, tabWidth, padding, padChar, flags)
fmt.Fprintf(w, "%s\t%s\t%s\t \n", "Configuration", "Required", "Default")
fmt.Fprintf(w, "%s\t%s\t%s\t \n", "-------------", "--------", "-------")
for key, val := range configs {
fmt.Fprintf(w, "%s\t%v\t%s\t \n", key, val.Required, val.Default)
}
}
Loading

0 comments on commit ef49baa

Please sign in to comment.