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

CLI commands support for packages in airgapped admin #8026

Merged
merged 1 commit into from
May 2, 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
21 changes: 18 additions & 3 deletions cmd/eksctl-anywhere/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import (
"context"

anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/dependencies"
"github.com/aws/eks-anywhere/pkg/files"
"github.com/aws/eks-anywhere/pkg/helm"
"github.com/aws/eks-anywhere/pkg/kubeconfig"
"github.com/aws/eks-anywhere/pkg/manifests/bundles"
"github.com/aws/eks-anywhere/pkg/registrymirror"
"github.com/aws/eks-anywhere/pkg/version"
"github.com/aws/eks-anywhere/release/api/v1alpha1"
)
Expand Down Expand Up @@ -50,7 +52,7 @@

func NewDependenciesForPackages(ctx context.Context, opts ...PackageOpt) (*dependencies.Dependencies, error) {
config := New(opts...)
return dependencies.NewFactory().
f := dependencies.NewFactory().

Check warning on line 55 in cmd/eksctl-anywhere/cmd/common.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/common.go#L55

Added line #L55 was not covered by tests
WithExecutableMountDirs(config.mountPaths...).
WithCustomBundles(config.bundlesOverride).
WithExecutableBuilder().
Expand All @@ -59,8 +61,13 @@
WithHelm(helm.WithInsecure()).
WithCuratedPackagesRegistry(config.registryName, config.kubeVersion, version.Get()).
WithPackageControllerClient(config.spec, config.kubeConfig).
WithLogger().
Build(ctx)
WithLogger()

Check warning on line 64 in cmd/eksctl-anywhere/cmd/common.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/common.go#L64

Added line #L64 was not covered by tests

if config.cluster != nil && config.cluster.Spec.RegistryMirrorConfiguration != nil {
f.WithRegistryMirror(registrymirror.FromCluster(config.cluster))

Check warning on line 67 in cmd/eksctl-anywhere/cmd/common.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/common.go#L66-L67

Added lines #L66 - L67 were not covered by tests
}

return f.Build(ctx)

Check warning on line 70 in cmd/eksctl-anywhere/cmd/common.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/common.go#L70

Added line #L70 was not covered by tests
}

type PackageOpt func(*PackageConfig)
Expand All @@ -72,6 +79,7 @@
mountPaths []string
spec *cluster.Spec
bundlesOverride string
cluster *anywherev1.Cluster
}

func New(options ...PackageOpt) *PackageConfig {
Expand Down Expand Up @@ -118,3 +126,10 @@
config.bundlesOverride = bundlesOverride
}
}

// WithCluster sets cluster in the config with incoming value.
func WithCluster(cluster *anywherev1.Cluster) func(config *PackageConfig) {
return func(config *PackageConfig) {
config.cluster = cluster

Check warning on line 133 in cmd/eksctl-anywhere/cmd/common.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/common.go#L131-L133

Added lines #L131 - L133 were not covered by tests
}
}
21 changes: 20 additions & 1 deletion cmd/eksctl-anywhere/cmd/generatepackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"log"

"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 Down Expand Up @@ -70,7 +74,22 @@
return err
}

deps, err := NewDependenciesForPackages(ctx, WithRegistryName(gpOptions.registry), WithKubeVersion(gpOptions.kubeVersion), WithMountPaths(kubeConfig), WithBundlesOverride(gpOptions.bundlesOverride))
k8sClient, err := kubernetes.NewRuntimeClientFromFileName(kubeConfig)
if err != nil {
return fmt.Errorf("unable to initalize k8s client: %v", err)

Check warning on line 79 in cmd/eksctl-anywhere/cmd/generatepackage.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/generatepackage.go#L77-L79

Added lines #L77 - L79 were not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/generatepackage.go#L82-L84

Added lines #L82 - L84 were not covered by tests
}

deps, err := NewDependenciesForPackages(ctx,
WithRegistryName(gpOptions.registry),
WithKubeVersion(gpOptions.kubeVersion),
WithMountPaths(kubeConfig),
WithBundlesOverride(gpOptions.bundlesOverride),
WithCluster(cluster))

Check warning on line 92 in cmd/eksctl-anywhere/cmd/generatepackage.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/generatepackage.go#L87-L92

Added lines #L87 - L92 were not covered by tests
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/eksctl-anywhere/cmd/installpackagecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@
return fmt.Errorf("the cluster config file provided is invalid: %v", err)
}

deps, err := NewDependenciesForPackages(ctx, WithMountPaths(kubeConfig), WithClusterSpec(clusterSpec), WithKubeConfig(ico.kubeConfig), WithBundlesOverride(ico.bundlesOverride))
deps, err := NewDependenciesForPackages(ctx,
WithMountPaths(kubeConfig),
WithClusterSpec(clusterSpec),
WithKubeConfig(ico.kubeConfig),
WithBundlesOverride(ico.bundlesOverride),
WithCluster(clusterSpec.Cluster))

Check warning on line 67 in cmd/eksctl-anywhere/cmd/installpackagecontroller.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/installpackagecontroller.go#L62-L67

Added lines #L62 - L67 were not covered by tests
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ require (
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/net v0.23.0
golang.org/x/oauth2 v0.15.0
golang.org/x/sys v0.18.0
golang.org/x/text v0.14.0
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -183,6 +182,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.17.0 // indirect
Expand Down