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

Adding airgap support for list packages command #8286

Merged
merged 1 commit into from
Jun 12, 2024
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
4 changes: 0 additions & 4 deletions cmd/eksctl-anywhere/cmd/generatepackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ var generatePackageCommand = &cobra.Command{

func runGeneratePackages(cmd *cobra.Command, args []string) error {
clusterName := gpOptions.clusterName
if len(gpOptions.kubeVersion) > 0 {
// allow both
clusterName = ""
}
if err := curatedpackages.ValidateKubeVersion(gpOptions.kubeVersion, clusterName); err != nil {
return err
}
Expand Down
28 changes: 26 additions & 2 deletions cmd/eksctl-anywhere/cmd/listpackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"os"

"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types"

anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/clients/kubernetes"
"github.com/aws/eks-anywhere/pkg/constants"
"github.com/aws/eks-anywhere/pkg/curatedpackages"
"github.com/aws/eks-anywhere/pkg/kubeconfig"
)
Expand All @@ -33,7 +37,7 @@
listPackagesCommand.Flags().StringVar(&lpo.kubeConfig, "kubeconfig", "",
"Path to a kubeconfig file to use when source is a cluster.")
listPackagesCommand.Flags().StringVar(&lpo.clusterName, "cluster", "",
"Name of cluster for package list.")
"Name of cluster for package list. Required for airgapped environments.")
listPackagesCommand.Flags().StringVar(&lpo.bundlesOverride, "bundles-override", "",
"Override default Bundles manifest (not recommended)")
}
Expand All @@ -60,7 +64,27 @@
if err != nil {
return err
}
deps, err := NewDependenciesForPackages(ctx, WithRegistryName(lpo.registry), WithKubeVersion(lpo.kubeVersion), WithMountPaths(kubeConfig), WithBundlesOverride(lpo.bundlesOverride))

depOpts := []PackageOpt{
WithRegistryName(lpo.registry),
WithKubeVersion(lpo.kubeVersion),
WithMountPaths(kubeConfig),
WithBundlesOverride(lpo.bundlesOverride),

Check warning on line 72 in cmd/eksctl-anywhere/cmd/listpackages.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/listpackages.go#L68-L72

Added lines #L68 - L72 were not covered by tests
}
cluster := &anywherev1.Cluster{}
if len(lpo.clusterName) > 0 {
k8sClient, err := kubernetes.NewRuntimeClientFromFileName(kubeConfig)
if err != nil {
return fmt.Errorf("unable to initalize k8s client: %v", err)

Check warning on line 78 in cmd/eksctl-anywhere/cmd/listpackages.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/listpackages.go#L74-L78

Added lines #L74 - L78 were not covered by tests
}

if err := k8sClient.Get(ctx, types.NamespacedName{Name: lpo.clusterName, Namespace: constants.DefaultNamespace}, cluster); err != nil {
return fmt.Errorf("unable to get cluster %s: %v", lpo.clusterName, err)

Check warning on line 82 in cmd/eksctl-anywhere/cmd/listpackages.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/listpackages.go#L81-L82

Added lines #L81 - L82 were not covered by tests
}
depOpts = append(depOpts, WithCluster(cluster))

Check warning on line 84 in cmd/eksctl-anywhere/cmd/listpackages.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/listpackages.go#L84

Added line #L84 was not covered by tests
}

deps, err := NewDependenciesForPackages(ctx, depOpts...)

Check warning on line 87 in cmd/eksctl-anywhere/cmd/listpackages.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/listpackages.go#L87

Added line #L87 was not covered by tests
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
12 changes: 5 additions & 7 deletions pkg/curatedpackages/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ import (
)

func ValidateKubeVersion(kubeVersion string, clusterName string) error {
if len(clusterName) > 0 {
if len(kubeVersion) > 0 {
return fmt.Errorf("please specify either kube-version or cluster name not both")
}
return nil
}

if len(kubeVersion) > 0 {
versionSplit := strings.Split(kubeVersion, ".")
if len(versionSplit) != 2 {
return fmt.Errorf("please specify kube-version as <major>.<minor>")
}
return nil
}

if len(clusterName) > 0 {
// no-op since either cluster name or kube-version is needed.
return nil
}
return fmt.Errorf("please specify kube-version or cluster name")
}
7 changes: 0 additions & 7 deletions pkg/curatedpackages/validations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ func TestValidateNoKubeVersionWhenClusterSucceeds(t *testing.T) {
}
}

func TestValidateKubeVersionWhenClusterFails(t *testing.T) {
err := curatedpackages.ValidateKubeVersion("1.21", "morby")
if err == nil {
t.Errorf("not both kube-version and cluster")
}
}

func TestValidateKubeVersionWhenNoClusterFails(t *testing.T) {
err := curatedpackages.ValidateKubeVersion("", "")
if err == nil {
Expand Down
Loading