Skip to content

Commit

Permalink
Curated packages bugfixes (#2045)
Browse files Browse the repository at this point in the history
* Fix some minor issues

* Add License during cluster creation

* Add License in controller and package installation

* Add formatting curated packages license

* Gofumpt resolution

* Fix PR Review Comments

* Fix PR Review Comments
  • Loading branch information
a-cool-train authored May 6, 2022
1 parent e1fae51 commit ac57fbd
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/applypackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var applyPackagesCommand = &cobra.Command{

func applyPackages(ctx context.Context) error {
kubeConfig := kubeconfig.FromEnvironment()
deps, err := newDependenciesForPackages(ctx, kubeConfig)
deps, err := curatedpackages.NewDependenciesForPackages(ctx, kubeConfig)
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
13 changes: 0 additions & 13 deletions cmd/eksctl-anywhere/cmd/common.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package cmd

import (
"context"

"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/dependencies"
"github.com/aws/eks-anywhere/pkg/kubeconfig"
"github.com/aws/eks-anywhere/pkg/version"
"github.com/aws/eks-anywhere/release/api/v1alpha1"
Expand All @@ -28,13 +25,3 @@ func getKubeconfigPath(clusterName, override string) string {
}
return override
}

func newDependenciesForPackages(ctx context.Context, paths ...string) (*dependencies.Dependencies, error) {
return dependencies.NewFactory().
WithExecutableMountDirs(paths...).
WithExecutableBuilder().
WithManifestReader().
WithKubectl().
WithHelm().
Build(ctx)
}
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/createpackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var createPackagesCommand = &cobra.Command{

func createPackages(ctx context.Context) error {
kubeConfig := kubeconfig.FromEnvironment()
deps, err := newDependenciesForPackages(ctx, kubeConfig)
deps, err := curatedpackages.NewDependenciesForPackages(ctx, kubeConfig)
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/deletepackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var deletePackageCommand = &cobra.Command{

func deleteResources(ctx context.Context, args []string) error {
kubeConfig := kubeconfig.FromEnvironment()
deps, err := newDependenciesForPackages(ctx, kubeConfig)
deps, err := curatedpackages.NewDependenciesForPackages(ctx, kubeConfig)
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/describepackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var describePackagesCommand = &cobra.Command{

func describeResources(ctx context.Context, args []string) error {
kubeConfig := kubeconfig.FromEnvironment()
deps, err := newDependenciesForPackages(ctx, kubeConfig)
deps, err := curatedpackages.NewDependenciesForPackages(ctx, kubeConfig)
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/generatepackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func runGeneratePackages(cmd *cobra.Command, args []string) error {

func generatePackages(ctx context.Context, args []string) error {
kubeConfig := kubeconfig.FromEnvironment()
deps, err := newDependenciesForPackages(ctx, kubeConfig)
deps, err := curatedpackages.NewDependenciesForPackages(ctx, kubeConfig)
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/eksctl-anywhere/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/viper"

"github.com/aws/eks-anywhere/pkg/constants"
"github.com/aws/eks-anywhere/pkg/curatedpackages"
"github.com/aws/eks-anywhere/pkg/features"
"github.com/aws/eks-anywhere/pkg/kubeconfig"
)
Expand Down Expand Up @@ -39,7 +40,7 @@ func preRunPackages(cmd *cobra.Command, args []string) error {
func getResources(ctx context.Context, resourceType string, output string, args []string) error {
kubeConfig := kubeconfig.FromEnvironment()

deps, err := newDependenciesForPackages(ctx)
deps, err := curatedpackages.NewDependenciesForPackages(ctx, kubeConfig)
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand All @@ -56,9 +57,9 @@ func getResources(ctx context.Context, resourceType string, output string, args
return fmt.Errorf("kubectl execution failure: \n%v", err)
}
if len(stdOut.Bytes()) == 0 {
fmt.Printf("No resources found in %v namespace", constants.EksaPackagesName)
fmt.Printf("No resources found in %v namespace\n", constants.EksaPackagesName)
return nil
}
fmt.Println(&stdOut)
fmt.Print(&stdOut)
return nil
}
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/installpackagecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func runInstallPackageController(cmd *cobra.Command, args []string) error {
func installPackageController(ctx context.Context) error {
kubeConfig := kubeconfig.FromEnvironment()

deps, err := newDependenciesForPackages(ctx, kubeConfig)
deps, err := curatedpackages.NewDependenciesForPackages(ctx, kubeConfig)
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/installpackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func runInstallPackages(cmd *cobra.Command, args []string) error {

func installPackages(ctx context.Context, args []string) error {
kubeConfig := kubeconfig.FromEnvironment()
deps, err := newDependenciesForPackages(ctx, kubeConfig)
deps, err := curatedpackages.NewDependenciesForPackages(ctx, kubeConfig)
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
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 @@ -51,7 +51,7 @@ var listPackagesCommand = &cobra.Command{

func listPackages(ctx context.Context) error {
kubeConfig := kubeconfig.FromEnvironment()
deps, err := newDependenciesForPackages(ctx, kubeConfig)
deps, err := curatedpackages.NewDependenciesForPackages(ctx, kubeConfig)
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/upgradepackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var upgradePackagesCommand = &cobra.Command{

func upgradePackages(ctx context.Context) error {
kubeConfig := kubeconfig.FromEnvironment()
deps, err := newDependenciesForPackages(ctx, kubeConfig)
deps, err := curatedpackages.NewDependenciesForPackages(ctx, kubeConfig)
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/curatedpackages/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (b *BundleReader) UpgradeBundle(ctx context.Context, controller *packagesv1
if err != nil {
return err
}
params := []string{"create", "-f", "-", "--kubeconfig", b.kubeConfig}
params := []string{"apply", "-f", "-", "--kubeconfig", b.kubeConfig}
_, err = b.kubectl.CreateFromYaml(ctx, controllerYaml, params...)
if err != nil {
return err
Expand Down
24 changes: 24 additions & 0 deletions pkg/curatedpackages/curatedpackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ import (
releasev1 "github.com/aws/eks-anywhere/release/api/v1alpha1"
)

const (
LICENSE = `The EKS Anywhere package controller and the EKS Anywhere Curated Packages
(referred to as “features”) are provided as “preview features” subject to the AWS Service Terms,
(including Section 2 (Betas and Previews)) of the same. During the EKS Anywhere Curated Packages Public Preview,
the AWS Service Terms are extended to provide customers access to these features free of charge.
These features will be subject to a service charge and fee structure at ”General Availability“ of the features.`
WIDTH = 112
)

func NewRegistry(deps *dependencies.Dependencies, registryName, kubeVersion, username, password string) (BundleRegistry, error) {
if registryName != "" {
registry := NewCustomRegistry(
Expand Down Expand Up @@ -75,3 +84,18 @@ func NewDependenciesForPackages(ctx context.Context, paths ...string) (*dependen
WithHelm().
Build(ctx)
}

func PrintLicense() {
// Currently, use the width of the longest line to repeat the dashes
// Sample Output
//----------------------------------------------------------------------------------------------------------------
//The EKS Anywhere package controller and the EKS Anywhere Curated Packages
//(referred to as “features”) are provided as “preview features” subject to the AWS Service Terms,
//(including Section 2 (Betas and Previews)) of the same. During the EKS Anywhere Curated Packages Public Preview,
//the AWS Service Terms are extended to provide customers access to these features free of charge.
//These features will be subject to a service charge and fee structure at ”General Availability“ of the features.
//----------------------------------------------------------------------------------------------------------------
fmt.Println(strings.Repeat("-", WIDTH))
fmt.Println(LICENSE)
fmt.Println(strings.Repeat("-", WIDTH))
}
3 changes: 3 additions & 0 deletions pkg/curatedpackages/packageclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (pc *PackageClient) packageMap() map[string]packagesv1.BundlePackage {
}

func (pc *PackageClient) InstallPackage(ctx context.Context, bp *packagesv1.BundlePackage, customName string, kubeConfig string) error {
PrintLicense()
p := convertBundlePackageToPackage(*bp, customName, pc.bundle.APIVersion)
displayPackage := NewDisplayablePackage(&p)
params := []string{"create", "-f", "-", "--kubeconfig", kubeConfig}
Expand All @@ -122,6 +123,7 @@ func (pc *PackageClient) InstallPackage(ctx context.Context, bp *packagesv1.Bund
}

func (pc *PackageClient) ApplyPackages(ctx context.Context, fileName string, kubeConfig string) error {
PrintLicense()
params := []string{"apply", "-f", fileName, "--kubeconfig", kubeConfig}
stdOut, err := pc.kubectl.ExecuteCommand(ctx, params...)
if err != nil {
Expand All @@ -133,6 +135,7 @@ func (pc *PackageClient) ApplyPackages(ctx context.Context, fileName string, kub
}

func (pc *PackageClient) CreatePackages(ctx context.Context, fileName string, kubeConfig string) error {
PrintLicense()
params := []string{"create", "-f", fileName, "--kubeconfig", kubeConfig}
stdOut, err := pc.kubectl.ExecuteCommand(ctx, params...)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/curatedpackages/packagecontrollerclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func NewPackageControllerClient(chartInstaller ChartInstaller, kubectl KubectlRu
}

func (pc *PackageControllerClient) InstallController(ctx context.Context) error {
PrintLicense()
ociUri := fmt.Sprintf("%s%s", "oci://", pc.uri)
return pc.chartInstaller.InstallChartFromName(ctx, ociUri, pc.kubeConfig, pc.chartName, pc.chartVersion)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/workflows/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (c *Create) Run(ctx context.Context, clusterSpec *cluster.Spec, validator i
}

if packagesLocation != "" {
curatedpackages.PrintLicense()
err = installCuratedPackages(ctx, clusterSpec, packagesLocation)
}
return err
Expand Down

0 comments on commit ac57fbd

Please sign in to comment.